banner



How To Use Camera To Follow Line Raspberry Pi

Equally we all know Raspberry Pi is a wonderful Developing platform based on ARM microprocessor. With its loftier computational ability and development options it tin piece of work out wonders in hands of electronics hobbyists or students. To learn more than well-nigh a Raspberry Pi and how information technology works, allow us try building a Line Follower Robot using Raspberry Pi.

If you lot are interested in robotics so yous should be very familiar with the name "Line Follower Robot". This robot is capable of following a line, just past using pair of sensor and motors. It might not sound efficient to use a powerful microprocessor similar Raspberry Pi to build a simple robot. But, this robot gives you room for infinite evolution and robots like Kiva (Amazon warehouse robot) are an example for this. You can also check our other Line Follower Robots:

  • Line Follower Robot using 8051 Microcontroller
  • Line Follower Robot using Arduino

Materials Required:

  1. Raspberry Pi 3 (whatsoever model should piece of work)
  2. IR Sensor (2Nos)
  3. DC Gear Motor (2Nos)
  4. L293D Motor Driver
  5. Chaises (You can likewise build your own using cardboards)
  6. Power depository financial institution (Any available power source)

Concepts of Line Follower

Line Follower Robot is able to runway a line with the help of an IR sensor. This sensor has a IR Transmitter and IR receiver. The IR transmitter (IR LED) transmits the lite and the Receiver (Photodiode) waits for the transmitted calorie-free to return dorsum. An IR light will return back simply if it is reflect by a surface. Whereas, all surfaces exercise not reflect an IR calorie-free, but white the colour surface can completely reverberate them and blackness colour surface will completely notice them as shown in the figure below. Acquire more about IR sensor module here.

Concept of White Line Follower Robot

Concept of Black Line Follower Robot

IR Sensor Module

Now we will utilise 2 IR sensors to check if the robot is in track with the line and two motors to right the robot if its moves out of the runway. These motors crave high current and should be bi-directional; hence we use a motor driver module similar L293D. Nosotros will likewise demand a computational device like Raspberry Pi to instruct the motors based on the values from the IR sensor. A simplified block diagram of the aforementioned is shown below.

Raspberry pi line follower robot block-diagram

These 2 IR sensors will be placed one on either side of the line. If none of the sensors are detecting a black line them they PI instructs the motors to movement forrad as shown below

Working of Raspberry Pi Line Follower Robot

If left sensor comes on black line then the PI instructs the robot to turn left by rotating the right cycle alone.

Turning left to line follower robot using Raspberry Pi

If right sensor comes on black line so the PI instructs the robot to turn right by rotating the left wheel solitary.

Turning right to line follower robot

If both sensors comes on black line, robot stops.

Stopping Arduino Line Following Robot

This way the Robot will be able to follow the line without getting outside the track. Now allow united states see how the excursion and Code looks like.

Raspberry Pi Line Follower Robot Circuit Diagram and Explanation:

The consummate excursion diagram for this Raspberry Pi Line Follower Robot is shown below

Raspberry pi line follower robot circuit diagram

As you tin can encounter the circuit involves two IR sensor and a pair of motors continued to the Raspberry pi. The complete excursion is powered past a Mobile Power bank (represented past AAA battery in the circuit above).

Since the pins details are not mentioned on the Raspberry Pi, we demand to verify the pins using the below moving-picture show

Raspberry Pi 3 GPIO pins Layout

Equally shown in the picture the height left corner pin of the PI is the +5V pivot, we employ this +5V pin to power the IR sensors every bit shown in the circuit diagram (red wired). Then we connect the ground pins to the ground of the IR sensor and Motor Driver module using black wire. The yellow wire is used to connect the output pin of the sensor one and ii to the GPIO pins and 3 respectively.

To drive the Motors, we need four pins (A,B,A,B). This iv pins are continued from GPIO14,iv,17 and 18 respectively. The orange and white wire together forms the connection for i motor. So we accept two such pairs for two motors.

The motors are connected to the L293D Motor Commuter module as shown in the moving-picture show and the driver module is powered by a power depository financial institution. Make sure that the footing of the power bank is connected to the ground of the Raspberry Pi, simply then your connection will piece of work.

Programming your Raspberry PI:

Once yous are done with your assembly and connections your robot should look something like this.

Raspberry pi line follower robot setupRaspberry pi line follower robot setup

At present, it is time to programme our bot and go it running. The complete code for this bot can exist found at the lesser of this tutorial. Acquire more than about Program and run lawmaking in Raspberry Pi here. The of import lines are explained below

We are going to import GPIO file from library, below function enables us to programme GPIO pins of PI. We are too renaming "GPIO" to "IO", so in the program whenever nosotros want to refer to GPIO pins we will utilise the word 'IO'.

import RPi.GPIO as IO

Sometimes, when the GPIO pins, which we are trying to utilise, might be doing another functions. In that case, nosotros will receive warnings while executing the program. Below command tells the PI to ignore the warnings and proceed with the program.

