Don't Touch the Light Switch

Introduction: Don't Touch the Light Switch

Hi, i'm Aviv Friedman, i'm from Israel and i started 8th grade this month.

When you walk into a dark room, the first thing you naturally want to do is to turn on the light. But who touched that light just before you? Is it worth the risk, or better just to stay in the dark? You no longer will have to face this dilemma with the "don't touch the light switch" device.

Step 1: Make the Circuit

Connect the servo, the distance sensor, and the battery holder to the Arduino Pro Mini. The wiring is shown in the diagram:

Servo:

yellow wire to 8

Black wire to GND

Red wire to VCC

Distance sensor:

VCC to VCC

Trig to 9

Echo to 10

GND to GND

Battery holder:

Red to RAW (not VCC!!!)

Black to GND

Step 2: Coding

You need to use a programmer to upload the code to the Arduino. Make sure the battery is not connected when you do the upload. The program is here:

#include <Servo.h>
Servo myservo;
bool x = 0;
int pos = 0;
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
  //myservo.attach(8);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  Serial.print("Distance: ");
  Serial.println(distance);
  // The minimum distance needed to activate the switch
  if (distance < 10)  {
    x = !x;

    if (x == 0) {
      myservo.attach(8);
      for (pos = 0; pos <= 180; pos += 50) {
        // in steps of 1 degree}
        myservo.write(pos);
        delay(500);
        myservo.detach();
        // waits 15ms for the servo to reach the position
      }
    }
    if (x == 1) {
      myservo.attach(8);
      for (pos = 180; pos >= 0; pos -= 50)
      { myservo.write(pos);
        delay(100);
        myservo.detach();
      }
    }
    delay(500);
  }
}

Step 3: Make the Wooden Button and Connect the Servo

Connect a piece of wood (approximately 4 cm by 2 cm by 1 cm) to the servo using one of the connectors that comes with the servo. Connect another piece of wood (approximately 5.5 cm by 4 cm by 1.5 cm), e.g. using tape, to the side of the base of the servo (so it will be the right distance from the switch). Adjust the thickness appropriately based on how far the switch is from the wall.

Step 4: Attach to the Wall

Attach the servo (with the piece of wood attached) to the wall using blutack.

Step 5: Make the Switch More Friendly

In order to make the switch more friendly, cut out a robot shape from a piece of light cardboard. Make holes for the distance sensor (i.e., the eyes). Feel free to decorate as you wish (e.g. mouth, etc.). Use blutack to attach the robot to the wall.

Move your hand next to the robot's eyes to turn the switch on or off.

"Can't Touch This" Family Contest

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

Be the First to Share

    Recommendations

    • Micro:bit Contest

      Micro:bit Contest
    • Plastic Challenge

      Plastic Challenge
    • Halloween Contest

      Halloween Contest

    Comments