Project showcase
Clap-Controlled Lights That You Can Actually Use

Clap-Controlled Lights That You Can Actually Use

Clap twice to turn on and off a bright LED.

  • 2,377 views
  • 1 comment
  • 8 respects

Components and supplies

Necessary tools and machines

About this project

During the night, no one wants to get up and walk all the way to your light switch just to be hit with a sudden extreme amount of light. Solution! A lighting system controlled by two claps. Just clap from wherever you are to turn on LEDs bright enough to light an entire room just the right amount. It looks for a clap and repeats the program in loop(). I used four super bright LEDs, an Arduino Micro (any will work), and a sound sensor. Just clap twice to turn on and off.

Bright LEDs: https://www.amazon.com/gp/product/B07MQJKY73/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1

Arduino Micro:

https://store.arduino.cc/usa/arduino-micro

Sound Sensor:

https://www.sparkfun.com/products/12642

Code

ClapLightC/C++
/*
* GND → GND
 * VCC → 5V
 * Gate → Pin 4
 * Envelope → A0
 * 
 * LED → 7
 * LED → 9
 */
int LED0 = 7;
int firstClap;
int LED1 = 9;



// if true, the LED is on
// if false, then LED is off
bool state = false;

// when the last clapped happened
unsigned long lastClapTime;

// pin's state.
void soundISR()
{
  int pin_val;

  pin_val = digitalRead(PIN_GATE_IN);
  digitalWrite(PIN_LED_OUT, pin_val);
}

void setup()
{
  Serial.begin(9600);

  //  Configure LED pin as output
  pinMode(PIN_LED_OUT, OUTPUT);

  // configure input to interrupt
  pinMode(PIN_GATE_IN, INPUT);
  attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);


  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  
  pinMode(LED0, OUTPUT);
  pinMode(LED1, OUTPUT);

  // when we start, LED is off
  state = false;
  lastClapTime = 0;

  digitalWrite(LED0, LOW);
  digitalWrite(LED1, LOW);
}

//
// This function returns true if person has clapped
// else it returns false.
//
bool isClapped(int sound) {
  if (sound > 50) {
    return true;
  }
  return false;
}

void toggleState() {
  if (state == true) {
    state = false;
    digitalWrite(LED0, LOW);
    digitalWrite(LED1, LOW);
  } else {
    state = true;
    digitalWrite(LED0, HIGH);
    digitalWrite(LED1, HIGH);
  }
}


void loop() {  
  int sound = analogRead(PIN_ANALOG_IN);

  unsigned long now = millis();
  if (isClapped(sound)) {
    delay(200);
    
    // check if the two previos claps were within 1 second of one another 
    if (lastClapTime + 1000 > now) {
      Serial.println("Now: " + String(now) + " LastClappedTime: " +  String(lastClapTime) + " Toggling");
      toggleState();
      lastClapTime = 0;
      delay(1000);
    } else {
      Serial.println("Now: " + String(now) + " LastClappedTime: " +  String(lastClapTime));
      lastClapTime = now;
    }
  }
}

Schematics

claplight_XEJHAtkVr1.png
Claplight xejhatkvr1

Comments

Similar projects you might like

Arduino Controlled Artificial Candle Lights

Project tutorial by Mattias Larsson

  • 30,821 views
  • 14 comments
  • 51 respects

DIY RGB Tube Lights

Project tutorial by Mukesh Sankhla

  • 10,126 views
  • 4 comments
  • 19 respects

DIY Automatic Musical Christmas Lights (MSGEQ7 + Arduino)

Project tutorial by Just Barran

  • 1,017 views
  • 0 comments
  • 2 respects

Huge LED Christmas Lights

Project showcase by Savva Osipov

  • 19,031 views
  • 2 comments
  • 42 respects

Arduino Bike Blink Lights

Project showcase by Sam

  • 8,912 views
  • 3 comments
  • 15 respects
Add projectSign up / Login