loading

Here is my second version of an automated toy using a reed switch from my bicycle to control the servo which tilts the toy up and down. Also I use a smoothing routine in the Arduino code to keep the toy from bouncing.

It works quite well and goes quite fast (video does not show the top speed) but still fast.

Next version will use an adjustable reed switch so that I can adjust the toy angle.

Stay tuned!

Step 1: Arduino Code...

#include <Servo.h>

Servo servo1;

int servangle = 0; // servo angle variable

int potPin = 4; // select the input pin for the potentiometer

int ledPin = 13; // select the pin for the LED

int val = 0; // variable to store the value coming from the sensor

int valInc = 4; int currAngle = 0; int newAngle = 0; int delayTime = 0; //////////////////////////////////////

/Analog read pins const

int buttonPin = 2;

void myServo1(int curAngle,int newAngle,int angleInc,int incDelay) {

if (curAngle < newAngle) { for(int angle=curAngle;angle < newAngle;angle += angleInc) { servo1.write(angle); delay(incDelay); } }

else if (curAngle > newAngle) { for(int angle=curAngle;angle > newAngle;angle -= angleInc) { servo1.write(angle); delay(incDelay); } }

}

void setup()

{ Serial.begin(9600);

pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT

pinMode(buttonPin,INPUT);

servo1.attach(9);

delay(1000);

servo1.write(90); //go vertical

delay(5000); //wait 5 seconds

servo1.write(172); } //start rolling by lowering toy frame

void loop() {

if (digitalRead(buttonPin) == HIGH) {

val = analogRead(potPin) * 2; // read the value from the pot sensor (1 to 1024)

Serial.print(" poy val= ");Serial.println(val);

digitalWrite(ledPin,HIGH);

servo1.write(90); //put frame vertical

// myServo1(172,90,1,15);

delay(val);

//servo1.write(172);

myServo1(90,172,1,5); //put frame down slower so not to bounce it

digitalWrite(ledPin,LOW); }

}

Smart idea! Thanks for shearig :)
<p>I have to say I was curious but didn't think much of it from the pictures. </p><p>Then I saw the video and changed my mind! It's curiously hypnotic and has a great feel to it when it's moving! The magic is in the motion.</p>
<p>I like cyclical projects for some reason, maybe they are easier. I made an electronic pendulum that is often running on my table. Maybe it appeals to my obsessive/compulsive brain.</p>
<p>I've had a look at your other Instructables. I immediately thought anyone who rides a unicycle can't be all mad but then I saw your bike reins so I changed my mind. However, they seem to be filling a gap in my life so I'll definitely be making some. I'll let you know how I got on with them once I get out of my anticipated stay in casualty.</p>
<p>It's about time someone made one.</p>
<p>It's great to see the development of this from the earliest version (on LMR). That is running so much better now. </p>
<p>Oh, yeah, that is me on LMR.</p>
<p>Yes, thanks. LMR gives a lot of good technical ideas and motivation to make a project better. Thought about smoothing but probably wouldnt have done it except for some suggestions about it. And someones ragging about the spring switch I built got me to thinking that, yes, I do have a reed switch, on my bike.</p>
<p>This is really cool!! I'd love to see some pictures of your build process and what your code looks like!! I'm excited to see your future updates!</p>
<p>Thank you so much! Here is a link to more details about version 1. I will post the code though here in this instructable.</p><p>http://letsmakerobots.com/content/automated-gyro-wheel-toy-using-arduino-and-servo</p>

About This Instructable

562views

8favorites

License:

Bio: I am an American teaching English at Shangluo University, Shaanxi. I like making machines that do interesting but fairly useless things - I call them Quixotic ... More »
More by JimRD:Arduino Controlled Morse Code Key and Transmitter Magnetic Levitating Globe Tear-apart and Fix Morse Code Key (and Sounder) Made From Steak-knife and Multi-tester 
Add instructable to: