how to make clap switch using arduino
Clap switch using Arduino
In this Arduino project for beginners. The sound
made by clapping is detected by an electret microphone connected to one of the
Arduino analog input pin.
The first time that the clap is detected by the Arduino, the light will be switch ON. The second
time that a clap is detected the light will be switched OFF. this is an easy
and fun project for beginners.
Circuit diagram.
Requirements.
Microphone.
100n (104)
ceramic capacitor.
100k resistor.
10k resistor.
100 – 1k
resistor any one of them.
BC547 NPN
Transistor.
12v Relay.
Wire.
Holder.
12v DC
Supply.
Jumper wire.
Arduino (Any Arduino board ).
https://youtu.be/hH07vDR9zn8
Arduino code.
After
building the above circuit, load the following sketch to the Arduino board.
void setup() {
Serial.begin(9600); // using serial port to check analog value
pinMode(2, OUTPUT); // LED on digital pin 2
}
void loop() {
int analog_val; // analog value read from A2
static bool led_state = false; // current state of LED
analog_val = analogRead(A2);
if (analog_val > 55) { // trigger threshold, you can change the value as per your requirements, if you decrease the value sensitivity is increased or vice versa, here I used 55 because of I used 12v SMPS so its output, not pure dc means its output mix with ac with 50Hz frequency, so I used 55
// toggle LED
if (led_state) {
led_state = false; // LED was on, now off
digitalWrite(2, LOW);
Serial.println(analog_val); // print analog value for debug purposes
}
else {
led_state = true;
digitalWrite(2, HIGH); // LED was off, now on
Serial.println(analog_val);
}
delay(50); // wait for clap noise to subside
}
}
Comments
Post a Comment