Introduction: Automatic Lighting Management Using Ambient Sounds

This instructables will show you how to simply turn on your LYT bulbs when ambient souds are detected.

You can use it to maintain your lights powered ON when people are in a room and power OFF them when no more sounds are detected. With small modifications you can also create nice effects like power ON and OFF the lights clapping your hands.

Moreover this project can be used also as a simple deterrent for thieves and power ON LYTs when sounds are detected in your absence from home (of course you can add many more sensors to complete and customize it as a real powerful alarm).


For this project you will need the following (over your arduino):

-One Authometion LYT/WiFi shield (www.authometion.com/shop)

-One or more Authomeiton 9W RGB-W LYT radio bulb (www.authometion.com/shop)

-One Adafruit Electret Microphone Amplifier (https://www.adafruit.com/products/1063)

Step 1: Interface the Microphone to the Arduino

Connect the VCC Microphone pin to 3.3V arduino pin and the GND Microphone pin to one arduino GND pins.
For the best performance, use the "quietest" supply available (on an Arduino, this would be the 3.3V supply).

Then connect the OUT Microphone pin to the arduino A0 analog input.

The audio waveform will come out of the OUT pin. The output will have a DC bias of VCC/2 so when its perfectly quiet, the voltage will be a steady VCC/2 volts (it is DC coupled).

Step 2: Clap Your LYT!

Now it's time to use your hands.

With this sketch you can control your LYTs clapping your hands!!

One clap power ON. Two claps power OFF.

You can adjust sound sensitivity increasing or decreasing the SOUND_LEVEL value.

The sketch will counts the number of claps generated within CHECK_TIME millisecons (in this case 1000).

Between one detection and the other has been introduced a DETECT_DELAY (150 ms) to avoid multiple clap detection.

Play with any of the previous values to suit your needs.

You can also customize the sketch to recognize more claps or a specific sequence of claps!

**PLEASE REMEMEBR THAT AUTHOMETION LYT IS A 2.4GHz RADIO CONTROLLED E27 RGBW BULB AND YOU CAN WIRELESS CONTROL IT USING A LYT/WiFi Shield**

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * *<br> Code by AUTHOMETION S.r.l.
 Version: 1.00
 Date: 02.06.2015
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <SPI.h>
#include <PL1167.h>
#include <EEPROM.h>
#include <Lytwifi.h>
#include <SoftwareSerial.h>
#include <WiFiInterrupt.h>
#define PL1167_CS_PIN     10
#define BULB_ADDRESS_HIGH 0
#define BULB_ADDRESS_LOW  0
#define SOUND_LEVEL 100
#define CHECK_TIME 1000
#define DETECT_DELAY 150
int CLAP = 0;
int PULSE = 0;
int FLAG_WAIT = 0;
long BtnDelay;
//ESP8266 Serial
SoftwareSerial mySerial(5, 6); // RX, TX
LYTWiFi myNetWork(mySerial);
void setup()
{
  Serial.begin(9600, SERIAL_8N1);
  myNetWork.vfInitialize(PL1167_CS_PIN);
  vfISRInit(&myNetWork);

}
void loop()
{
  int adc_sound;
  adc_sound = analogRead(0);
  //CONNECT MICROPHONE VCC TO ARDUINO 3.3VDC FOR BETTER PERFORMANCE
  adc_sound = abs(adc_sound - 350); // Center on zero (3.3VDC)

  //CLAP DETECTED
  if (adc_sound > SOUND_LEVEL)
  {

     BtnDelay = millis();
     if (FLAG_WAIT == 0)
     FLAG_WAIT = 1;
     CLAP++;    
     Serial.println("\r\nCLAP++");


     //Delay to avoid multiple clap detection
     delay(DETECT_DELAY);
    
  }
  
  //AFTER ONE SECOND (CHECK_TIME=1000) CHECK HOW MANY CLAPS DETECTED
  if ((millis() - BtnDelay > CHECK_TIME) && FLAG_WAIT == 1)
  {

    if (CLAP == 1)
    {

 
      myNetWork.ui8fSwitchOnAndCheck(BULB_ADDRESS_HIGH, BULB_ADDRESS_LOW, C_MULTICAST);
      Serial.println("\r\nLYT ON");
    }
    else if (CLAP == 2)
    {
      myNetWork.ui8fSwitchOffAndCheck(BULB_ADDRESS_HIGH, BULB_ADDRESS_LOW, C_MULTICAST);
      Serial.println("\r\nLYT OFF");
    }
    
    FLAG_WAIT = 0;
    CLAP = 0;
   }

}

Step 3: Our Video!

Step 4: Listen Sounds Around You

Here our second sketch that will power ON your LYTs when sounds are detected and keeps lit until the background noise does not fall below the threshold level SOUND_LEVEL and DELAY time has expired.

**PLEASE REMEMEBR THAT AUTHOMETION LYT IS A 2.4GHz RADIO CONTROLLED E27 RGBW BULB AND YOU CAN WIRELESS CONTROL IT USING A LYT/WiFi Shield**

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 Code by AUTHOMETION S.r.l.
 Version: 1.00
 Date: 02.06.2015
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <SPI.h>
#include <PL1167.h>
#include <EEPROM.h>
#include <Lytwifi.h>
#include <SoftwareSerial.h>
#include <WiFiInterrupt.h>
#define PL1167_CS_PIN     10
#define BULB_ADDRESS_HIGH 0
#define BULB_ADDRESS_LOW  0
#define SOUND_LEVEL 100
#define DELAY 1000 //10 seconds (DELAY*10)
byte SOUND_DETECTED=0; 
long COUNTER=0; 
//ESP8266 Serial
SoftwareSerial mySerial(5, 6); // RX, TX
LYTWiFi myNetWork(mySerial);
void setup() 
{
  Serial.begin(9600, SERIAL_8N1);
  myNetWork.vfInitialize(PL1167_CS_PIN);
  vfISRInit(&myNetWork);
  
}
void loop() 
{
    int adc_sound;
   
    adc_sound=analogRead(0);  
      
    //CONNECT MICROPHONE VCC TO ARDUINO 3.3VDC FOR BETTER PERFORMANCE    
    adc_sound=abs(adc_sound - 350);// Center on zero (3.3VDC)
      
      
    if(adc_sound>SOUND_LEVEL && SOUND_DETECTED==0) 
    {
        SOUND_DETECTED=1;
        COUNTER=0;
        Serial.println(adc_sound);   
	Serial.println("\r\nPOWER ON");
        myNetWork.ui8fSwitchOnAndCheck(BULB_ADDRESS_HIGH, BULB_ADDRESS_LOW, C_MULTICAST);
        adc_sound=0;
    }      
      
    //LYT IS ON BUT SOUNDS STILL DETECTED SO RESET COUNTER
    if(adc_sound>SOUND_LEVEL && SOUND_DETECTED==1)
    {
      COUNTER=0;
      Serial.println("\r\nCOUNTER RESET"); 
    }
    //IF DELAY REACHED POWER OFF LYT
    if(COUNTER>=DELAY)
    {
        SOUND_DETECTED=0;
        COUNTER=0;
        Serial.println("\r\nPOWER OFF");   
        myNetWork.ui8fSwitchOffAndCheck(BULB_ADDRESS_HIGH, BULB_ADDRESS_LOW, C_MULTICAST);
    
    }  
    
    //INCREASE COUNTER IF LYT IS ON
    if(SOUND_DETECTED==1)
      COUNTER++;
   
    
    //TIME BASE 10ms
    delay(10);
    
}

Step 5: Our Video!

Comments