Easiest No-Touch Light Switch

by Avengers3648 in Circuits > Arduino

676 Views, 2 Favorites, 0 Comments

Easiest No-Touch Light Switch

Untitled drawing (4).jpg

Hello my name is Asher and i am going into the 8th grade. i had an idea to make a light that turns on whenever you swipe your hand in front of it. my inspiration for this was an automatic paper towel dispenser. i hope you enjoy making this.

Supplies

  • cardboard
  • servo
  • ultrasonic sensor
  • arduino uno
  • hot glue gun
  • paper (optional)

The Code

Fantastic Jaiks.png
IMG_1910.JPG

Ultrasonic sensor pins: Trig-4, Echo-2

Servo pin: 9

my code may have some errors because my servo stopped working while i was still testing it. I used tinkercad for the final testing and coppied and pasted from there so there may be errors from that. also make sure comment bellow if there are any problems and I will do my best to help. make sure to use the servo head with an arm on each side!!!

# include

Servo myservo;

const int trigPin = 2;

const int echoPin = 4;

void setup() {

Serial.begin(9600);

myservo.attach(9);

}

void loop() {

long duration, cm;

pinMode(trigPin, OUTPUT);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(20);

digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

cm = microsecondsToCentimeters(duration);

if (cm > 7 && cm < 14) {

myservo.write(180);

delay(2000);

}

else if (cm < 8) {

myservo.write(10);

delay(100);

}

else {

myservo.write(10);

delay(100);

}

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(100);

}

long microsecondsToCentimeters(long microseconds) {

return microseconds / 29 / 2;

}

Enclosure Part

IMG_1882.JPG
IMG_1883.JPG
IMG_1885.JPG

to make the enclosure measure how big the light switch you are going to use is for me that was about 4.5 by 4.5 inches mark that down on a piece of cardboard with about 5 inches on either side. place all of the hardware around the box and leave about 1-2 inches on the top and sides and about 4-5 inches on the bottom, cut it all out. now recreate the same thing except without any hole. check all of it against the pics above.

Placing Everything Down

IMG_1900.JPG

now place down your arduino in the spot of your choice right now you need to decide where you want your ultrasonic sensor to be mine will be on the bottom right. tape or glue down your board and cable manage all the wires except the ones for the servo.

Positioning the Servo 1

IMG_1904.JPG
IMG_1937.JPG

place the cardboard around the light switch and potion the servo so the center point is at the center of the switch. trace the area of the servo that is still on the cardboard. cut out about 3 small pieces of cardboard the size of the area you just traced, we will use these in the next step.

Positioning the Servo 2

IMG_1950.JPG
IMG_1951.JPG
IMG_1959.JPG
IMG_1962.JPG
IMG_1976.JPG
IMG_1977.JPG

glue all the pieces from the step before together and then glue them to the area you just traced. glue the servo to these pieces. the servo should now be flush with the light switch. now what you will need to do is get an idea of how thick you would like your enclose to be for me that is 1.5 in. now measure the distance between the top of the servo to the bottom of the cardboard. subtract that number from 1.5 write the number down. now make small cardboard pieces the same size as the ones below the servo the the added depth of these pieces should be the number you wrote earlier. glue all of these pieces together and then glue them to the top of the servo. This will hold the servo in place. I am taping my servo instead of gluing because i will switch it out when i get one. sorry about the blurry photos i couldnt get it to focus

Sides

IMG_1901.JPG
IMG_1980.JPG
IMG_1982.JPG
IMG_1984.JPG

draw and cut out the outline of the "eyes" of the ultrasonic sensor. push the ultrasonic sensor through. now make the walls of the enclosure and make sure to leave a small hole for your arduino so you can plug it in or edit the code if needed.

Decoration and Finishing

FB863BPKED4WE1D.jpg

you can now decorate your box, i just put a piece of white paper with a diagonal blue stripe to match the room it is in. you will now need to get it to the wall, i would recommend using two sided sticky foam. you are now finished with your light! if you are pluging it into a wall you should use a 12v power adapter like like the one that comes with an iPad.