Published

Useless Box

A machine that turns off the knob that you've just switched on- a ruthless battle between human and robot.

BeginnerFull instructions provided19,313
Useless Box

Things used in this project

Hardware components

Arduino Zero & Genuino Zero
Arduino Zero & Genuino Zero
×1
Breadboard (generic)
Breadboard (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
small SPDT switch
×1
servo motor
×1
cardboard
Good quality ones
×1
artist tape
×1
dental floss
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

laptop
wire stripper
voltmeter

Story

Read more

Schematics

Schematics

Using the breadboard to figure out the angle of the servo before soldering the wires is highly recommended. To adjust the programming to get the right angle of the servo hinge and the switch took a lot of trial and errors.

Code

Arduino IDE code

C/C++
Download the Arduino IDE for your computer and run it.

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 copied from Instructables to program the Arduino. He modified the "Sweep" code by Barragan.
He also randomized the speed when the finger retreats into the box to make it more interesting. I made slight adjustments to the range.
// 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
     }
  }
}

Credits

Thanks to rsucgang.

Comments