DIY HOME AUTOMATION - Replace Traditional Light Switches

Introduction: DIY HOME AUTOMATION - Replace Traditional Light Switches

Turn on or off LIGHTS using touch sensors


  • Capacitive touch sensors are used to turn on the lights instead of traditional mechanical switches.
  • PIR Sensors for automated lights.

Step 1: Materials Needed

1. ESP8266 shield - Product - A5-- ESP8266 serial WIFI model ESP-12 ESP-12E ESP12F Authenticity Guaranteed ESP12

2. Arduino UNO - Product - UNO R3 Development Board ATmega328P CH340 CH340G For Arduino UNO R3 With Straight Pin Header 3. Arduino Mega - Product - Mega 2560 R3 Board 4. Breadboard - Product - MB102 Breadboard 5. Jumper wires - Product - Male + Female to Male and Female to Female Jumper Wire Dupont Cable for arduino DIY KIT

Step 2: LIGHTS- Selecting the Pins for Touch Sensors and Relays

Here 4 capacitive touch sensors are used. Each one is use to turn on or off the light.

How it works? When the sensor the pressed it activated a relay. The light connected to the relay is then activated. To turn off the light the sensor is pressed again.


Pin 22 - Touchsensor1

Pin 23 - Touchsensor2

Pin 24 - Touchsensor3

Pin 25 - Touchsensor4


Pin 26 - Input 1 of relay (Relay1)

Pin 27 - Input 2 of relay (Relay2)

Pin 28 - Input 3 of relay (Relay3)

Pin 29 - Input 4 of relay (Relay4)


Touchsensor1 activates Relay1 and so on...

Step 3: LIGHTS - Selecting Pins for PIR Sensors and Relay

There are two lights that are activated by the PIR sensors.


Pin 30 - PIR1

Pin 31 - PIR2


Pin 32 - Input 5 of relay (Relay5)

Pin 33 - Input 6 of relay (Relay6)


PIR1 activates Relay5

PIR2 activates Relay6

Step 4: Programming the Arduino

// Pins for capactitive touch sensor

#define TouchSensor1 22

#define TouchSensor2 23

#define TouchSensor3 24

#define TouchSensor4 25

// Pins for PIR sensors

int PIR1 = 30; //
int PIR2 = 31; //

int val1 = 0;
int val2 = 1;

boolean currentState1 = LOW;
boolean lastState1 = LOW;

boolean RelayState1 = LOW;

boolean currentState2 = LOW;

boolean lastState2 = LOW;

boolean RelayState2 = LOW;

boolean currentState3 = LOW;

boolean lastState3 = LOW;

boolean RelayState3 = LOW;

boolean currentState4 = LOW;

boolean lastState4 = LOW;

boolean RelayState4 = LOW;

// Pins for relay

int Relay1 = 26;

int Relay2 = 27;

int Relay3 = 28;

int Relay4 = 29;

int Relay5 = 32;

int Relay6 = 33;

void setup() {
//define relays as output

pinMode(relay1, OUTPUT);

pinMode(relay2, OUTPUT);

pinMode(relay3, OUTPUT);

pinMode(relay4, OUTPUT);

pinMode(relay5, OUTPUT);

pinMode(relay6, OUTPUT);

//define touch sensors as input

pinMode(TouchSensor1, INPUT);

pinMode(TouchSensor2, INPUT);

pinMode(TouchSensor3, INPUT);

pinMode(TouchSensor4, INPUT);


CLICK ON THE FILE X.ino to download.


Step 5: CIrcuit Diagram - Wiring Light to Relay

This picture is self- explanatory.

Beware risk of electric shock

Be the First to Share


    • Halloween Contest

      Halloween Contest
    • Fandom Contest

      Fandom Contest
    • Crayons Challenge

      Crayons Challenge


    Akshay Koonja
    Akshay Koonja

    Reply 3 years ago

    i'll work on that soon


    3 years ago

    Good job Akshay


    3 years ago on Step 5

    Great idea, interested in it myself as doing home renovation. Few questions:
    How to cover the touch sensors? Plaster over?
    How to connect it and control it with another smart home system to unify with Zigbee / Z-wave supporting system?
    I guess once connected to a smart home system, can also work with Alexa / Siri / Google, or any other way?

    Akshay Koonja
    Akshay Koonja

    Reply 3 years ago

    You can use silicon paste to cover it or mold a casing for the sensor
    I don't know about zigbee but if the arduino can be connected to wifi maybe it might work with Alexa,etc


    3 years ago

    I've been mulling over something similar to this for a while now. This looks nicely done.

    This approach has lots of benefits that can be taken advantage of - like having two switches for one light (wiring diagram?).

    Do you have any photos of the final appearance of the touch sensitive pads? I'm curious how they look.

    Akshay Koonja
    Akshay Koonja

    Reply 3 years ago

    thanks.. two switches can be used as a 2 - way switch.
    this is only part of a bulky project so i don't have any pictures to illustrate this one.