Bluetooth controlled car using Arduino.
Hi there, In this Blog we are going to learn about "Bluetooth controlled car using Arduino".
AIM:- To make a car which can be manually controlled by Arduino with the help of a Motor Driver which acts as a bridge between Arduino and Bluetooth.
Components Required :-
AIM:- To make a car which can be manually controlled by Arduino with the help of a Motor Driver which acts as a bridge between Arduino and Bluetooth.
Components Required :-
- Arduino UNO :- This component is basically the heart of the entire system. To understang this component, do check out my last blog https://arduinoseries.blogspot.com/
- Motor Driver L293D module:-
- HC -05 Bluetooth Module:-
PROGRAMMING PART :-
#define ml1 6 //sets left motor's positive pin to 6
#define ml2 9 //sets left motor's negative pin to 7
#define mr1 10 //sets right motor's positive pin to 10
#define mr2 11 //sets right motor's negative pin to 11
void setup() {
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT); //declaring all the motor pins as OUTPUT pins.
pinMode(11,OUTPUT);
Serial.begin(9600); //sets baud rate(data per second as 9600, which is assumed to be 9600 per second)
}
void left() //Function used to rotate the car left by giving an analog speed 200 to right motor's positive terminal.Maximum speed however can be 255 because of an 8-bit register.
{
analogWrite(6,0);
analogWrite(9,0);
analogWrite(10,200);
analogWrite(11,0);
}
void right() //Function used to rotate the car right by giving an analog speed 200 to left motor's positive terminal.
{
analogWrite(6,200);
analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);
}
void forward() //Function used to move the car forward by giving an analog speed 220 to left and right motor's positive terminal.
{
analogWrite(6,220);
analogWrite(9,0);
analogWrite(10,220);
analogWrite(11,0);
}
void backward() //Function used to move the car backward by giving an analog speed 220 to left and right motor's negative terminal.
{
analogWrite(6,0);
analogWrite(9,220);
analogWrite(10,0);
analogWrite(11,220);
}
void stoop() //Function to stop the car by giving speed 0 to all of its motors terminals.
{
analogWrite(6,0);
analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);
}
void loop() {
while(Serial.available()>0) //checks whether data has been sent from phone or not
{
char val= Serial.read(); //Reads the data from phone
Serial.println(val);
if(val=='F'){ //Moves the car forward in case user enter F in Bluetooth interface.
Serial.println("Forward");
forward();
}
else if(val=='B') //Moves the car backward in case user enter B in Bluetooth interface.
{
Serial.println("Backward");
backward();
}
else if(val=='L') //Moves the car left in case user enter L in Bluetooth interface.
{
Serial.println("Left");
left();
}
else if(val=='R') //Moves the car right in case user enter R in Bluetooth interface.
{
Serial.println("Right");
right();
}
else if(val=='S') //Stops the car in case user enter S in Bluetooth interface.
{
Serial.println("Stoop");
stoop();
}
}
}
Comments
Post a Comment