Step 1

Gather The Parts


If you want to follow along with this project here’s a list of parts you will probably need to order:

  1. Ultrasonic Sensors (x 3) = $7.20
  2. Arduino Uno = $25.00
  3. High torque servos (x2) = $12.56
  4. AA Battery holder = $1.91
  5. 6x4x2 Project Box = $6.49
  6. Toggle Switch = $3.49
  7. Desk Lamp = $22.69

Here’s a list of other parts and tools that you you will probably find around the house (as I did):

  1. Dremel and/or Drill
  2. Soldering equipment
  3. Breadboard and wires

Step 2

Connecting The Components

Screen Shot 2014-08-31 at 9.55.37 PM

Download the Wiring Diagram

Alright, let’s start connecting the hardware first. We’re going to be using three ultrasonic sensors. They’ll be used to detect swipe left, swipe right, and forward and back movement. Depending on what type of utrasonic sensor you have, you may have a different ammount of pins. Mine has 5, but we’ll only be using four. You want to connect a ground port on the Arduino to the negative row on the breadboard and the 5v port to the positive row on the breadboard. Now you can now connect the ground pins of the sensors to the ground row, and the VCC pins to the positive row. On the left sensor connect the Trig pin to port 8, and the echo to port 9. For the center sensor, trig goes to 10 and echo goes to 11. And for the right sensor, trig goes to 12 and echo goes to 13. Using a separate breadboard, let’s connect the servos. Start by connecting both ground wires together and both power wires together. Then connect a power supply to the motors. But you have to make sure you also connect the ground to a ground on the Arduino. Eventually this power supply will power both of the motors as well as the Arduino. Now connect one servo to port 6 on the Arduino and the other one to port 7. Then connect the Arduino up to your computer and let’s start writing code!

Step 3

Writing The Code

Screen Shot 2014-09-01 at 3.38.51 PM


When you have everything connected up the next step is to plug the Arduino into your computer and start writing code for it. You can download the code from below, but before you can run it, you will need to download the NewPing Arduino library and unzip it to your Arduino Libraries folder.

Download The Arduino Code

Step 4

Assemble The Parts

31_all_parts copy


To hide all of the electronics and to make the lamp look a lot more functional and less nerdy, it’s best to put everything into a project enclosure box. The 6x4x2.5 project enclosure from Radio Shack is the perfect size for the lamp base and can easily hold all of our electronics. But it will require some modifications in order to make it functional.

  1. Using a Dremel (or other rotary tool), you will need to cut a square on the top of the box to house our rotational servo motor. Make sure it’s not too large, but that the motor fits snuggly inside of it.
  2. On one of the long sides of the box, you will need to drill 8 holes that are about 3/4 inches in diameter. These will be fore the ultrasonic sensors to peep out of. MAKE SURE YOUR MEASUREMENTS ARE ACCURATE. When in doubt, measure again.
  3. On the reverse side of the box from the ultrasonic sensor holes, you will need to drill one final hole for the power switch. Mine was about 1/2 inch in diameter.

In order to save on space, I swapped out the Arduino Uno for a Arduino Pro Mini compatible board. And using the smaller Arduinio, I was able to solder everything onto one circuit board. I soldered two 3 pronged connector pins so that the servo’s can plug right into the board, and I also soldered all power and ground sources to the battery pack (and added a switch). Please refer to the Fritzing sketch above to see how the circuitry connects. With the Project Box modded and the circuitry simplified, let’s attach the motors to the lamp. Here’s the steps I took to get everything attached

  1. Mount the rotational motor into the project box and fasten it into place.
  2. Screw the base of the lamp on the rotational motor head
  3. Notice in the first picture that I already have the vertical motor cable already threaded through the base. This is important because it will be a pain to run this through later.
  4. Attach the rest of the lamp to the base.
  5. Mount the vertical motor to the middle of the bottom arm.
  6. Using strong wire (I was able to use a coat hanger), attach the motor head to the upper arm so that it pulls it up and down.

Step 5

Final Steps


Now that the lamp and motors are mounted to the project box, you can now connect the servos to the circuit board and mount all of the circuitry into the box, making sure that the switch is properly attached and the Ultrasonic sensors are peeping through the front holes. You\’ll notice that the lamp is extremely wobbly from balancing on the rotating servo head, so I attached some thumbtacks to the base of the lamp to help prevent tilting.