Wouldn’t it be cool to have a house with futuristic technology, where everything is automated or computer controlled? Well, here’s a couple ways to rig up a little tech and coolness into your life! For both versions of this project, the same Arduino controlled light switch will be used, so let’s make that first.

 

Arduino Switch

The Parts

The robotics parts

DFRobot Romeo Microprocessor

HC-SR04 Ultrasonic Object Detector

2WD Mini Robot Platform Kit

Power Supply

Frame Material (I used lumber)

Lightswitch

Lamp

 

Connecting Everything Together

Connection diagram

The ultrasonic sensor’s trig pin is connected to pin 2 on the Romeo board, and the echo pin is connected to pin 3 on the board. Vcc goes to the 5v pin on the board, and Gnd goes to Gnd.

The motor is connected to M2, which means it is controlled by digital pins 6 and 7 on the board.

 

Building The Frame

You will need to build some kind of frame to mount everything on. I used lumber because it’s easy to work with and I had some lying around. It doesn’t have to be perfect unless you want a professional look, so just put something together and don’t worry.

 

As long as the center of the wheel is at the same height as the center of the switch, and the switch is between the wheel spokes, it will work fine.

 

Wiring The Switch

I used a regular lightswitch and just wired it into the hot wire of an old lamp. The hot wire is the narrower prong on the plug. Just cut the hot wire and strip the ends. Do not cut the neutral wire (The wide prong on the plug). On the switch I used, the wire coming from the wall connects to the bottom screw on the switch and the wire going to the lamp connects to the top screw.

DO NOT WIRE THE SWITCH WITH THE CORD PLUGGED INTO THE WALL OR ANY OTHER POWER SOURCE!!! I AM NOT RESPONSIBLE FOR YOU BEING AN IDIOT!!! THE AMOUNT OF ELECTRICITY COMING FROM A WALL OUTLET CAN KILL YOU!!!

VERSION 1: The Touchless Switch

If you want to make the Touchless Switch, you are done building! This version is cool because all you have to do is wave your hand in front of the sensor to turn the switch on or off. Plus, think about all the germs not being spread! Time to upload the code and test it all!

Uploading The Code

Uploading code to the board is easy!

1. Download and install the Arduino IDE on your computer.

2. Plug in the board to the computer.

3. Select “Arduino Uno” from the Tools -> Board menu, if you are using the DFRobot Romeo board I recommended.

4. Copy and paste the code from this page into the IDE.

5. Click the upload button and you’re finished!

Here is the code:

int trigPin = 2;    
int echoPin = 3;    
long duration, inches;
int thing = 0;
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(7, OUTPUT);
}
void loop()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  inches = (duration/2) / 74; 
  delay(200);
  while(inches<=8){
    if(thing==0){
      thing=thing+1;
      analogWrite(6,127);
      digitalWrite(7,HIGH);
      delay(100);
      analogWrite(6,0);
      delay(100);   
      break;
    }
    if(thing==1){
      thing=thing-1;
      analogWrite(6,127);
      digitalWrite(7,LOW);
      delay(100);
      analogWrite(6,0);
      delay(100);
      break;
    }
  }
}

VERSION 2: The Floating Magnet Switch

Another option for building the switch is to use magnets to control the switch. This is more for adding that “cool factor” to the project than function.

The Parts

A Shoe Box

Magnets

String or Wire

 

Building The Frame

Attach your magnets to your string or wire. I used wire because I didn’t have any string lying around. Poke a hole in the top and the bottom of the shoe box so you can run the strings or wires through. Tie them off on the outside of the box.

 

Make sure the magnets aren’t too far apart. If the magnets are too close, all you have to do is tie knots onto the string or wire on the inside of the box to pull the magnets further apart.

 

Once the magnets are attached to the box properly, stand the box up and hang the bottom magnet from the top one. Poke a hole in the side of the box at about the height of the top magnet. Run the wires for the ultrasonic object detector through this hole and then attach the sensor to the wires. Position the sensor so it is aiming at the bottom magnet.

