How To Push Button With Buzzer

Required Hardware

For users who do not have Hackerspace Karachi Arduino Kit v1.0

  • Arduino Board
  • Breadboard
  • Push-button
  • Buzzer
  • Resistor 220 ohm
  • Hook-up Wires

Circuit

For users who do not have Hackerspace Karachi Arduino Kit v1.

Schematic

Code

                    

1. /*
2. Push Button with Buzzer
3.
4. This example shows how to use Push Button with Buzzer
5. The circuit:
6. – BUZZER
7. Anode connected to analog pin Ao.
8. Cathode connected to Ground.
9. – Push Button
10. Anode connected to VCC.
11. Cathode connected to digital pin 2.
12. Cathode connected to GND through 220 resistor.
13.
14.
15. http://hackerspacekarachi.org/
16. */
17.
18. void setup() {
19. pinMode(A0, OUTPUT); //Declare pins to be used as ouput
20. pinMode(2, INPUT); // declaration of input
21. }
22.
23. void loop()
24. {
25. int d = digitalRead(2); // read and store input
26.
27. if (d == 1)
28. {
29.
30. tone ( A0, 450); //setting frequency
31. delay (500);
32. noTone (A0);
33. delay (500);
34.
35. }
36. }

1. /*