Other Arduino Codes and Videos by Robojax

Control AC Bulb with hand Clap or Voice Robojax.com

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 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.

 * watch HC-SR505 Motion Sensor video for details https://youtu.be/qhThpxiXubI
 * Code is available at http://robojax.com/learn/arduino

 * 
 // Writeen by Ahmad S. for Robojax.com on 
Recorded Feb 17, 2018 at 13:28 at 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);
}
   

Control AC Bulb with hand Clap or Voice (Advanced: Analog)

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 Advanced version where Analog output A0 of the module is used. Please see other version where DO pin is used to control light.

 /*
 * This is the Arduino code Control AC Bulb with hand Clap or Voice (Advanced: Analog)
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 Advanced version where  Analog output A0 of the module is used.
Please see other version where DO pin is  used to control light.

 * watch HC-SR505 Motion Sensor video for details https://youtu.be/1szA8CKWuZY
 * Code is available at http://robojax.com/learn/arduino

 * 
 // Writeen by Ahmad S. for Robojax.com on 
Recorded Feb 17, 2018 at 13:28 at Ajax, Ontario, Canada


 * watch video for details https://youtu.be/QH1Lw9BwTJI
 * Code is available at http://robojax.com/learn/arduino
 */


int relayPin = 10;// Connected to relay (LED)
int soundValue = 530;// The sound level to trigger ON/OFF


///////////// do NOT change the lines bellow
int val = 0; // light value from pin 2
int lightON = 0;//light status
int heard = 0;//sound heard status
int dVal =0;// digital value for "val"


void setup() {
   // SOUND Sensor Advanced Code by Robojax.com 20180217
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);// set Pin 10 as output

}

void loop() {
 // SOUND Sensor Advanced Code by Robojax.com 20180217
  val = analogRead(A0);// read A0 pin value

  if(val > soundValue && lightON == LOW){

    heard = 1-heard;
    dVal =HIGH;
    delay(100);
  }else{
     dVal =LOW;
  }
 // SOUND Sensor Advanced Code by Robojax.com 20180217
  lightON = dVal;

      if(heard == HIGH){
        Serial.print(val);// print the A0 value
        Serial.println(" Light ON");
        digitalWrite(relayPin, LOW); // Turn the light ON
       
      }else{
        Serial.print(val);// print the A0 value
        Serial.println(" Light OFF");
        digitalWrite(relayPin, HIGH);// Turn the light OFF
   
      }     


 // SOUND Sensor  Advanced Code by Robojax.com 20180217
  delay(100);
}