Hello everyone out there it's me Ajith V Anil. so today, I am going to show you How to build a "Bluetooth Controlled Car (Robot)". without wasting any time lets get started.
so the basic component in this project is Arduino. Please follow the steps in the video.
code for the project is given below please copy-paste the code to your Arduino IDE or into arduinoDroid app in your phone.
Code
int m1a = 8;
int m1b = 9;
int m2a = 10;
int m2b = 11;
char val;
void setup()
{
pinMode(m1a, OUTPUT);
pinMode(m1b, OUTPUT);
pinMode(m2a, OUTPUT);
pinMode(m2b, OUTPUT);
Serial.begin(9600);
}
void loop()
{
while (Serial.available() > 0)
{
val = Serial.read();
Serial.println(val);
}
if( val == 'F') // Forward
{
digitalWrite(m1a, HIGH);
digitalWrite(m1b, LOW);
digitalWrite(m2a, HIGH);
digitalWrite(m2b, LOW);
}
else if(val == 'B') // Backward
{
digitalWrite(m1a, LOW);
digitalWrite(m1b, HIGH);
digitalWrite(m2a, LOW);
digitalWrite(m2b, HIGH);
}
else if(val == 'L') //Left
{
digitalWrite(m1a, LOW);
digitalWrite(m1b, LOW);
digitalWrite(m2a, HIGH);
digitalWrite(m2b, LOW);
}
else if(val == 'R') //Right
{
digitalWrite(m1a, HIGH);
digitalWrite(m1b, LOW);
digitalWrite(m2a, LOW);
digitalWrite(m2b, LOW);
}
else if(val == 'S') //Stop
{
digitalWrite(m1a, LOW);
digitalWrite(m1b, LOW);
digitalWrite(m2a, LOW);
digitalWrite(m2b, LOW);
}
else if(val == 'J') //Backward Right
{
digitalWrite(m1a, LOW);
digitalWrite(m1b, HIGH);
digitalWrite(m2a, LOW);
digitalWrite(m2b, LOW);
}
else if(val == 'H') //Backward Left
{
digitalWrite(m1a, LOW);
digitalWrite(m1b, LOW);
digitalWrite(m2a, LOW);
digitalWrite(m2b, HIGH);
}
}
Comments
Post a Comment