Countdown to Christmas Makes Challenge 2017 – Day 19

Clap-on/Clap-off Lights

Using an Arduino UNO and a KY-038 Sound Sensor

Clap-on/Clap-off lights, using a Arduino UNO and a KY-038 sound sensor.

(Full description, and wiring diagram to follow shortly)


C/C++ Code

boolean lightsStatus = false;
int sensor = 2;
int lights = 3;

void setup() {
  pinMode(sensor, INPUT);
  pinMode(lights, OUTPUT);
  // Serial.begin(9600);
}

void loop() {
  int data = digitalRead(sensor);
  // Serial.println(data);
  if(data == 1) {
    if(lightsStatus == false) {
      lightsStatus = true;
      digitalWrite(lights, HIGH);
      delay(1000);
    }
    else {
      lightsStatus = false;
      digitalWrite(lights, LOW);
      delay(1000);
    }
  }  

Leave a Reply