Easiest No-Touch Light Switch

Introduction: Easiest No-Touch Light Switch

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)

Step 1: The Code

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;

}

Step 2: Enclosure Part

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.

Step 3: Placing Everything Down

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.

Step 4: Positioning the Servo 1

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.

Step 5: Positioning the Servo 2

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

Step 6: Sides

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.

Step 7: Decoration and Finishing

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.

"Can't Touch This" Family Contest

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

Be the First to Share

    Recommendations

    • Maps Challenge

      Maps Challenge
    • DIY Summer Camp Contest

      DIY Summer Camp Contest
    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge

    2 Comments

    0
    natanonkitti
    natanonkitti

    Tip 10 months ago

    you might want to use a stronger servo, something like a 10 grams would do perfectly

    0
    Avengers3648
    Avengers3648

    Reply 10 months ago

    Thanks for the advice!