Hello everyone. Today, in this post we will discuss about How to make a Bluetooth Controlled Arduino Robotic Car. The car will be controlled by a bluetooth module interfaced with Arduino Mega, and will receive signal from the bluetooth of a smartphone using bluetooth serial monitor app.
List of Components:
1. Arduino Mega
2. Robot Chassis
3. Wheels.
4. Castor Wheel.
5. Motor Driver.
6. Bluetooth Module HC-05
7. LiPo Battery
8. Connecting Wires.
9. SmartPhone.
Arduino Code:
#include <SoftwareSerial.h>
SoftwareSerial bt(10,11); // assigning 10 as RX and 11 as TX
#define motor_left 5 // PWM PINS FOR LEFT MOTOR
#define motor_right 3 // PWM PIN FOR RIGHT MOTOR
#define motor_right_dir 2 // DIRECTION PIN FOR RIGHT MOTOR
#define motor_left_dir 4 // DIRECTION PIN FOR LEFT MOTOR
void setup()
{
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
while(!Serial) // waiting for serial communication to setup.
{;}
bt.begin(9600); // beginning the bluetooth connection.
}
void loop()
{
bt.listen();
while(bt.available()) // loop continues until input is received.
{
char ch= bt.read(); // read the input one character at a time.
if(ch=='f')
{ // MOVES FORWARD IF INPUT RECEIVED IS 'F'
digitalWrite(motor_left_dir,HIGH);
digitalWrite(motor_right_dir,HIGH);
analogWrite(motor_left,150);
analogWrite(motor_right,150);
// delay(100);
}
else if(ch=='b')
{
digitalWrite(motor_left_dir,LOW);
digitalWrite(motor_right_dir,LOW);
analogWrite(motor_left,150);
analogWrite(motor_right,150);
}
else if(ch=='l')
{
digitalWrite(motor_left_dir,HIGH);
digitalWrite(motor_right_dir,HIGH);
analogWrite(motor_left,0);
analogWrite(motor_right,120);
}
else if(ch=='r')
{
digitalWrite(motor_left_dir,HIGH);
digitalWrite(motor_right_dir,HIGH);
analogWrite(motor_left,120);
analogWrite(motor_right,0);
}
else if(ch=='s')
{
digitalWrite(motor_left_dir,HIGH);
digitalWrite(motor_right_dir,HIGH);
analogWrite(motor_left,0);
analogWrite(motor_right,0);
}
}
}// thanks for viewing. PLEASE SUBSCRIBE CHANNEL.
Connections:
For connection, please watch the complete video.
Thanks for reading the post. Hope you will enjoy making the project yourself. Thanks and Happy Learning.
Comments
Post a Comment