Arduino Voice Controlled Robot
Car
}
voice="";
}
}
void forward_car()
{
motor1.run(FORWARD);
motor1.setSpeed(700);
//viral science motor2.run(FORWARD);
//voice controlled car motor2.setSpeed(700);
delay(2000);
#include <AFMotor.h> motor1.run(RELEASE);
#include <Servo.h> motor2.run(RELEASE);
String voice; }
AF_DCMotor motor1 (1, MOTOR12_1KHZ); void back_car()
AF_DCMotor motor2 (2, MOTOR12_1KHZ); {
Servo myServo; motor1.run(BACKWARD);
motor1.setSpeed(700);
void setup() motor2.run(BACKWARD);
{ motor2.setSpeed(700);
Serial.begin(9600); delay(2000);
myServo.attach(10); motor1.run(RELEASE);
myServo.write(90); motor2.run(RELEASE);
}
}
void right_car()
void loop() {
{ myServo.write(0);
while (Serial.available()){ delay(1000);
delay(10); myServo.write(90);
char c = Serial.read(); delay(1000);
if (c == '#') {break;} motor1.run(FORWARD);
voice += c; motor1.setSpeed(190);
} motor2.run(BACKWARD);
if (voice.length() > 0){ motor2.setSpeed(190);
if(voice == "*go ahead"){ delay(1000);
forward_car(); motor1.run(RELEASE);
} motor2.run(RELEASE);
else if(voice == "*go back"){ }
back_car();
} void left_car()
else if(voice == "*right") { {
right_car(); myServo.write(180);
} delay(1000);
else if(voice == "*left") { myServo.write(90);
left_car(); delay(1000);
} motor1.run(BACKWARD);
else if(voice == "*stop") { motor1.setSpeed(190);
stop_car(); motor2.run(FORWARD);
motor2.setSpeed(190);
delay(1000);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void stop_car ()
{
motor1.run(RELEASE);
motor2.run(RELEASE);
}