SMART ROBOT CAR
This smart robo is based on arduino , and canwork in 3 modes .... all these modes are
selected by a common android app
1st mode : Inbuilt App Joystick
working via the app inbuilt joystick command were we can use joystick to control robo like a
RC car.
2nd mode : Voice controlled robo
Here you can give input to the robo with voice commands.
3rd mode : Autonomous mode
Here the robo will use its ultrasonic sensor to find free way and avoid collision with objects or
wall.
4th mode : Line follower (optional).
Here we are giving you the option of line following if you need you can active.
5th mode ; IR remote control (optional).
This option is also available here.if you need you may active.
____________________________________________________________________
Download link for app =>
------------------------------------------------------------------------------------------------------
Spare parts (needed) =>
1- Arduino board (any).---------1pc
2- DC motor driver -L298n ___1pc
3- IR sensor -----------------------2pcs
4- IR Receiver --------------------1pc
5- Bluetooth Module (HC05/HC06)----------1pc
7- Servo Motor SG90 -------------1pc
8- DC gear motor with chassis--- 2pc or 4pcs
9- Jumper wire.
10- Data cable-----------------------1pc
11- PC with Arduino IDE.
-------------------------------------------------------------------------------------------------------
Circuit diagram =>
For circuit you just have to attach all components Vcc to 5 volts and GND to ground
now follow the instruction with me :-
IR Sensors =>
............................................................................................................................................
IR Receiver =>
............................................................................................................................................
Ultrasonic sensor =>
...........................................................................................................................................
Servo =>
.............................................................................................................................................
Motor driver =>
..............................................................................................................................................
Programming =>
Download the program from above and paste It to your arduino IDE,
note that in my build i have not used IR sensor or IR receiver so part
the program is commented so if you are using both this sensors you
can uncomment and use it .
Before uploading the program be sure that rx and tx of arduino and
bluetooth module are dissconected ....After uploading is done connect
back rx of module to tx of arduino and vicw versa.
#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(2, 3); // RX, TX
const int RECV_PIN = A5;
#define enA 10//Enable1 L298 Pin enA
#define in1 9 //Motor1 L298 Pin in1
#define in2 8 //Motor1 L298 Pin in1
#define in3 7 //Motor2 L298 Pin in1
#define in4 6 //Motor2 L298 Pin in1
#define enB 5 //Enable2 L298 Pin enB
#define servo A4
#define echo A2 //Echo pin
#define trigger A3 //Trigger pin
int distance_L, distance_F = 30, distance_R;
long distance;
int set = 20;
int bt_ir_data; // variable to receive data from the serial port and IRremote
int Speed = 130;
int mode=0;
int IR_data;
void setup(){ // put your setup code here, to run once
pinMode(echo, INPUT );// declare ultrasonic sensor Echo pin as input
pinMode(trigger, OUTPUT); // declare ultrasonic sensor Trigger pin as Output
pinMode(enA, OUTPUT); // declare as output for L298 Pin enA
pinMode(in1, OUTPUT); // declare as output for L298 Pin in1
pinMode(in2, OUTPUT); // declare as output for L298 Pin in2
pinMode(in3, OUTPUT); // declare as output for L298 Pin in3
pinMode(in4, OUTPUT); // declare as output for L298 Pin in4
pinMode(enB, OUTPUT); // declare as output for L298 Pin enB
Serial.begin(9600); // start serial communication at 9600bps
BT_Serial.begin(9600);
pinMode(servo, OUTPUT);
for (int angle = 70; angle <= 140; angle += 5) {
servoPulse(servo, angle); }
for (int angle = 140; angle >= 0; angle -= 5) {
servoPulse(servo, angle); }
for (int angle = 0; angle <= 70; angle += 5) {
servoPulse(servo, angle); }
delay(500);
}
void loop(){
if(BT_Serial.available() > 0){ //if some date is sent, reads it and saves in state
bt_ir_data = BT_Serial.read();
Serial.println(bt_ir_data);
if(bt_ir_data > 20){Speed = bt_ir_data;}
}
if(bt_ir_data == 8){mode=0; Stop();} //Manual Android Application and
else if(bt_ir_data ==10){mode=2; Speed=200;} //Auto Obstacle Avoiding Command
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_ir_data == 1){forword(); } // if the bt_data is '1' the DC motor will go forward
else if(bt_ir_data == 2){backword();} // if the bt_data is '2' the motor will Reverse
else if(bt_ir_data == 3){turnLeft();} // if the bt_data is '3' the motor will turn left
else if(bt_ir_data == 4){turnRight();} // if the bt_data is '4' the motor will turn right
else if(bt_ir_data == 5){Stop(); } // if the bt_data '5' the motor will Stop
//===============================================================================
// Voice Control Command
//===============================================================================
else if(bt_ir_data == 6){turnLeft(); delay(400); bt_ir_data = 5;}
else if(bt_ir_data == 7){turnRight(); delay(400); bt_ir_data = 5;}
}
if(mode==2){
//===============================================================================
// Obstacle Avoiding Control
//===============================================================================
distance_F = Ultrasonic_read();
Serial.print("S=");Serial.println(distance_F);
if (distance_F > set){forword();}
else{Check_side();}
}
delay(10);
}
void servoPulse (int pin, int angle){
int pwm = (angle*11) + 500; // Convert angle to microseconds
digitalWrite(pin, HIGH);
delayMicroseconds(pwm);
digitalWrite(pin, LOW);
delay(50); // Refresh cycle of servo
}
//**********************Ultrasonic_read****************************
long Ultrasonic_read(){
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
distance = pulseIn (echo, HIGH);
return distance / 49 / 4;
}
void compareDistance(){
if (distance_L > distance_R){
turnLeft();
delay(350);
}
else if (distance_R > distance_L){
turnRight();
delay(350);
}
else{
backword();
delay(300);
turnRight();
delay(600);
}
}
void Check_side(){
Stop();
delay(100);
for (int angle = 70; angle <= 140; angle += 5) {
servoPulse(servo, angle); }
delay(300);
distance_L = Ultrasonic_read();
delay(100);
for (int angle = 140; angle >= 0; angle -= 5) {
servoPulse(servo, angle); }
delay(500);
distance_R = Ultrasonic_read();
delay(100);
for (int angle = 0; angle <= 70; angle += 5) {
servoPulse(servo, angle); }
delay(300);
compareDistance();
}
void forword(){ //forword
digitalWrite(in1, HIGH); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, HIGH); //Left Motor forword Pin
}
void backword(){ //backword
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, HIGH); //Right Motor backword Pin
digitalWrite(in3, HIGH); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
void turnRight(){ //turnRight
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, HIGH); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, HIGH); //Left Motor forword Pin
}
void turnLeft(){ //turnLeft
digitalWrite(in1, HIGH); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, HIGH); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
void Stop(){ //stop
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
...........................................................................................................................................
...........................................................................................................................................
For its working do check out our Youtube video for the same =>
https://drive.google.com/file/d/1Xsm317gT9Gc8tkCykGt1swJwFmqzqcy1/view?usp=sharing
For serial library-
https://github.com/PaulStoffregen/SoftwareSerial.git
............................................................................................................................................
WE WOULD LOVE YOUR INVOLVEMENT IN PROJECT MAKING SO IF YOU HAVE MADE THE SAME PROJECT DO SHARE US ON geniustec18@gmail.com .
............................................................................................................................................
Comments
Post a Comment