As all know, we can make different projects using Arduino Uno. In this article, I'll show you how to make a line following Bluetooth car using Arduino Uno board. Before start, I like to remind you about our last article about Arduino. It also the same concept. Refer to our previous article. Let's go to the article.
Arduino Uno Line Following Car |
- This Bluetooth-controlled car follows a line using 3 IR sensors. Maybe you have a question about why we use 3 IRs. Actually, the middle IR sensor detects the line and the other two keep the car steady on the track
- We can do the make this using 2 IRs but for better performance and to get the smooth condition, we use 3 IR sensors.
- First, we consider the types of equipment that we need
Apparatus
1.Arduino Uno board
Arduino Uno board |
2. 3 IR sensor
IR sensor |
3.DC motor drive(L298N)
DC motor drive |
4.Jumper wires
Jumper wires |
5.Four phone battery
phone battery |
6.Dc motor with gear
Dc motor |
7.Bluetooth module(HC 6)
CONNECTION DIAGRAM
CONNECTION DIAGRAM |
Arduino code
*/
//m1
int enA = 10;
int in1 = 12;
int in2 = 8;
//m2
int enB = 5;
int in3 = 7;
int in4 = 6;
char val;
void setup() {
Serial.begin(9600);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
}
void mpower(int motor, int rotation, int spd) {
int pwm;
int pA;
int pB;
if (motor == 1) {
pwm = enA;
pA = in1;
pB = in2;
}
else if (motor == 2) {
pwm = enB;
pA = in3;
pB = in4;
}
else {
return;
}
if (rotation == 0) {
digitalWrite(pA, LOW);
digitalWrite(pB, LOW);
}
else if (rotation == 1) {
digitalWrite(pA, HIGH);
digitalWrite(pB, LOW);
}
else if (rotation == -1) {
digitalWrite(pA, LOW);
digitalWrite(pB, HIGH);
}
analogWrite(pwm, spd);
}
void loop() {
int lol;
if (digitalRead(3) == HIGH) {
if (digitalRead(2) == LOW) {
if (digitalRead(4) == LOW) {
//go straight
mpower(1, -1, 255);
mpower(2, 1, 255);
lol == '1';
}
else {
//turn right
mpower(1, 1, 255);
mpower(2, 1, 255);
lol == '2';
}
}
else {
if (digitalRead(4) == LOW) {
//turn left
mpower(1, -1, 255);
mpower(2, -1, 255);
lol == '3';
}
else {
//stop
mpower(1, 1, 0);
mpower(2, -1, 0);
lol == '4';
}
}
}
else {
if (digitalRead(2) == LOW) {
if (digitalRead(4) == LOW) {
//stop
if (lol == '1') {
mpower(1, -1, 255);
mpower(2, 1, 255);
}
else if (lol == '2') {
mpower(1, -1, 255);
mpower(2, -1, 255);
}
else if (lol == '3') {
mpower(1, 1, 255);
mpower(2, 1, 255);
}
else if (lol == '4') {
mpower(1, -1, 0);
mpower(2, 1, 0);
}
else if (lol == '6') {
mpower(1, -1, 255);
mpower(2, -1, 255);
}
else if (lol == '7') {
mpower(1, 1, 255);
mpower(2, 1, 255);
}
else if (lol == '8') {
mpower(1, -1, 0);
mpower(2, -1, 0);
}
//lol=='5';
}
else {
//turn right
mpower(1, 1, 255);
mpower(2, 1, 255);
lol == '6';
}
}
else {
if (digitalRead(4) == LOW) {
//turn left
mpower(1, -1, 255);
mpower(2, - 1, 255);
lol == '7';
}
else {
//stop
mpower(1, -1, 0);
mpower(2, -1, 0);
lol == '8';
}
}
}
}
You can watch the completed project by clicking here
Don't forget to subscribe to our youtube channel.
If you have any issue regarding this project, you can directly contact us or you can comment on our youtube channel.
0 Comments