Automated Gyro Wheel Toy (version 2)

by JimRD in Circuits > Arduino

927 Views, 9 Favorites, 0 Comments

Automated Gyro Wheel Toy (version 2)

Gyro Wheel w Pot ,Smoothing and Reed Switch
Gyro Wheel Reed Switch.JPG

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!

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); }

}