Automatic Light Switch

by mattb0561 in Workshop > Home Improvement

80 Views, 3 Favorites, 0 Comments

Automatic Light Switch

lightswitch.jpeg
Lightswitchassembly.png

This main objective of this project was to create device that could flip a light switch when a person enters my room. It should also turn the light back off if it hasn’t detected movement for 5 seconds (This time is reasonable for testing only). The device uses an ultrasound sensor and a servo motor to achieve this. The ultrasound sensor is responsible for detecting motion within 10 inches of the device. This distance senses a person entering the room but doesn’t pick up anything past the door. The servo motor has custom attachments to allow it to connect to the light switch. These two parts combined with other essential microcontroller parts allow the device to operate. 

Supplies

Arduino photo.jpeg
Battery Pack photo.jpeg
Servo motor photo.jpeg
  • Generic Sparkfun Servo motor
  • Sparkfun ultrasonic distance sensor
  • Arduino microcontroller
  • Bread board
  • Battery pack with batteries
  • 3D printed plate
  • 3D printed Servo Crank Attachment
  • 3D printed Arm Attachment
  • 3D printed Cap
  • Velcro strips
  • Jumper Cables
  • Super Glue

Design the 3D Printed Parts

Plate .png
Servo Arm.png
Servo Crank Attachment.png

Plate should have enough space to fit the servo motor, the battery pack, the bread board, and the arduino microcontroller. My plate has a dedicate spot for the servo motor.

The servo crank attachment should have an inner diameter about .01 inches larger than the servo motor to prevent slipping when lifting and lowering the light switch. You might have to experiment with the diameter based on 3D printing tolerances. It should also have holes for the arm.

The arm should have a peg with an outer diameter .01 inches less than the holes of the crank. The rectangular hole can be adjusted based on the dimensions of you light switch.

Put the Device Together

IMG_3938.jpg
IMG_3939.jpg
  • I used hot glue to attach the battery pack, the servo motor, and the crank.
  • The crank is glued to the servo to prevent slipping.
  • The arm is attached to the crank with a cap.
  • You might need to use hot glue if you sand down the peg on the arm too much.
  • The arduino board is connected to the plate with a velcro strip, and the breadboard is connected to it with its own adhesive.
  • The back of the plate also has a velcro strip to connect to my wall

Develop the Code

Final project flowchart.jpg
Screen Shot 2024-05-09 at 11.09.44 PM.png

The flow chart gives the general outline of the code. My code was created in C++. Simply, if someone walks in front of the sensor the motor raises the arm to turn the light on. After a certain period of time it lowers it if no one is in front of the sensor.

Place the Board and Watch It Work

Assembled device on wall.jpg

The servo motor isn't strong enough so the video is just going be on my desk.

Downloads