Voice-controlled Light Switch

Introduction: Voice-controlled Light Switch

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.

Step 1: Tools and Materials

  • Arduino Uno
  • Breadboard
  • Sound Detector Board
  • Servo Motor
  • Jumper Cables

Step 2: Connecting the Sound Detector Board and Servo to the Arduino

Sound detector board connections
  1. Connect the pin labeled as 'envelope' on the sound detector board to the analog pin 0 on the Arduino.
  2. Connect the pin labeled as 'ground' on the sound detector board to the GND pin on the Arduino.
  3. Connect the pin labeled as 'VCC' on the sound detector board to the 3.3V pin on the Arduino.

Servo connections

  1. Connect the brown pin of the servo to the GND pin on the Arduino.
  2. Connect the orange middle pin of the servo to the 5V pin on the Arduino.
  3. Connect the beige pin of the servo to the digital pin 9 on the Arduino.

Step 3: Securing the Servo Motor

Tape the servo to provide enough counter-moment for the turning motion of the control horn.

Step 4: Coding

//include the servo library
 //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()
  // attach servo to pin 9
  // 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
  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);

Step 5: Demo

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!

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

Invention Challenge 2017

Participated in the
Invention Challenge 2017

Be the First to Share


    • Microcontroller Contest

      Microcontroller Contest
    • Automation Contest

      Automation Contest
    • Make it Glow Contest

      Make it Glow Contest



    2 months ago

    when i run the code the servo moves back and forth non stop regardless of sound.


    Question 2 years ago

    exit status 1

    'servo1' was not declared in this scope

    the code its not working can you help