zayedalam
Published © MPL-2.0

Control sound using pushbuttons

Hi guys, As always I have created a simple project by using arduino nano, pushbuttons and a buzzer.

IntermediateFull instructions provided243
Control sound using pushbuttons

Things used in this project

Story

Read more

Schematics

Here's the schematics

Code

Here is the code

Arduino
/****************************************************************************
 *Controlling sounds using push buttons
 *                                                    by Zayed alam
 *Hi guys!
 *Today as always I have an interesting project which needs the following
 *breadboard
 *buzzer
 *pushbuttons
 *wires
 *arduino,nano,uno or mega
 *You can add additional buttons(If you have multiple same breadboard.
 *****************************************************************************
 */
int but1=2;//For button1
int but2=3;//For button2
int but3=4;//FOr button3
int but4=5;//for button4
 int buttonState1=0;
 int buttonState2=0;
 int buttonState3=0;
 int buttonState4=0;

const int buzzer=6;//Our buzzer
void setup() {
  // put your setup code here, to run once:
pinMode(buzzer,OUTPUT);
pinMode(but1,INPUT);
pinMode(but2,INPUT);
pinMode(but3,INPUT);
pinMode(but4,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
buttonState1 = digitalRead(but1);
  buttonState2 = digitalRead(but2);
  buttonState3 = digitalRead(but3);
   buttonState4 = digitalRead(but4);

   if(buttonState1==HIGH){//If we press first button
    tone(buzzer,1000);
    delay(20);
    noTone(buzzer);
   }
   if(buttonState2==HIGH){
    tone(buzzer,100);
    delay(20);
    noTone(buzzer);
   }
   if(buttonState3==HIGH){
    tone(buzzer,10);
    delay(20);
    noTone(buzzer);
   }
   if(buttonState4==HIGH){
    tone(buzzer,786);
    delay(20);
    noTone(buzzer);
   }
   
}

Credits

zayedalam
7 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.