Arduino - Voice - Control - Robot Code
Arduino - Voice - Control - Robot Code
Arduino - Voice - Control - Robot Code
*Version 1.0
*Before Uploading the sketch you must install the required libraries first.
*Also remove the bluetooth and servo connector before uploading the sketch.
*/
String command;
//Right motor
int rightMotorPin1=D5;
int rightMotorPin2=D6;
//Left motor
int leftMotorPin1=D7;
int leftMotorPin2=D8;
#define trigger_pin D1
#define Echo_pin D2
long duration;
int distance;
void setup() {
Serial.begin(9600);
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
void loop() {
delay(10);
while(Serial.available()) {
command = "";
command = Serial.readString();
Serial.print(command);
forward();
Serial.println("Forward Entering");
backward();
left();
right();
Stop();
command = "";
if((millis()-oldtime)>1000)
delayMicroseconds(2);
if(distance<30)
digitalWrite( rightMotorPin1,LOW);
digitalWrite(rightMotorPin2,LOW);
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2 , LOW);}
oldtime=millis();
void forward()
digitalWrite(rightMotorPin1,HIGH);
digitalWrite(rightMotorPin2,LOW);
digitalWrite(leftMotorPin1,HIGH);
digitalWrite(leftMotorPin2,LOW);
void backward()
digitalWrite(rightMotorPin1,LOW);
digitalWrite(rightMotorPin2,HIGH);
digitalWrite(leftMotorPin1,LOW);
digitalWrite(leftMotorPin2,HIGH);
void right()
digitalWrite(rightMotorPin1,HIGH);
digitalWrite(rightMotorPin2,LOW);
digitalWrite(leftMotorPin1,LOW);
digitalWrite(leftMotorPin2,HIGH);
void left()
{
digitalWrite(rightMotorPin1,LOW);
digitalWrite(rightMotorPin2,HIGH);
digitalWrite(leftMotorPin1,HIGH);
digitalWrite(leftMotorPin2,LOW);
void Stop()
digitalWrite(rightMotorPin1,LOW);
digitalWrite(rightMotorPin2,LOW);
digitalWrite(leftMotorPin1,LOW);
digitalWrite(leftMotorPin2,LOW);