Introduction: Arduino Line Follower With PID and 90 Degree Turns
This is my line follower with PID and arduino.
It does 90 degree turns.
I will show you how i build it.
Have fun!
Step 1: First of All the Result
Step 2: Materials
- 2 Pololu Micro Metal Gearmotor HP 6v
- 2 Pololu Micro Metal Gearmotor Bracket Pair - Black
- 2 Pololu Wheel 32×7mm Pair - White
- 1 SparkFun Motor Driver - Dual TB6612FNG (with Headers)
- 1 QTR-8RC Reflectance Sensor Array
- 1 Arduino Nano
- 2 cells 7.4V 1000Ah Li-Po Battery
- 1 Of this
Acrylic
Screws
- Nuts
- Foamy
Step 3: Connections Between Arduino Nano and Line Sensor
Between Arduino nano and line sensors (Pololu QRT8-RC)
Its similar like in the image, but i usea another pins.
Now,
Arduino---|---Sensor
D2----------|--------8
D3----------|--------7
D4----------|--------6
D5----------|--------5
D6----------|--------4
D7----------|--------3
D8----------|--------2
D9----------|--------1
5V----------|-------Vcc(+)
Gnd(-) ----|-------Gnd(-)
Step 4: Connections Between Arduino Nano and Motor Diver
The conection its similar like its shown in the image.
I varie the original circuit to fit with the arduino nano, so i use ports A's not D's.
Arduino------|-----Motor diver
D10 ----------|-----PWM A
A5------------|------IN2 A
A4 -----------|------IN1 A
A3------------|------STANDBY
A2------------|------IN1 B
A1------------|------IN2 B
D11-----------|-----PWM B
5V------------|------Vcc(+)
Gnd(-)-------|------Gnd(-)
VM its a special case, beacuse it goes to the positive (+) of the battery, like in the first image.
Step 5: Connections Between Motor Diver and Motors
Its very simple,
Just follow the connections of the image and thats it.
Step 6: Chasis
I made it from a square of acrylic with a motor tool, you may use CNC or other techniques.
The bot have foamy to protect the sensors from the external light.
Step 7: Code
Here you can download the complete code.
I use PID derived from the theory of control.
You may ajust the values of Kd, Kp, and maybe the base motor speed.
Those values were found experimentally, so you may try diferent values.
Attachments

Participated in the
Circuits Contest 2016
1 Person Made This Project!
- Debraj mukherjee made it!
13 Comments
2 years ago
Its PD control not PID control.
2 years ago
Nics job My Friend , What is the width of the black line you are using?
3 years ago
hello, tried to complile code and found below error,
"QTRSensorsRC' does not name a type"
Reply 3 years ago
You need add the library 'Qtr Sensors'
6 years ago
Nice, work! but how is the code, if we change Polulu QTR8 with DIY line tracker sensor module. I can't find the QTR8 at my country.
Reply 5 years ago
I want to ask that same question too. Cant find any IR array in my country
Reply 3 years ago
You can buy it from aliepress.com for cheap.I have bought this too. Link is gien below:-
https://www.aliexpress.com/item/32819884826.html?s...
3 years ago
will this robot follow the discontinuity of line???
4 years ago
It for arduino uno r3
6 years ago
What should be the position values on the black background and the white line. Thank you.
6 years ago
!!!!!!SOBERBIO!!!! yo lo ise esta genial graxx
6 years ago
Good Work!
6 years ago
Nice work