Hai guys;
I have a project on balancing the robot using single axis gyro sensor.
The sensor works great but the servo motor cannot lock it position even
angle of the surface is change.Here is the code:
#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
void setup()
{
myservo.attach(9);
}
void loop()
{
int val = analogRead(potpin);
val = map(val, -512, 512, -270, 270); //map gyro value
myservo.write(val); //move servo using map value
delay(100);
}
Now you see that, i have map the gyro analog value from -512 to 512 to -270(servo -270 degree) to 270(servo 270 degree) rotation.This code works but the servo only rotates once i moves the plane surface only and it did not lock the position at a surface i move.seems it return to initial position.Any suggestions?
With many thanks;
Khai