IO.setwarnings(Fake)

Nosotros tin refer the GPIO pins of PI, either by pin number on board or by their function number. Like 'PIN 29' on the board is 'GPIO5'. And so we tell here either we are going to represent the pivot here by '29' or '5'.

IO.setmode (IO.BCM)

Nosotros are setting 6 pins as input/output pins. The first two pins are the input pins to read the IR sensor. The adjacent four are the output pins out of which kickoff two is used to control the right motor and the side by side two for the left motor.

IO.setup(2,IO.IN) #GPIO 2 -> Left IR out IO.setup(3,IO.IN) #GPIO 3 -> Right IR out  IO.setup(4,IO.OUT) #GPIO four -> Motor 1 final A IO.setup(14,IO.OUT) #GPIO 14 -> Motor 1 terminal B  IO.setup(17,IO.OUT) #GPIO 17 -> Motor Left terminal A IO.setup(18,IO.OUT) #GPIO 18 -> Motor Left terminal B

The IR sensor outputs "True" if it is over a white surface. So equally long as both the sensor says True nosotros tin move forwards.

          if(IO.input(2)==True and IO.input(3)==True): #both white motility forward             IO.output(4,True) #1A+         IO.output(fourteen,False) #1B-          IO.output(17,True) #2A+         IO.output(18,False) #2B-

Nosotros have to brand a correct plough if the first IR sensor comes over a black line. This is done by reading he IR sensor and if condition is satisfied nosotros cease the right motor and rotate left motor alone as shown in the code below

elif(IO.input(2)==Imitation and IO.input(3)==True): #turn right          IO.output(four,True) #1A+         IO.output(xiv,Truthful) #1B-          IO.output(17,True) #2A+         IO.output(xviii,False) #2B-

We take to make a left plough if the 2nd IR sensor comes over a blackness line. This is done by reading he IR sensor and if condition is satisfied we stop the left motor and rotate right motor alone equally shown in the lawmaking beneath

elif(IO.input(two)==Truthful and IO.input(3)==Simulated): #plough left         IO.output(4,Truthful) #1A+         IO.output(14,Fake) #1B-          IO.output(17,Truthful) #2A+         IO.output(18,True) #2B-

If both the sensor comes over a black line, it ways that the robot has to stop. This can be done by making both the terminals of the motor to be true as shown on the code below

          else:  #stay still         IO.output(four,Truthful) #1A+         IO.output(14,True) #1B-          IO.output(17,True) #2A+         IO.output(18,Truthful) #2B-

Raspberry Pi Line Follower in Action:

Upload the python code for line follower to your Raspberry Pi and run it. Nosotros need a portable power supply, a power banking company in this case becomes handy hence I have used the same. The 1 that I am using comes with ii USB ports then I accept used to power the PI and other to Ability Motor Driver as shown in the movie below.

Raspberry pi line follower robot with power bank

At present all that yous have to do is ready up your own blackness color rails and release your bot over it. I have used a black color Insulation record to create the track you can apply any black color material, but make sure your ground colour is not nighttime.

Raspberry pi line follower robot in action

The complete working of the bot can exist found at the video given below. Hope you understood the projection and enjoyed building one. If you have whatever questions post them on the annotate department below.

Code

import RPi.GPIO as IO
import time
IO.setwarnings(Imitation)
IO.setmode(IO.BCM)

IO.setup(2,IO.IN) #GPIO ii -> Left IR out
IO.setup(three,IO.IN) #GPIO 3 -> Correct IR out

IO.setup(iv,IO.OUT) #GPIO 4 -> Motor ane last A
IO.setup(14,IO.OUT) #GPIO 14 -> Motor 1 terminal B

IO.setup(17,IO.OUT) #GPIO 17 -> Motor Left terminal A
IO.setup(eighteen,IO.OUT) #GPIO 18 -> Motor Left terminal B

while 1:

    if(IO.input(2)==True and IO.input(3)==Truthful): #both while move frontwards
IO.output(4,True) #1A+
IO.output(14,False) #1B-

        IO.output(17,True) #2A+
IO.output(18,False) #2B-

    elif(IO.input(ii)==False and IO.input(3)==True): #plough right
IO.output(4,Truthful) #1A+
IO.output(14,True) #1B-

        IO.output(17,True) #2A+
IO.output(eighteen,False) #2B-

    elif(IO.input(2)==True and IO.input(three)==Fake): #turn left
IO.output(4,True) #1A+
IO.output(14,False) #1B-

        IO.output(17,True) #2A+
IO.output(xviii,True) #2B-

    else:  #stay still
IO.output(iv,True) #1A+
IO.output(14,True) #1B-

        IO.output(17,True) #2A+
IO.output(xviii,Truthful) #2B-

Source: https://circuitdigest.com/microcontroller-projects/raspberry-pi-line-follower-robot

Posted by: bottscoctur.blogspot.com

0 Response to "How To Use Camera To Follow Line Raspberry Pi"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel