Introduction: Hands-free Light Switch

Made by Tai (grade 8) :)

Here goes...(might be a bit boring and long, sorry, please skip it if so) So last week I wanted to play around with an Arduino and needed an excuse to do so; I set out to think of what might prove useful in this pandemic situation, and my thought landed on light switches, they are almost as commonly touched as doorknobs in public places, and mainly being made of Polycarbonate (commonly known as PC) or Acrylonitrile butadiene styrene (commonly known as ABS), they are capable of sustaining a virus for up to 3 days according to this article from business insider. In addition to rarely being cleaned for fear of electricity shorting or just pure laziness(aka me not cleaning properly), it is possible for the simple household light switch to become a medium to spread Sars-coV2-(also known as Coronavirus). The reason that I did not just outright buy a contactless light switch is because of the rarity of something that can be considered a novelty item. I know that an Arduino Uno is overpowered for such a simple application, and also oversized too, but it is one of the most common microcontroller boards, and the same with the type of distance sensor and relay that I have used because they come in most beginner kits, however, you are welcome to replace the components to those of your choosing and I would be glad to hear and assist you in the comments/email.

DISCLAIMER: This article is designed to simplify the process of safely creating a circuit that deals with high voltage(depending on your location up to 240 volts) so if you do not feel comfortable with such a project, or if you do not understand the dangers or are unable to complete your own risk assessment, please please for your own safety, don't do this and also, DO NOT DO THIS WITHOUT READING THROUGH THE WHOLE GUIDE AND UNDERSTANDING IT FIRST.

NOTE: This article was made purposefully slightly vague, and if you do not understand all steps fully, please do not attempt this for your safety

Supplies

any Arduino IDE compatible microcontroller (I am using an Arduino UNO+programming USB cable)

wires(22AWG required for any high voltage connections) breadboard jumpers(for Arduino-relay-sensor connections)

ultrasonic distance sensor

any 9-volt wall barrel jack plug(to power the Arduino, sensor and to energize the relay)

any relay module(has to be able to handle at least 125% of current, but it is recommended to use at least 150% required for safety purposes, any reasonably big relay should be able to handle enough current( find out by doing W/V=I where W is the rated bulb wattage and V is voltage)

soldering iron and solder

electrical tape

hot glue OR zip ties

a box(MANDATORY for safety purposes because of high voltage), has to be nonconductive otherwise it might short something out

Step 1: Programming

First, we need to program the Arduino as it might prove inaccessible when we are finished wiring, here is the code to be posted in Arduino IDE, configure to your liking then upload (guide to installing Arduino IDE here):

<pre>#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04<br>#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04
#define trigger_distance 4 //put your trigger distance here(connect to serial to adjust)in cm
#define relaypin 11 //pin the relay is on
// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
bool trigger = false;//is the light on or off when the arduino is reset?, valid values are true/false
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  Serial.begin(11520);
  Serial.println("ready");
}
void loop() {
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
  if(distance < trigger_distance){
    Serial.println("Triggered");
    trigger = !trigger;
        digitalWrite(relaypin, trigger);  // toggle LED
        delay(1000); //amount of time to wait for hand to leave trigger distance
    }
  }

Step 2: Wiring

wiring diagram for the bare relay(Tinkercad) is here

wire the Arduino to the sensor as such:

Arduino sensor

5V -----> VCC

D3 -----> TRIG

D2 -----> ECHO

GND -----> GND

wire the Arduino to the relay as such:

5V -----> VCC

GND -----> GND

D11 -----> IN

THE NEXT PART IS DANGEROUS AND SHOULD BE DONE BY QUALIFIED PEOPLE, IT IS DANGEROUS

DO NOT TURN ELECTRICITY BACK ON UNTIL YOU HAVE COMPLETED THE NEXT STEP

then wire the relay to light as such(turn of circuit breaker before proceeding, wire using 22AWG and solder connections to the mains):

1)cut the wire at the point labeled "cut here"(they can be found in the lightswitch socket)

2)wire one side to the COM of the relay and another to the NO of the relay(you might want to use the 22AWG to extend the wires out, screw the relay terminals tightly)

3)solder all connections with wires

4)wrap all loose connections in electrical tape

Step 3: Organising

1)put all in a box with a hole for the ultrasonic sensor, put the box somewhere accessible then mount it

2)attach all cables firmly to the box

3)plug-in 9volt power supply into Arduino then rout the cable out and plug it into a wall socket

4)close the lid and seal with some tape firmly ENSURE THAT THE LID IS NEVER OPENED BEFORE POWER IS DISCONNECTED

5)turn mains power back on

Step 4: Testing

now try and toggle the light by placing your hand in front of the ultrasonic sensor and see if the light toggles state after 1 second or before that, if so, congratulations! , you have finished, otherwise, check your wiring after turning electricity off, contact me at my email if it still is not working.

"Can't Touch This" Family Contest

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