Introduction: E-Switch

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (

The e-Switch is a device that uses an Arduino Uno, an IR receiver, and an HCSR04 proximity sensor to control a servo motor which is attached to a light switch. This product was created to save energy and add ease of access via remote control capabilities. The product differs from existing ones in that it is ready to install, only needing to be screwed in over an existing light switch, with no further assembly or wiring required. The materials required are listed below:

  • Arduino Uno
  • HCSR04 Proximity Sensor
  • IR Receiver + Remote
  • SG90 Servo Motor
  • 3D printer + PLA filament
  • Wires
  • Small Breadboard
  • Velcro
  • Electrical Tape

Step 1: Wiring

For this circuit there are 3 external components, the servo, proximity sensor, and IR receiver. All components are to be connected in parallel using the same ground and VCC supply.

  • IR receiver: The IR receiver has 3 pins, the left is the signal pin, which is connected to digital pin 2. The middle pin is the ground pin, and the last pin is the voltage pin which requires +5V.
  • HCSR04 Proximity sensor: The proximity sensor has 4 pins, from left to right they are VCC (+5V), Trig (pin 4), Echo (pin 3), and ground.
  • SG90 Servo Motor: The servo has 3 connections, red is VCC (+5V), brown is ground, and yellow is signal (pin 5).

Step 2: Code

*The code has been uploaded as a .rar file, must be unzipped*

The Arduino code uses the HCSR04 and the IR Receiver as inputs, whereas the servo motor is the only output. A variable dubbed "state" is used to record the servo motors current position. 0 corresponds to the servo being in the off position, 1 is indicative of the on position.

In the loop, the first step is to update the last recorded proximity sensor distance (lastValue), the next is to record the current distance (distance), then these values are compared. If the lastValue is greater than the current distance, then a hand is approaching, and the servo will turn 90 degrees down, turning off the lights, given that the current state is 1. Else, if lastValue is less than distance, a hand is retracting, and the servo will rotate 90 degrees upwards, turning on the lights, given that the current state is 0. If neither of these conditions are met, the IR receiver checks for signals and decodes them, producing "results". Depending on the result, the IR receiver will turn up or down. The code 0xFFE01F corresponds to the IR remotes plus button, and if received will rotate the servo upwards to turn on the light, given that the current state is 0. The code 0xFFA857 corresponds to the IR remotes minus button, and if received will rotate the servo downwards to turn off the light, given that the current state is 1. If neither signal is received, the code loops and continues searching (irrecv.resume).

Step 3: 3D Printed Components

For this project, two components had to be designed and printed, a light switch bracket for the servo, and a housing for all the components, that could readily fit over existing switches.

  • Light Switch Bracket: This piece was designed to hold a light switch between its prongs, it was also designed to attach to a servo motor, and has a hole for such.
  • The housing has 4 compartments: one for the proximity sensor, which is at the front-base of the housing, with a rectangular opening. Directly above this is a compartment for the Arduino and IR receiver, it has built in holes that lead to the other compartments (for wiring), as well as holes for screws. The back of the housing is hollowed out. The large area containing two prongs is the servo motor and breadboard compartment, the prongs are spaced and sized for mounting the servo motor. The smaller compartment is the last, and it is fitted for a 9V battery.

Step 4: Assembly

  1. Connect wires to the pins on the HCSR04, then place the sensor in its compartment, as depicted. Run the wires through the openings and to the servo motor compartment.
  2. Connect wires to the pins of the IR Receiver, then secure the receiver to the inner front panel of the Arduino compartment using electrical tape, ensuring the head of the receiver is jutting out from the side, as to prevent communication issues. Place as close to the top of the housing as possible. Run the wires down to the servo motor compartment.
  3. Run the battery connector cable through the longest hole in the housing, near the main opening. Ensure that both parts of the connector are on the appropriate side (Arduino connector to Arduino compartment, battery connector to battery compartment).
  4. Using a servo screw, connect the 3D printed light switch bracket to the servo motor as depicted. Then, mount the servo motor using the prongs, with wires pointing up.
  5. Use Velcro to install the breadboard.
  6. Before placing the Arduino in its housing, wire all the components to the breadboard, then to the appropriate Arduino pins. All components should have their power supplied in parallel. When finished, place the Arduino in its compartment, with the 9V battery port facing outwards.
  7. Place the 9V battery in its housing, and connect to the Arduino.

Step 5: Usage

To use the device, one can bring their hand towards the device to turn the lights off, or away from the device to turn the lights on. Pressing the IR remotes plus button will turn the lights on, and pressing minus will turn the lights off.