Buzzer on using potentiometer

 Buzzer on using potentiometer

Arduino Uno - 01
Breadboard - 01
330 Ohm Resistors - 01
10K Potentiometer - 01
Jumper wires

                                Arduino Sketch

int buzzer = 13;                                         // Buzzer connected to digital pin No 13
int potentio = A0;                                     // potentiometer connected to digital pin No 2
int ANALOG_THRESHOLD  = 500;    // Analog Threshold (This value can change)

void setup(){                                              // Function is called when sketch start
 
  pinMode(buzzer, OUTPUT);               // Buzzer is an Output
  pinMode (potentio,INPUT);                // potentiometer is an Input
}

void loop(){                                              // Run continuously
int analogValue = analogRead(potentio);                  // Read the analog pin value 
if(analogValue > ANALOG_THRESHOLD){          // if analog value more than THRESHOLD
tone(buzzer, 700);                                                        // Buzzer ON(This Value can change)         
}
else{                  
noTone(buzzer);                                                //*if Buzzer OFF  
 }
}



Comments