Motion Activated Light Switch

by CSpencer in Circuits > Arduino

346 Views, 4 Favorites, 0 Comments

Motion Activated Light Switch

Picture2.jpg
Picture4.jpg
Picture6.jpg

This project is an attachment to existing light switch covers and allows the user to wave their hand over the distance sensor to activate the light switch. In its existing configuration, it would turn the light switch on/off when the user waves their hand close to the sensor - thus allowing someone with mobility issues to easily use the light switch instead of flipping it directly. However, this could easily be configured in a way that toggles the light switch on whenever there's a recent movement in the general vicinity (and turn it off once it recognizes no one is in the room anymore or movement is idle).

The light switch is toggled by a micro servo with an attachment that allows it to toggle the light switch on and off again. There are also light indicators that blink when the system is idle and are solid when it is in the process of flipping the switch. However, this is obviously configurable if the blinking might annoy someone. The thought process is to direct someone where the sensor is when the room is dark while also providing some feedback information.

In order to use this, you'd first need to install it over an old light switch cover and provide it power (a fun modification could be to hitch off of the wall power and use a buck converter to keep the wiring tidier). Once it's plugged in, all you have to do is wave your hand within 20 centimeters of the light switch, and it will rotate the servo to flip the switch. Repeating this action will flip it in the opposite direction to turn the lights off.

Supplies

  • Arduino Uno
  • Micro Servo (sg90)
  • LED 2x
  • 220-ohm Resistor 2x
  • Ultrasonic Distance Sensor (hr-sr04)
  • Adafruit Proto-Sheild
  • Wire & Soldering Iron
  • 3D printed parts 2x
  • Assorted Screws (comes with Arduino Uno and Micro Servo)

Design Brainstorming

Picture20.jpg

The first sketches of this project initially included a light sensor, but as I was designing it in tinkerCAD, I realized there may be some sort of conflict with the LEDs or other light sources and that the state of the lightswitch can just be held by the microcontroller in memory.

Circuit Planning

Picture7.png

This circuit diagram was planned out using tinkerCAD circuits. It's an extremely useful tool for planning Arduino circuits - you can even get the code working within the online simulations. This visual is excellent for anyone looking to recreate this project since it can be traced - unlike the god-awful wiring in the pictures :).

CAD Modeling

Picture17.png
mark_III_2022-Nov-28_03-37-45PM-000_CustomizedView17872374207_jpg.jpg
mark_III_2022-Nov-28_03-37-20PM-000_CustomizedView1118451068_jpg.jpg
mark_III_2022-Nov-28_03-36-20PM-000_CustomizedView10878785565_jpg.jpg

The 3D model was made with onshape. I did import the .step file into fusion 360 to make some renders. The components were imported from grabcad to test spacings (not crediting here because I have no idea where those links went).

The main housing was designed in a way that it could replace an existing light switch cover. I first used dimensions from a light switch to create that outline, but I extended it outward to make room for the rest of the electronics. The servo's position is as close as it can get to the lightswitch so it can fit with it behind the drywall. The micro servo and the Arduino Uno have screw holes (not threaded), and the other electronics are friction fitted. The extension to the servo did need to be hot glued a little, though, since it was falling off with just the friction mount.

Engineering Drawings

Picture8.png
Picture9.png
Picture10.png

Engineering drawings generated with onshape.

Programming

Picture11.png

Hopefully, this flowchart demonstrates exactly how the program operates. It essentially repeatedly grabs the current distance from the ultrasonic sensor and checks if the distance is sub 20cm. If it is, it'll flip the switch to the opposite position than it is currently; otherwise, it'll blink the lights and keep checking the distance.

I was worried at first that noise on the ultrasonic would compromise this setup, so I started to develop a running-average system, but I scrapped it since it wasn't much of an issue.

3D Printing, Construction, and Design Iterations

Picture16.jpg
Picture5.jpg

It took me a few tries to get the spacing correct for each part - some of them were due to negligence, and other times to tolerance issues. The hardest spacing to figure out was that for the ultrasonic - ultimately, I needed to drill out the insides a little to make it work, but I fixed it in the CAD if anyone wants to print it and happens to have the same ultrasonic sensor. Although, fair warning, it needs to be the exact one on the parts list since there are a few different versions.

With this project, I also included the protoboard because it allowed the components to be soldered permanently, whereas all the wires won't fling out and ruin everything. Most of the soldering is done underneath the protoboard, so it can't exactly be copied, but following the electrical circuit plan from the tinker cad will serve as a good template.

Design Limitations

In some instances, the servo is programmed to wind back for more momentum to flip the switch. A more thoughtfully designed attachment to the micro servo would allow more torque to be applied in the correct direction and make this hacky coding solution unnecessary. I also noticed that sometimes the servo attachment could slide over the light switch so maybe the servo itself could be lowered a bit or the attachment could be changed to be a tad thicker.

I also wish this project was done with more of a Arduino Nano hidden electronics vibe tucked behind the wall or behind some thoughtfully designed cover but I was working with some restrictions as I made this for an engineering class.

Video Demonstration

Light Switch Demo