Smart Car
In this Arduino Tutorial I will show You How to make a Smart Car using Arduino Uno Board and other some Electronic Components. You can Watch this Video or Read the Following Blog for more details.
Working Principle :
This Smart Car has a Basic and necessary component UltraSonic and IR sensors. Both the Sensors are Used to Detect Obstacles to avoid from it. Then the Both Sensors mounted on the Car that Detects and Avoids Car from Collision.
Required Components :
- Arduino UNO Board
- L293D Motor Driver
- IR Sensors
- UltraSonic Sensor
- Gear Motors and Rubber Wheels
- Jumper Wires
- Li-ion Battery
Construction :
- First you need a cardboard of high Durability.
- And Mount a Gear motors Using Double Sided Tape or GlueGun.
- Place the Arduino Uno Board on the Cardboard Connected With L293D Motor Driver.
- Connect the Gear motor Wires to the L293D Motor Driver.
- And place the UltraSonic Sensor infront of the Cardboard.
- Attach IR Sensors on the sides of Car to detect Objects.
- Connect Sensors to the Motor Driver Using Jumper Wires.
- Make sure your Sensors Output Pins are Correctly Mounted with the Analog input Pins of Motor Driver.
- Now move on to the Software Portion, Open Your Arduino IDE
- Select smart_car.ino file
- Download Required Libraries and Select Board & Port , Click Upload .
- Now time to Connect a Battery. I use 2no's of li-ion 3.7V battery in Series Connection.
- After Connecting Batteries, Switch on your Car and Place it on Track, That will Avoids the Obstacles in its track and perfectly run on its track .
- That's Solve Guys !
Circuit Diagram :
You can follow our DIY Video for Circuit Diagram. I will clearly explained the connections of this Smart Car.
Arduino Code :
//CRATUS MK7
//SMART CAR
//BY PRADEEP RAJ(M.P.R)
//MAY 15 2020
// ------THIS CODE IS OPEN SOURCE FOR OUR SUBSCRIBERS------
// ------ THE FAUCETER ------
#include<AFMotor.h>
#include<NewPing.h>
#define left A1
#define right A0
#define trig A2
#define echo A3
#define MAX_DISTANCE 100
NewPing sonar(trig,echo,MAX_DISTANCE);
AF_DCMotor motor1(1,MOTOR12_1KHZ);
AF_DCMotor motor2(2,MOTOR12_1KHZ);
AF_DCMotor motor3(3,MOTOR34_1KHZ);
AF_DCMotor motor4(4,MOTOR34_1KHZ);
void setup() {
// put your setup code here, to run once:
pinMode(left,INPUT);
pinMode(right,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int distance = sonar.ping_cm();
Serial.print("Distaance");
Serial.println(distance);
if (distance >13) {
motor1.setSpeed(200);
motor1.run(FORWARD);
motor2.setSpeed(200);
motor2.run(FORWARD);
motor3.setSpeed(200);
motor3.run(FORWARD);
motor4.setSpeed(200);
motor4.run(FORWARD);
}
else if (distance <=14 && distance >0) {
Stop();
delay(100);
if (digitalRead(right)==0 && digitalRead(left)==0) {
turnright();
delay(400);
}
else if (!digitalRead(right)==0 && digitalRead(left)==0) {
turnleft();
delay(400);
}
else if (digitalRead(right)==0 && !digitalRead(left)==0) {
turnright();
delay(400);
}
else if (!digitalRead(right)==0 && !digitalRead(left)==0) {
turnaround();
delay(1600);
}
}
else if (!digitalRead(right)==0 && digitalRead(left)==0) {
turnleft();
delay(100);
}
else if (digitalRead(right)==0 && !digitalRead(left)==0) {
turnright();
delay(100);
}
}
void Stop() {
motor1.setSpeed(0);
motor1.run(RELEASE);
motor2.setSpeed(0);
motor2.run(RELEASE);
motor3.setSpeed(0);
motor3.run(RELEASE);
motor4.setSpeed(0);
motor4.run(RELEASE);
}
void turnright() {
motor1.run(FORWARD);
motor1.setSpeed(200);
motor2.run(BACKWARD);
motor2.setSpeed(200);
motor3.run(BACKWARD);
motor3.setSpeed(200);
motor4.run(FORWARD);
motor4.setSpeed(200);
}
void turnleft() {
motor1.run(BACKWARD);
motor1.setSpeed(200);
motor2.run(FORWARD);
motor2.setSpeed(200);
motor3.run(FORWARD);
motor3.setSpeed(200);
motor4.run(BACKWARD);
motor4.setSpeed(200);
}
void turnaround() {
motor1.run(FORWARD);
motor1.setSpeed(200);
motor2.run(BACKWARD);
motor2.setSpeed(200);
motor3.run(BACKWARD);
motor3.setSpeed(200);
motor4.run(FORWARD);
motor4.setSpeed(200);
}
//-----------------------------------------------------THE FAUCETER----------------------------------------------------------------------------------------
Comments
Post a Comment