Voice-controlled Light Switch
![2016-07-22 16.47.21.jpg](/proxy/?url=https://content.instructables.com/FY2/1I9D/J5K5ZBMP/FY21I9DJ5K5ZBMP.jpg&filename=2016-07-22 16.47.21.jpg)
Sometimes, I just don't want to get out of the bed to turn off the light. I've always wished I can just control the lights remotely so that it turns off when I command it to. This project accomplishes just that. It gives users control of any light by using a servo motor to control a light switch. Using a sound detector board as an input, the Arduino can move a servo at a given level of sound such that the light switch is toggled on or off.
Tools and Materials
![2016-07-22 13.40.37.jpg](/proxy/?url=https://content.instructables.com/F8D/VIZP/J5K5ZBIY/F8DVIZPJ5K5ZBIY.jpg&filename=2016-07-22 13.40.37.jpg)
- Arduino Uno
- Breadboard
- Sound Detector Board
- Servo Motor
- Jumper Cables
Connecting the Sound Detector Board and Servo to the Arduino
![2016-07-22 16.47.15.jpg](/proxy/?url=https://content.instructables.com/F3Y/2XH1/J5K5ZBML/F3Y2XH1J5K5ZBML.jpg&filename=2016-07-22 16.47.15.jpg)
- Connect the pin labeled as 'envelope' on the sound detector board to the analog pin 0 on the Arduino.
- Connect the pin labeled as 'ground' on the sound detector board to the GND pin on the Arduino.
- Connect the pin labeled as 'VCC' on the sound detector board to the 3.3V pin on the Arduino.
Servo connections
- Connect the brown pin of the servo to the GND pin on the Arduino.
- Connect the orange middle pin of the servo to the 5V pin on the Arduino.
- Connect the beige pin of the servo to the digital pin 9 on the Arduino.
Securing the Servo Motor
![2016-07-22 14.18.27 copy.jpg](/proxy/?url=https://content.instructables.com/F8W/NS29/J5K5ZBLD/F8WNS29J5K5ZBLD.jpg&filename=2016-07-22 14.18.27 copy.jpg)
Tape the servo to provide enough counter-moment for the turning motion of the control horn.
Coding
![Screen Shot 2017-07-28 at 1.37.21 AM.png](/proxy/?url=https://content.instructables.com/FMA/S6KX/J5MQ9VEF/FMAS6KXJ5MQ9VEF.png&filename=Screen Shot 2017-07-28 at 1.37.21 AM.png)
//include the servo library
#include //pin variable
const int soundPin = 0; const int servoPin = 9; int clap_on = 0;
// declare servo Servo servo1;
//variables for storing raw sound and scaled value int sound;
void setup() { Serial.begin(9600); // attach servo to pin 9 servo1.attach(servoPin); // always initialize the servo as light off. servo1.write (180); servo1.write (150); clap_on = 0; }
void loop() { //read and store the audio from Envelope pin sound = analogRead(soundPin); //map sound which in a quiet room a clap is 300 //from 0 to 3 to be used with switch case
//print values over the serial port for debugging Serial.println(sound);
if (sound > 20){ if (clap_on == 0){ // check if the servo still hasnt rotated servo1.write(150); // turn light on clap_on = 1;} // set a toggle on clap so then next time it //happens it will turn the light off else if (clap_on == 1){ servo1.write(180); // turn light off clap_on = 0;} // set toggle again. } delay (500); }
Demo
![Voice Controlled Light](/proxy/?url=https://content.instructables.com/FRR/1YC8/J5K5Z8X6/FRR1YC8J5K5Z8X6.jpg&filename=Voice Controlled Light)
The sound module is actually not analyzing the commands I give it as information, but rather as sound signals only. That is, I can clap, snap, or make any other sound to turn it on or off. In this case, voice control worked perfectly!