Introduction
In this article, I'm going to explain about making sound in the Arduino, using the push button.
Parts Of Lists
- Arduino Uno
- Push Button
- Buzzer
- Bread Board
- Hookup Wire.
Connection
- Push Button To Board:
- Connect the 1st pin of the VCC of 5v to the Arduino Board
- Connect the 2nd pin to the Gnd and any digital pin of the input side to the Board.
Buzzer to Board
- Connect one side of the wire to the VCC
- Connect the another side of the wire to the Gnd.
Programming
- #include "pitches.h"
- const int buttonPin = 2; // the number of the pushbutton pin
- int note1 = NOTE_C4; // define note sound
- // variables will change:
- int buttonState = 0; // variable for reading the pushbutton status
- void setup() {
- // initialize the pushbutton pin as an input:
- pinMode(buttonPin, INPUT);
- }
- void loop() {
- // read the state of the pushbutton value:
- buttonState = digitalRead(buttonPin);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is HIGH:
- if (buttonState == HIGH) {
- // sound tone
- tone(8, note1);
- } else {
- //turn off sound
- noTone(8);
- }
- }
That's it. Now, when the button is pressed, it will automatically produce the sound.


Hussain PatelPosted Nov 2, 2016, 6:37 AM EDT
Its interesting and seems easy - tempting me to invest in Arduino..
RajaPosted Oct 31, 2016, 4:01 AM EDT
Nice Share..
Prasanna MuraliPosted Sep 5, 2016, 5:07 AM EDT
Nice one...
Hussain PatelPosted Sep 5, 2016, 12:12 AM EDT
Good one
Anu VPosted Sep 4, 2016, 7:39 PM EDT
Nice..
Vignesh ManiTOP 100Posted Sep 4, 2016, 12:59 PM EDT
Good one