loading
I wanted to get into Arduino projects and introduce my sons to robotics using Arduino. So I thought about building a simple project that made use of an Arduino Uno and a servo. I saw a great post in Instructables about The Most Useless Machine Ever and was inspired to create an Arduino-powered version.

It was a most satisfying build experience with my sons and I learned a lot about programing the Arduino.

How does it work?

The Arduino "listens" to the state of the switch and actuates the servo when the switch is activated.

In the OFF state, the Arduino sends the servo to the reset position (box lid closed). When a user flips the switch to ON, the Arduino sends a signal to the servo and actuates a finger to push the switch to the OFF state.

Step 1: Parts List

Parts list.

You will need:

- wooden jewelry box (you can get these at your local craft store for less than $5)
- Arduino UNO
- Laptop (I use a Macbook Pro)
- 10k ohm resistor
- small SPDT switch
- servo motor
- wires
- 9v battery
- popsicle sticks
- wood glue
- some 0.5" x 0.5 " wooden rod
- old coax cable
- 2 pcs of small hinges (approximately the same size of the hinges that comes with the box)

Tools:

- Dremel tool
- saw
- screw driver
- pliers
- wire stripper
- soldering iron, lead solder
- voltmeter
- breadboard
- electrical tape

Schema:

Check out the schema for the component wiring. I used Fritzing app for Mac to lay out my components.

I recommend wiring up your circuit using a bread board first. Check your servo calibration and play around with the code to achieve the desired rotation or position of your servo arms. This may vary so you need to tweak the code to achieve the right motion.

Step 2: Programming the Arduino

Download the Arduino IDE for your computer and run it. I use a Mac.

Connect the Arduino UNO to the Mac using USB cable. For more info, check out: http://arduino.cc/en/Guide/MacOSX

Below is the code I used to program the Arduino. I modified the "Sweep" code by Barragan.
To make it more interesting, I randomize the speed when the finger retreats into the box.

========== CODE BELOW ========

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>

const int  buttonPin = 2;
int buttonState = 0;

Servo myservo;  // create servo object to control a servo
                             // a maximum of eight servo objects can be created
int pos;                // variable to store the servo position
long timeDelay;

