Bolly and My Kids
This is my first robot project with arduino and I it is based on this instructable:Basic Arduino Robot, Light Seeker!
The my surprise of this project is the interaction between a simple robot and my seven years old kids and the great interesting in my nine years old daughter.
Circuit Diagram and Code
CODE:
const int RightMotor = 12;
const int LeftMotor = 11;
const int RightSensor = 1;
const int LeftSensor = 2;
int SensorLeft;
int SensorRight;
int SensorDifference;
void setup() {
pinMode(LeftMotor, OUTPUT);
pinMode(RightMotor, OUTPUT);
pinMode(LeftSensor, INPUT);
pinMode(RightSensor, INPUT);
digitalWrite(A1, HIGH);
digitalWrite(A2, HIGH);
Serial.begin(9600);
Serial.println(" \nBeginning Light Seeking Behavior");
}
void loop() {
SensorLeft = 1023 - analogRead(LeftSensor);
delay(1);
SensorRight = 1023 - analogRead(RightSensor);
delay(1);
SensorDifference = abs(SensorLeft - SensorRight);
if (SensorLeft > 500 && SensorRight > 500){
if (SensorLeft > SensorRight && SensorDifference > 75) {
digitalWrite(RightMotor, HIGH);
digitalWrite(LeftMotor, LOW);
}
if (SensorLeft < SensorRight && SensorDifference > 75) {
digitalWrite(RightMotor, LOW);
digitalWrite(LeftMotor, HIGH);
}
if (SensorDifference < 75) {
digitalWrite(RightMotor, HIGH);
digitalWrite(LeftMotor, HIGH);
}
}
if (SensorLeft < 500 && SensorRight < 500){
if (SensorLeft > SensorRight && SensorDifference > 75) {
digitalWrite(RightMotor, LOW);
digitalWrite(LeftMotor, LOW);
}
}
}