Afterwards, follow the steps above to upload code to the board, but use this code instead:

int trigPin = 2;    
int echoPin = 3;    
long duration, inches;
int switchState = 0;
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(7, OUTPUT);
  pinMode(13,OUTPUT);
}
void loop() {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(5);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    pinMode(echoPin, INPUT);
    duration = pulseIn(echoPin, HIGH);
    inches = (duration/2) / 74; 
    delay(200);
    while(switchState==0) {
      if(inches>5){
        break;
      }
      if(inches<=5) {
          switchState=1;
        analogWrite(6,127);
        digitalWrite(13,HIGH);
        digitalWrite(7,HIGH);
        delay(100);
        analogWrite(6,0);
        delay(100);   
        break;
      }
    }
    while(switchState==1) {
      if(inches<=5) {
        break;
      }
      if(inches>5) {
        switchState=0;
        analogWrite(6,127);
        digitalWrite(13,LOW);
        digitalWrite(7,LOW);
        delay(100);
        analogWrite(6,0);
        delay(100);
        break;
      }
    }
}

Like I said, this is a fairly easy project with a pretty cool payoff. Try it yourself and let me know what you think!

23 COMMENTS

  1. Simply desire to say your article is as astounding.

    The clearness in your post is simply cool and i can assume you’re an expert on this subject.
    Well with your permission let me to grab your RSS feed to keep up to date with forthcoming
    post. Thanks a million and please keep up the rewarding work.

  2. Wow! This blog looks exactly like my old one! It’s on a entirely different subject but it has pretty much the same page layout and design. Excellent choice of colors!

  3. I have been surfing on-line more than three hours lately, yet I
    never found any attention-grabbing article like yours.
    It is beautiful worth sufficient for me. Personally, if all website owners and bloggers
    made good content as you probably did, the net shall be a lot more helpful than ever before.

  4. Hi this is kinda of off topic but I was wanting to know
    if blogs use WYSIWYG editors or if you have to manually code with HTML.

    I’m starting a blog soon but have no coding experience so
    I wanted to get guidance from someone with experience.
    Any help would be enormously appreciated!

  5. Hello my lkved one! I wish to say that this article is amazing, great written and come with
    almost all significant infos. I’d like to look extra posts like this.

  6. I’m only commenting to inform you of the outstanding experience our girl encountered reading
    the blog. She noticed several pieces, which included how like to possess
    an incredible giving nature to get certain people really easily learn certain multifaceted things.
    You undoubtedly exceeded visitors’ desires. I appreciate you for
    rendering the important, healthy, educational in addition to easy tips regarding the topic.

  7. Incredible! This can be one of the most beneficial
    blogs i’ve ever arrive across on this subject.
    In fact this is fantastic. I’m also an experienced in this topic so I can understand your effort.

  8. Excellent post. I used to be checking continuously
    this blog and I am inspired! Extremely useful information particularly the ultimate phase 🙂
    I take care of such information much. I
    was seeking this particular info for a long time. Thanks and good luck.

  9. Very good website you have here but I was curious about if you knew of any user discussion forums that cover the same topics discussed here?

    I’d really like to be a part of community where I
    can get advice from other experienced people that share the
    same interest. If you have any recommendations, please let me know.
    Thanks a lot!

  10. I’m not sure where you’re getting your info, but good topic.

    I needs to spend some time learning much more or understanding more.
    Thanks for excellent info I was looking for this information for my mission.

  11. Hey! I just wanted to ask if you ever have any problems with hackers?
    My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no back up.
    Do you have any methods to protect against hackers?

  12. Great beat ! I would like to apprentice while you amend your site, how can i subscribe for a blog
    web site? The account aided me a acceptable deal.
    I had been a little bit acquainted of this your broadcast offered bright clear
    idea

LEAVE A REPLY

Please enter your comment!
Please enter your name here