0% found this document useful (0 votes)
13 views13 pages

Line Robot1

This document provides a step-by-step guide to building a line-following robot using a Raspberry Pi and various components like line sensors and jumper leads. It includes instructions for preparing connectors, connecting sensors, testing functionality, and writing code to control the robot's movement. The project aims to teach users about physical computing by integrating coding with electronics to create a functional robot that can follow a track autonomously.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

Line Robot1

This document provides a step-by-step guide to building a line-following robot using a Raspberry Pi and various components like line sensors and jumper leads. It includes instructions for preparing connectors, connecting sensors, testing functionality, and writing code to control the robot's movement. The project aims to teach users about physical computing by integrating coding with electronics to create a functional robot that can follow a track autonomously.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
1128128, 1:29 PM Build a tine-fotowing robot Projects Build a line-following robot Make your robot buggy follow a track by itself Step1 What you will make Make sure you have a working buggy, like the one in the Build a buggy (hittps://projects.raspberrypi. ects/build-a-buggy) project. rglen/proj You will also need: + 8 socket-to-socket or socket-to-pin jumper leads ‘© 2iline following sensors ‘+ Soldering iron and solder ‘+ Insulating tape Additional information for educators Ifyou need to print this project, please use the printer-friendly version (hnttps://nrojects.raspberrypi.org/en/ projects/rpi-python-line-following/print) ‘Access all resources (httns://rpt.io/p/en/rpi-python-line-following-go) - including an example finished project. nipsifproje raspberrypiorgleriprojectstp-pythonine-followingiprint as. 1128128, 1:29 PM Build a tine-fotowing robot Step 2 Prepare the connectors Connect the line sensors to your buggy. Normally, the type of line sensor used in this project needs to be connected to a 3V3 pin, but you're going to run ‘two sensors via the same power pin, so you'll attach both of them to a 8V pin. ‘Take three of your sacket-to-socket jumper leads, remove a connector from each end, and then strip the plastic sheath to reveal about a centimeter of the multi-core wire beneath. Take the three jumper leads and twist their multi-core wires together. Then use a soldering iron to bond the leads. _ntips:fproects.raspberryplorgleriprojetsrp-python-ine-olowingiprint 23 1128128, 1:29 PM Build a tine-fotowing robot Cover the join of the leads with a small amount of insulating tape. Repeat the entire process with another three socket-to-socket jumper leads, _ntips:fproects.raspberryplorgleriprojetsrp-python-ine-olowingiprint 33 1128128, 1:29 PM Build a tine-fotowing robot Step 3 Connect the line sensors Each line sensor has three pins: VCC for power, GND for ground, and DO for digital out Take one of your soldered-together three-wire jumper leads, and connect two of its ends to the VCC pin on each of the two sensors. _ntips:fproects.raspberryplorgleriprojetsrp-python-ine-olowingiprint ans 1128128, 1:29 PM Build a tine-fotowing robot ‘Take the second of your soldered jumper leads, and connect two ends to the GND pin on each line sensor. ‘Take your remaining two single jumper leads and connect each one to the DO pin on each line sensor. _ntips:fprojects.raspberryplorgleriprojectsrp-python-ine-olowingiprint 513 1128128, 1:29 PM Build a tine-fotowing robot Now connect the VGC pins of both line sensors to @ SV pin on your Raspberry Pi and the GND pins of, the sensors to a GND pin on your Raspberry Pi. Each of the two DO pins can be connacted to any numbered GPIO pin. In this example, pins GPIO 17 and GPIO 27 are used. r _ntips:fprojects.raspberryplorgleriprojectsrp-python-ine-olowingiprint en3 1128128, 1:29 PM Build a tine-fotowing robot Step 4 Test the line sensors Next you're going to test whether your line sensors are working, and tune them. With the line sensor attached, boot up your Raspberry Pi Cut two small holes in the bottom of your buggy so that the sensor can view the line beneath it, and secure your sensors in place. Pass the sensors over a dark line. The LED on the sensor board should tum off. Use the small potentiometer on the board to tune your sensors, so that the LEDs turns off when over a dark line, and light up when over white space. _ntips:fprojects.raspberryplorgleriprojectsrp-python-ine-olowingiprint 713 1128128, 1:29 PM Build a tine-fotowing robot Step 5 Simple line follower Note: In this example, the motor controller board is connected so that the left motor is on pins GPIO 7 and GPIO 8. and the right motor is on pins GPIO 9 and GPIO 10. The lett line sensor is on pin GPIO 17, and the right line sensor is on pin GPIO 27. Open up Thonny from the Raspberry Pi Programming menu, and begin by setting up your motor controller board and your sensors using gpiozero: 1 | fron gptozero Inport Robot, LineSensor 2| from tine dnport sleep > | fron signal insert pause rotot = Robot(eFe-(7, 8), right=(9, 30 ‘right_sensor= Linesensoe(27) Underneath, write a simple line following program to test your robot. 1 | from gpiosero inport Rabot, LineSensor ‘ron tine Inport sleep ‘rom signal Lmpore pause robot = Robot eFt-(7, 8), right=(9, 22) Ieft_sensor = LineSensor(27 Fight_sensor= LineSensor (27 Left sensor nen_Line = robot. Left so | Fight sensor wen 1ine = robot eight 1» | right_sensor.shen_no_line ~ robot forward Don't worry if your robot tracks off its line. Just check it attempts to stay on the line. _ntips:fprojects.raspberryplorgleriprojetsrp-python-ine-olowingiprint ans 1128128, 1:29 PM Step6 Abetter line follower Don't forget to adjust the pin numbers if you've used different GPIO pins. Create a new fle ‘Add the following lines of code and run it. 1 | fron gptozero Inport Robot, LineSensor robot = Robot eFt-(7, 8), right=(9, 12) 5 | left sensor = Linesensor (37 leftadetect = int(Left_sensor value) so | rlgne_detect ~ sot(esghe_sensor value | print lee detect, nieneacstect Move the robot back and forth over the line to see what happens. Check you can see the output from the sensors. Within the while ‘True loop, create two new variables called 1eft_mot and right_mot. These variables should have the same value that you would lke the motors to receive. You can simply print out their values within the loop. 1 | fron gptozero Inport Robot, LineSensor ‘rom tine ingore sleep 4 | robot = Robot(teFe=(7, 8), riahee(9, 10 eft detect ~ int(left sensor value wo | rlehtadetect = int eight sensor. value | st aete_oetecs ete not Fight not © and rigne detect | SF aefe getect y eft not = 3 © and right detect 6 tote getect 2 right not = 1 and right detect _ntips:fprojects.raspberryplorgleriprojetsrp-python-ine-olowingiprint ‘ulld a line-fotowing robot ons 1128128, 1:29 PM Build a tine-fotowing robot Test: Run your code and see what is printed when you move the robot over the ine, _ntips:fprojects.raspberryplorgleriprojetsrp-python-ine-olowingiprint 10113 1128128, 1:29 PM Build a tine-fotowing robot Step7 The final follower Your code prints the values the motors can use. Change yourwhi le ‘True loop into a generator. 1 | fron gptozero Inport Robot, LineSensor from tine inport sleep robot = Rabot(eFt-(7, 8), right=(9, 22) 5 | left sensor = Linesensor 37 wale Toe: n ‘right_detect ~ int right_sensor. value 2B Af AeFe detect == @ ard right.detect = 8 Y and eight. detect == 2 4 eft not = 2 2 AF tof detect == 1 and right detect = 0 right.rot = 2 lela (right.vot, LeFt_not ‘A generator s like a function, but it runs continually and will only vied values when itis asked for them, Now all you need to dois to say that the source of the robot's motor values is going to be the result of the generator, ‘Add in this line of cade below the generator: To make sure that the robot doesn't keep running forever, and to close all the components’ connections cleanly, you can optionally add these lines to the end of your code: steep 60 rotot source = None left_sensor-cloze ight sensoo.close Now run your code and test your robot over a track. Sometimes the robot runs too fast. _ntips:fprojects.raspberryplorgleriprojetsrp-python-ine-olowingiprint 1013 1128128, 1:29 PM ‘ulld a line-fotowing robot ‘Add a speed multiplier to slow the robot down. rom gptozere inport Robot, Linesensor ron time inport ste Left sensor ~ Linesengor (27) Fight sensors LineSensor(27) speed = 0.65 12 | def notor speed) nf ne true B right_detect = int(right_sensor. value) % AF defe detect == @ and right.detect == 6 6 eft mot ” right not = 2 » St left detect == 0 ond right detect —- 2 2 eft mot = 1 a Af Aefe detect == 1 and right.detect == 6 2 right pot = 2 2B # printiry 1) » yieia (eight.not * speed, LeFt_not * specs) 2 | steepis0) 5 | robot close) a2 | Lert_sensor. closet) 2 | eagnt_sensor-close() -nips:ifprojects.raspberrypi orgleriprojectstp-python-ine-folowingiprint 123 1128128, 1:29 PM Build a tine-fotowing robot Step 8 What can you do now? ‘Try our Physical computing (httns://projects.raspberrypi.org/en/collections/physical_computing) project pathways where you will control and interact with the real world, combining code with electronics. Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons license (https://creativecommons.org/licenses/by-sa/4.0/). View project & license on GitHub (https://github.com/RaspberryPiLearning/rpi-python-line-following) -ntpsirojects.raspberryp org/enprojectalp-python-ine-ollowingprnt 1313

You might also like