My robot is so close to working, its almost ok but it does not travel in a straight line. It kinda does, but only but going left and right really fast, it goes kind of forewards. Its almost like its walking on wheels, shifting weight from one to the other. So, in researching photovores and code for such, its says that the sensors must read ABOUT THE SAME light for it to go straight. My code says, if it reads EXACTLY THE SAME light then it will go straight. But light is never exactly the same, which is why it curves back and forth. How can I make it almost the same instead of exactly the same?
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo leftservo; // create servo object to control a servo
Servo rightservo;
int potpin0 = 0; // analog pin used to connect the potentiometer
int left; // variable to read the value from the analog pin
int potpin1 = 1;
int right;
void setup()
{
leftservo.attach(7);
rightservo.attach(8);
rightservo.write(90);
leftservo.write(90);
delay(1000);
}
void loop()
{
left = analogRead(potpin0);
right = analogRead(potpin1);
if(left < right)
{ leftservo.write(75);
rightservo.write(90);}
else if (left > right)
{ leftservo.write(90);
rightservo.write(105);}
else
{leftservo.write(75);
rightservo.write(105);}
}