Line Follower and BT Robot - Ino
Line Follower and BT Robot - Ino
h>
SoftwareSerial BT_Serial(2, 3); // RX, TX
int mode=0;
void loop(){
if(BT_Serial.available() > 0){ //if some date is sent, reads it and saves in state
bt_data = BT_Serial.read();
if(bt_data > 20){Speed = bt_data;}
}
analogWrite(enA, Speed); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1
Speed
analogWrite(enB, Speed); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2
Speed
if(mode==0){
//===============================================================================
// Key Control Command
//===============================================================================
if(bt_data == 1){forword(); } // if the bt_data is '1' the DC motor will go
forward
else if(bt_data == 2){backword();} // if the bt_data is '2' the motor will Reverse
else if(bt_data == 3){turnLeft();} // if the bt_data is '3' the motor will turn
left
else if(bt_data == 4){turnRight();} // if the bt_data is '4' the motor will turn
right
else if(bt_data == 5){Stop(); } // if the bt_data '5' the motor will Stop
//===============================================================================
// Voice Control Command
//===============================================================================
else if(bt_data == 6){turnLeft(); delay(400); bt_data = 5;}
else if(bt_data == 7){turnRight(); delay(400); bt_data = 5;}
}else{
//===============================================================================
// Line Follower Control
//===============================================================================
if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 0)){forword();} //if Right Sensor
and Left Sensor are at White color then it will call forword function
if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 0)){turnRight();}//if Right Sensor
is Black and Left Sensor is White then it will call turn Right function
if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 1)){turnLeft();} //if Right Sensor
is White and Left Sensor is Black then it will call turn Left function
if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 1)){Stop();} //if Right Sensor
and Left Sensor are at Black color then it will call Stop function
}
delay(10);
}