Introduction: DIY Smart Light Switch

About: IT Teacher (Andalucía, Spain)

This time I present you an easy and economic way to convert a touch toggle light switch with a face plate similar to the one in the image above, to a touchless one you can manage waving your hand or from your mobile.

In the next fall, my son will be entering to 6th grade and my little daughter to 3th grade.

I decided to build this invention because very soon a lot of kids will come at home to do homeworks or simply to play with my sons and I would like to create a little more secure environment for all for them.

I hope you like and be useful for somebody.

Supplies

  • One micro servo
  • One KY-032 Infrared Obstacle Avoidance Sensor Module
  • One NodeMCU ESP8266
  • One old mobile battery (3,7 V)
  • One DC-DC boost setp up converter (3,7 V to 5 V)
  • One micro USB battery charger
  • One breadboard
  • One plastic box
  • One little switch
  • Cardboard or plywood
  • Wood
  • Wires

Step 1: How It Works

The following demo video shows you how it works when we use our hands to switch on/off the lights

and how it works when we use the WiFi network to switch on/off the lights

Step 2: The Basics of the Project

To simulate the movement of a toggle single-pole light switch is very easy using a micro servo as you can see in following video

Because all the touch light switch at my home have the same face plate, I have built a touchless one I can controll waving the hands near the device or using a BLYNK app from my mobile.

Basically with this project you will be able to configure a DIY smart light switches network at home that you can control waving your hands independently or from your mobile without contact and avoiding spread the disease.

Step 3: Designing the Face Plate

How your project will look, will depend of the face plate of your light switch.

In the first image you can see the face plate of all light switch at my home.

After measuring it, I bought a plastic box, as you can see in the second image, to cover it leaving enough space for the electrical components.

Then, I cut a piece of cardboard taking into account the meassures of the plastic box and the light switch and I put on its final position as you can see in the last image.

Finally I designed two smalls labels where everybody can read how to switch on/off the light without touching the device.

Step 4: Placing the Servo and the KY-032 Infrared Sensor

Screw a piece of wood to the servo as you can see in the first image.

Glue the servo to one side of a piece of wood and to the tupperware for the other side taking into account the face plate.

Open a little hole to pass through it the pair of infrared LEDs and glue the sensor in that position as you can see in the image

Open little holes using a soldering iron on the top of the tupperware to avoid overheating as you can see in the last image.

Step 5: Preparing the Breadboard

Using a cardboard template, presents all the electrical components before connecting as you can see in the second image.
Choose a little mobile battery as you can see in the second image.
Connect and solder all the components as you can see in the first image:

  • The NodeMCU board
  • The little switch
  • The set up boost converter
  • The micro USB battery charge

Check if the battery charging works and the NodeMCU board receives 5V through the Vin pin.

In the last image you can see all the components connected before installing and ready to test them.

Finally, I have connected the servo to D8 pin and the infrared sensor to D5 pin.

Step 6: Creating the BLYNK App

To create a BLYNK app you have to do the following:

  1. Download and install the BLYNK for ARDUINO, ESP8266, RPi on your mobile
  2. Create an account
  3. Create a new project
  4. Add devices to the project to configure the smart light switches network as you can see in the first image
  5. The system will send you and e-mail with the "Auth Token" for each device you add
  6. This string will be use later in each NodeMCU ESP8266 code.

I have created a network with three smart light switches at the kids room, at the living room and at the kitchen (first image).

The others images show you to configure each device and the final project running.

Because finally I have only used three buttons, the BLYNK app is free.

Step 7: The Code in the NodeMCU ESP8266 Board

First, you have to select the NodeMCU board in your ARDUINO IDE.

You have to access to "Preferences" in your IDE and to specify in additional boards manager URL what you can see in the first image. After that you will have available the NodeMCU board

Install the BLYNK libraries in your ARDUINO IDE. You have to open the "Library Manager", search "BLYNK" and install it how you can see in the second image.

Basically the code is very easy but I want to highlight the following in the code:

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// You will receive it by e-mail
char auth[] = "hhdhdhyeyeyrfgdgdgdgdgdg";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "your ssid";
char pass[] = "your password"; 

The Auth Token string has been generated when you created the BLYNK app (see the previous step).

The previous code is all what you need to connect your code installed on your NodeMCU board with your app on your mobile.

The following code move the servo to switch on/off the light when we push the button on the app or when the input value from the infrared sensor (D5) is LOW as you can see in the "loop" section.

void TurnOffOn(int value) {
  if (value == LOW) {
    if (switch_position == 0) {
      switch_position = 1;
      myservo.write(55);
    } else {
      switch_position = 0;
      myservo.write(100);        
    }
  }  
}
// V2 pushed on APP. Switch on/off light switch
BLYNK_WRITE(V2) {
  int ledState = param.asInt();
  TurnOffOn(LOW);
}

void setup()
{ 
  myservo.attach(D8);
  pinMode(D5 , INPUT);  //definir pin como entrada
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
  int value = HIGH;
  value = digitalRead(D5);
  TurnOffOn(value);
  delay(500);
}

Step 8: Testing the Device

You can controll the smart light switch in two ways:

  1. Waving your hands as you can see in the following video
  2. Using your WiFi network and the BLYNK app from your mobile

Step 9: Others Implementations

I have used a NodeMCU ESP8266 board because I wanted create a smart light switches network but you can use an ARDUINO NANO board or simply an ATTiny85 microcontroller to implement this project if you only want your smart light switch works only waving your hands.

Thanks for reading this project.

"Can't Touch This" Family Contest

Participated in the
"Can't Touch This" Family Contest