void setup()
{
  pinMode(buttonPin, INPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  buttonState = digitalRead(buttonPin);  // Read the button position
  if (buttonState == HIGH) {
     for(pos = myservo.read(); pos >=20; pos -= 1) { // goes from 90 degrees to 20 degrees in 1 step                                   
       myservo.write(pos);                        // tell servo to go to position in variable 'ONpos'
       timeDelay = random(15, 30);
       delay(15);                                        // randomize wait time for the servo to reach the position
     }
  }
  else {
     timeDelay = random(1, 4);
     for(pos = myservo.read(); pos <=90; pos += timeDelay) {// goes from 20 degrees to 90 degrees in 1 step                            
       myservo.write(pos);                         // tell servo to go to position in variable 'OFFpos'                
       delay(15);                                         // randomize wait time for the servo to reach the position
     }
  }
}


Step 3: Prepare the Box

Prepare the box.

The design we want is for the lids to open from the top of the box. To do this we would need to cut the lid in half, then re-position the hinges to the left and right side of the box.

1. Remove the metal latch from the front of the lid and the box.
2. Remove the hinges form the back.
3. Draw a line across the lid to indicate where the cut will be made. Note that the  line on the side of the lid is angled so when the top opens, the lid does not jam with the other.
4. Cut the lid and smooth out the edges with a file.
5. Make notches to the sides of the box where the hinges will be re-located. Smooth it out with a file and attach the lids on each end.
6. Attach the hinges to the lid and the box. Note that you need an extra pair of hinges as the box only comes with two (you need 4 hinges total).

Step 4: Create Servo Housing and the Finger

Create the housing for the servo that will drive the "finger" that flips the switch off.

1. Measure the servo dimensions and build a housing around it using the 0.5" x 0.5" wood rod. Cut the wood and secure the pieces. I reinforced it with a nail then I glued it together.
2. Fit the servo in the housing and position it on the lid where the SPDT switch will be attached.
3. Drill a hole on the lid and secure the switch. Position the servo housing underneath and align it with the servo levers.
4. Create the "finger" using popsicle sticks. Before creating the finger, i mocked it out by drawing the finger on a piece of paper, cutting it out, then superimposing them on the servo lever. Simulate the rotation of the server lever with the finger attached to see how the finger reaches around to flip the switch off. Once you get the right size, angle, and thickness, overlay the paper mock with the popsicle stick. You can add as many layers of popsicle sticks as you can to create the right thickness so when the finger rotates, it is able to strike the switch. Create holes on the servo-end of the finger where you can attach the finger to the servo lever.
5. Attach the finger to the servo lever by using a copper wire taken from the middle of a coax cable. They can be pretty strong so you will need to use a pair of pliers to cut and bend it. Secure the copper wires by soldering the other side to "lock" the finger to the lever. Be careful not to melt the servo lever.
6. Secure the servo housing underneath the lid with the switch by applying wood glue. Rotate the finger to ensure that it goes around the lid and hits the switch lever nicely while the glue is still wet.. Once you've found the right position, use a clamp to secure the servo housing to the lid as the glue dries.

Step 5: Wiring and Attaching Power Supply

Wire the switches and servo to the Arduino. Refer to the wiring diagram on Step 1.

Note that I soldered the 10k ohm resistor  directly to the wires. No need to create a PCB for this simple circuit.

Move the Arduino to the side so when the finger rotates, it does not get in the way.

Attach the 9V power supply to the Arduino. Remember to detach the battery when not in use or else it will drain your battery.

Step 6: Testing the Most Useless Machine Ever

My son testing the finished project.



My daughter Kayla's reaction.


My wife sent me a video from a site called Gag donkey that had these. Your work is great. Thank you for posting the step by step. I am doing an Alice In Wonderland theme Halloween, this would be great to put on the front porch and see how many of the little ghosties and goblins push the switch.
Perfect toy for kids!
LOL! She's like &quot;I WANNA DO IT!&quot; Little kids are great.
<p>I did it!</p>
<p>Here is the code if you don't want it random and a short delay from when the switch is switched and the moving of the SERVO se you dont have to get your finger out of the way quickly:</p><p>#include &lt;Servo.h&gt;</p><p>const int buttonPin = 2;</p><p>int buttonState = 0;</p><p>Servo myservo; // create servo object to control a servo</p><p> // a maximum of eight servo objects can be created</p><p>int pos; // variable to store the servo position</p><p>long timeDelay;</p><p>void setup()</p><p>{</p><p> pinMode(buttonPin, INPUT);</p><p> myservo.attach(9); // attaches the servo on pin 9 to the servo object</p><p>}</p><p>void loop()</p><p>{</p><p> buttonState = digitalRead(buttonPin); // Read the button position</p><p> if (buttonState == HIGH) {</p><p> for(pos = myservo.read(); pos &gt;=0; pos -=1) { // goes from 90 degrees to 20 degrees in 1 step </p><p> myservo.write(pos); // tell servo to go to position in variable 'ONpos'</p><p> delay(4); </p><p> }</p><p> }</p><p> else {</p><p> delay(100);</p><p> for(pos = myservo.read(); pos &lt;=120; pos += 1) {// goes from 20 degrees to 90 degrees in 1 step </p><p> myservo.write(pos); // tell servo to go to position in variable 'OFFpos' </p><p> }</p><p> }</p><p>}</p>
<p>Hello,<br><br>I know very little about servos... will something like this work? <a href="http://www.ebay.ca/itm/Micro-Servo-Motor-RC-toy-Robot-Helicopter-Airplane-controls-SG90-Servo-9G-Motor-/301666348401?hash=item463cb72d71:g:mHMAAOSwT6pVg-cO" rel="nofollow">http://www.ebay.ca/itm/Micro-Servo-Motor-RC-toy-Ro...</a><br><br>Thanks!<br></p>
<p>hey,</p><p>i also modified your code so now it also has a door servo and you can add moves, just like opening the door then close it, then open it again, switch it off and go back in the box. ;)</p><p>// Sweep</p><p>// by BARRAGAN &lt;http://barraganstudio.com&gt;</p><p>// This example code is in the public domain.</p><p>#include &lt;Servo.h&gt;</p><p>const int buttonPin = 2;</p><p>int buttonState = 0;</p><p>Servo handservo; // create servo object to control a servo</p><p>Servo doorservo; // a maximum of eight servo objects can be created</p><p>int pos; // variable to store the servo position</p><p>long timeDelay;</p><p>void setup()</p><p>{</p><p> pinMode(buttonPin, INPUT);</p><p> handservo.attach(9); // attaches the servo on pin 9 to the servo object</p><p> doorservo.attach(6);</p><p>}</p><p>void loop()</p><p>{</p><p> buttonState = digitalRead(buttonPin); // Read the button position</p><p> if (buttonState == HIGH) {</p><p> if(doorservo.read()==11){</p><p> doorservo.write(50);</p><p> delay(500);</p><p> handservo.write(11);</p><p> }</p><p> if(doorservo.read()==50){</p><p> doorservo.write(11);</p><p> delay(500);</p><p> handservo.write(11);</p><p> }</p><p> if(doorservo.read()==11){</p><p> doorservo.write(60);</p><p> delay(500);</p><p> handservo.write(11);</p><p> }</p><p> if(doorservo.read()==60){</p><p> handservo.write(100);</p><p> delay(1);</p><p> doorservo.write(61);</p><p> delay(1);</p><p> }</p><p> }</p><p> if (buttonState == LOW) {</p><p> handservo.write(11);</p><p> doorservo.write(11);</p><p> }</p><p> }</p>
How did you wire up the servos? I'm new to Arduino and love the other tutorial on here where the door and finger act sparatic but I don't have the other components to hook up a debouncing circuit.
And then connect the doorservo to digital pin 6 and the hanservo to digital pin 9.<br>http://library.isr.ist.utl.pt/docs/roswiki/attachments/rosserial_arduino(2f)Tutorials(2f)Servo(20)Controller/arduino_servo.png<br>
Oh ok. The answer was staring me in the face lol. Thanks!
<p>Thank you so much for posting this! I have been looking for an Arduino controlled useless robot!! I definitely want to build this soon.</p>
<p>Thanks ;) </p><p>I built other machine , based on your tutorial.</p><p>https://youtu.be/-bSdqhItKJE</p>
Did you have to modify the servo at all for continuous rotation?

About This Instructable

115,742views

179favorites

License:

More by rsucgang:Big Hero 6 Hiro Hamada and Gogo Tomago Costume Refreshingly simple pear and kale smoothie Avocado Ice Cream 
Add instructable to: