Hi, I am having a problem using the Adafruit motor shield. I am working on an autonomous robot that turns 180 degrees when it is 14 inches from the wall. The sonar sensor that I am using is the Maxbotix Ez0. When I upload my code, nothing happens. Motors don't turn, but the sonar does register accurate inch values.
here is my code:
#include <AFMotor.h>
AF_DCMotor motor1 (1);
AF_DCMotor motor2(2);
int SonarVal;
void setup() {
Serial.begin(9600);
motor1.setSpeed(255);
motor1.run(RELEASE);
motor2.setSpeed(255);
motor2.run(RELEASE);
}
void gather() {
SonarVal = analogRead(0);
}
void loop() {
gather();
if(SonarVal = 14) {
motor1.run(FORWARD);
motor1.setSpeed(200);
motor2.run(RELEASE);
motor2.setSpeed(200);
}
else {
motor1.run(FORWARD);
motor1.setSpeed(200);
motor2.run(FORWARD);
motor2.setSpeed(200);
}
}
any help is appreciated!!
Thanks, ke0aer