Control AC Bulb with hand Clap or Voice or Sound
Control AC Bulb with hand Clap or Voice (basic digital)
This video shows you how to turn an AC light ON with clap or your voice and Turn it off with another clap or shout. This code is basic version where digital output of the module is used. Please see other version where actual Analog sound values is used to control light.
This video has two Arduino code (sketch)
1-Baisc Code using Digital pin
2-Advanced Code using Analog pin
Resources for this sketch
- My Arduino Course on Udemy.com. Get Wiring diagram
- Get Early Access to my videos via Patreaon
- I2C Scanner
- Introduction to LCD1602-I2C with code
/*
* This is the Arduino code for Sound module for Arduino (basic)
This video shows you how to turn an AC light ON
with clap or your voice and Turn it off with another clap
or shout. This code is basic version where
digital output of the module is used.
Please see other version where actual Analog sound values is
used to control light.
*
// written by Ahmad Shamshiri for Robojax.com on
Feb 17, 2018 at 13:28 in Ajax, Ontario, Canada
* watch video for details https://youtu.be/1szA8CKWuZY
* Code is available at http://robojax.com/learn/arduino
*/
int SOUND = 2;// connect output to Sound module DO
int relayPin = 10;// Connected to relay (LED)
// do not change values bellow
int val = 0; // light value from pin 2
int lightON = 0;//light status
int heard = 0;//sound heard status
void setup() {
// SOUND Sensor Code by Robojax.com 20180217
Serial.begin(9600);
pinMode(SOUND, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
}
void loop() {
// SOUND Sensor Code by Robojax.com 20180217
val = digitalRead(SOUND);
if(val == HIGH && lightON == LOW){
heard = 1-heard;
delay(100);
}
// SOUND Sensor Code by Robojax.com 20180217
lightON = val;
if(heard == HIGH){
Serial.println("Light ON");
digitalWrite(relayPin, LOW);
}else{
Serial.println("Light OFF");
digitalWrite(relayPin, HIGH);
}
// SOUND Sensor Code by Robojax.com 20180217
delay(100);
}