Candypult--Computer Controlled Candy Catapult
by MikeTheMaker in Living > Toys & Games
4909 Views, 45 Favorites, 0 Comments
Candypult--Computer Controlled Candy Catapult
Parts:
Arduino
(2) Hitec HS-311 servo motors (Amazon.com)
(1) Hitec HS-645MG servo motor (high torque)--Amazon.com
(1) mini Servo YKS SG90 (Amazon.com)
(1) Two channel remote control toy--I got a car for $11.99 at a local pharmacy
(3) 5 volt relays--Jameco.com #139977 (these are polarized so that positive voltage on one coil lead causes it to pick up, but the other polarity doesn't; you can produce the same result with a 5 volt relay and a diode. Relays "B" and "C" only operate one at a time--based on the polarity provided.)
1/4" x 3 1/4" x .025 spring (available at Lowes)
(6) 12" servo extension cables
Spring from a ballpoint pen
4" lazy susan http://www.amazon.com/Capacity-Bearing-Turntable-Bearings-VXB/dp/B002TIKEQ6/ref=sr_1_2?ie=UTF8&qid=1372692771&sr=8-2&keywords=lazy+susan+4+inch
9 volt, 500 ma DC power supply
6 volt, 1 amp DC power supply
3D printed parts, design and print files at:
http://www.thingiverse.com/thing:110350
Wood, screws,paint, wire, jumpers
Take a 4" x 15" x 1/2 inch piece of plywood and paint it orange. Diagonally wrap painters tape to make the stripes.
Super glue the servo motor holder to the candy tower.
Note the use of servo extension cords and a wire guide to protect the wires that move through the rotation process.
Software:
#include <Servo.h>
Servo candy;
Servo rotate;
Servo latch;
Servo spring;
int fire=2;
int right=4;
int left=6;
int val=0;
int val1=0;
int val2=0;
int val3=0;
void setup()
{pinMode(fire,INPUT);
pinMode(right,INPUT);
pinMode(left,INPUT);
candy.attach(13);
rotate.attach(12);
latch.attach(8);
spring.attach(7);
rotate.write(45);
delay(500);
rotate.write(30);
latch.write(60);
spring.write(200);
candy.write(25);
candy.write(140);
delay(500);
candy.write(25);
}
void loop()
{
val=digitalRead(left);
val1=digitalRead(right);
val2=digitalRead(fire);
if(val==HIGH or val1==HIGH or val2==HIGH)
{
if (val==HIGH)
{val3=(val3+5);}
if (val3>=145)
{
val3=(val3-5);
}
if (val3<65)
{
val3=65;
}
rotate.write(val3);
delay(50);
}
else
val=digitalRead(left);
val1=digitalRead(right);
val2=digitalRead(fire);
if(val1==HIGH)
{val3=(val3-5);
if(val3<65)
{val3=(val3+5);
}
rotate.write(val3);
delay(50);
}
else
if(val2==HIGH)
{spring.write(50);
delay(1000);
latch.write(200);
delay(1000);
spring.write(200);
delay(500);
latch.write(60);
delay(1000);
rotate.write(50);
delay(500);
rotate.write(30);
candy.write(140);
delay(500);
candy.write(25);
val3=0;
}}
EXTRA CREDIT!
This is about 60% reliable, so more work needs to be done (probably in shielding the microphones).
The concept is this--when a loud sound arrives, it will probably be louder at the microphone pointed in the direction of the sound.
Microphones are Jameco #320179
In a room without a lot of people and clutter, I can achieve very high accuracy; but I think the machine trained me instead of the other way around.
Software:
#include <Servo.h>
Servo candy;
Servo rotate;
Servo latch;
Servo spring;
int led2=3;
int val2=0;
int ledcenter=6;
int ledPin=5;
int valm=0;
int val1=0;
void setup()
{pinMode(ledPin, OUTPUT);
pinMode(led2,OUTPUT);
pinMode(ledcenter,OUTPUT);
candy.attach(13);
rotate.attach(12);
latch.attach(8);
spring.attach(7);
rotate.write(45);
delay(500);
rotate.write(30);
latch.write(60);
spring.write(200);
candy.write(25);
candy.write(140);
delay(500);
candy.write(25);
}
void loop()
{
valm=analogRead(0);
val2=analogRead(3);
val1=analogRead(1);
if(valm>400 || val1>400 || val2>400)
//val1=val1-60;
{if(valm>val2 && valm>val1)
{digitalWrite(ledPin, HIGH);
rotate.write(130);
delay(500);
rotate.write(145);
spring.write(50);
delay(1000);
latch.write(200);
delay(1000);
spring.write(200);
delay(500);
latch.write(60);
delay(1000);
rotate.write(50);
delay(500);
rotate.write(30);
candy.write(140);
delay(500);
candy.write(25);
digitalWrite(ledPin, LOW);
delay(1000);
valm=0;
val2=0;
val1=0;
}
else
{
if(val2>valm && val2>val1)
{digitalWrite(led2,HIGH);
rotate.write(75);
spring.write(50);
delay(1000);
latch.write(200);
delay(1000);
spring.write(200);
delay(500);
latch.write(60);
delay(1000);
rotate.write(40);
delay(500);
rotate.write(30);
candy.write(140);
delay(500);
candy.write(25);
digitalWrite(led2,LOW);
delay(1000);
valm=0;
val2=0;
val1=0;
}
else
{if(val1>valm && val1>val2)
{digitalWrite(ledcenter,HIGH);
rotate.write(110);
spring.write(50);
delay(1000);
latch.write(200);
delay(1000);
spring.write(200);
delay(500);
latch.write(60);
delay(1000);
rotate.write(40);
delay(500);
rotate.write(30);
candy.write(140);
delay(500);
candy.write(25);
digitalWrite(ledcenter,LOW);
delay(1000);
valm=0;
val2=0;
val1=0;
}}}}}