Line Follower Robot With Pi Pico
by RoboCircuits in Circuits > Raspberry Pi
4640 Views, 6 Favorites, 0 Comments
Line Follower Robot With Pi Pico
A Line Follower follows a black line wherever it goes. It used proximity sensors or IR sensors. You may have seen a lot of line followers with Arduino today we are going to make it with the new Raspberry Pi Pico.
A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact. A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for instance), and looks for changes in the field or return signal.
Circuit
This is a circuit for LFR.
We design a line follower robot using the new microcontroller Raspberry Pi Pico Board.
There were 3 sections of the PCB
1. the First one was the IR sensor section
2. the Second one was the motor driver section
3. The last section was the pico section
The IR sensor section was designed by using lm358 operational amplifiers, pairs of IR emitter and IR receiver, a potentiometer, and some resistance.
IR sensors of this kind can be used to determine the difference between white and black.
the IR emitter throws light on the surface and the IR receiver receives it.
In the case of black color, the IR rays emitted by the emitter are absorbed. So output remains zero
In the case of white color, the IR rays are reflected and received by the receiver. So we get high output.
Coming to the motor driver section
The Motor Driver Section includes L293D motor driver ic and connectors for the motors and battery. L293D is based on H-Bridge. If you want to get more information about motor drivers. I have given a link in the description you can check out that.
The raspberry pi section includes raspberry pi and a 3.3v voltage regulator. Pi works on 3.3v so we used a voltage regulator AMS1117.
PCB Ordering
Let’s order
the PCB from JLCPCB.com. go to fabrication and get PCB fabrication files and click order at JLCPCB. JLCPCB order page will open.
Verify dimensions and select no of PCBs. Select surface finish and click add to cart. Now let's check out, fill in your details, and pay using PayPal.
$2 for 1-4 Layer PCBs, sign up to get $18 new user coupons: https://jlcpcb.com/IYB
Fun fact With over 10 years of experience in PCB manufacturing, JLCPCB has more than 200,000 customers, with over 8,000 online orders of PCB prototyping and small quantity PCB production per day.
after a week I got the PCBs. Matte Black color looks awesome.
Code
Let’s open
VS Code.
To program pico you will need PICO-go extension installed in your vs code. For more information watch my pico tutorial series click here
from machine import Pin
import time
in1 = Pin(2, Pin.IN)
in2 = Pin(3, Pin.IN)
m11 = Pin(4, Pin.OUT)
m12 = Pin(5, Pin.OUT)
m21 = Pin(6, Pin.OUT)
m22 = Pin(7, Pin.OUT)
while True:
sensor1 = in1.value()
sensor2 = in2.value()
if sensor1 == 1:
if sensor2 == 1:
m11.value(0)
m12.value(1)
m21.value(0)
m22.value(1)
elif sensor2 == 0:
m11.value(0)
m12.value(0)
m21.value(0)
m22.value(1)
elif sensor1 == 0:
if sensor2 == 1:
m11.value(0)
m12.value(1)
m21.value(0)
m22.value(0)
else:
m11.value(0)
m12.value(0)
m12.value(0)
m22.value(0)
Then using the if statement we will run our motors by setting pins high or low.
When the left sensor touches the black strip the robot moves it moves to the right and vice versa. And if both sensors are on white it keeps moving forward.
Testing
It worked
fine.
The LFR follows the black line. I programmed it to stop working when both sensors touch black. So on this side of the paper, it stops at every intersection.