In this lesson we show how you do have some ability to adjust the tone on the Active Buzzer to make a sound or alarm that is a little more interesting. If you want to make notes or play simple songs you should use the passive buzzer, but the active buzzer can be adjusted somewhat.
If you want to follow along at home, an official Arduino Uno R3 is available HERE. In this new series of lessons, I will be using the sensor and other components found in this KIT.
The video above takes you through the hookup and the steps. Also, the code used in the example above is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | int buzzPin=8; int dt1=1; int dt2=2; int j; void setup() { // put your setup code here, to run once: pinMode(buzzPin, OUTPUT); } void loop() { for (j=1;j<=100;j=j+1){ digitalWrite(buzzPin, HIGH); delay(dt1); digitalWrite(buzzPin, LOW); delay(dt1); } for (j=1; j<=100;j=j+1){ digitalWrite(buzzPin, HIGH); delay(dt2); digitalWrite(buzzPin, LOW); delay(dt2); } } |