Today’s Worksheet:
Task 1 – Make a noise using ton() and a Piezo Buzzer
For this task, we followed the instructions from the lab sheet above. We were to set up a circuit using a breadboard, Arduino (clone), 100 ohms resister, a Piezo Buzzer and some cables.
Once we have built the circuit we needed to code the Arduino to allow a sound to be created as an output.
The Code:
// A sketch to demonstrate the tone() Function
// Specifu digital pin on the arduino that the positive lead of piezo buzzer is attached.
const int piezo = 8;
void setup() {
} //close setup
void loop() {
//*Tone needs 2 arguments, but can take three.
- pin#
- frequency – this is in Hz cycle per second wich determins the pitch (the lower the number the lower the pitch, the higher the number the higher the pitch)
- duration – how long the tone will be played/hold for.
*/
tone(piezoPin, 1000, 500);
}
Task 2 – Add a break in the loop
To create a break in the loop we added the following code after the tone() function.
delay(1000);
}
Task 3 – To create a beat
we do this by adding/changing to the code we used for task 1
tone(piezoPin, 450);
delay(500);
noTone(piezoPin);
delay(500);