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, 10:37 AM
Its interesting and seems easy - tempting me to invest in Arduino..
RajaPosted Oct 31, 2016, 8:01 AM
Nice Share..
Prasanna MuraliPosted Sep 5, 2016, 9:07 AM
Nice one...
Hussain PatelPosted Sep 5, 2016, 4:12 AM
Good one
Anu VPosted Sep 4, 2016, 11:39 PM
Nice..
Vignesh ManiPosted Sep 4, 2016, 4:59 PM
Good one