Line-following Robot
This is a simple 2-sensor line-following robot. It follows a line made of black electrical tape. This uses an Arduino Nano, which is powered by a power bank. demonstration
Skill Level: beginner
Minimum cost (shipping not included): ≈ £39.14
Time (not including 3d-printing): ≈ 1 hour
Supplies
- 18 M3 nuts
- 8 M3 screws (27 mm long)
- 1 M3 screws (20mm long)
- 2 M3 screws (8 mm long)
- screwdriver that matches your M3 screws
((Prices don't include shipping))
- power bank (£1.99)
- Arduino Nano (£20.87) or Unofficial Arduino Nano (£5.99) ((for the unofficial one, you have to solder-on the header pins yourself, but it's well worth the money saved!))
- H-bridge motor driver (£5.32)
- IR sensors (£5.49) ((we will use 2 sensors))
- Geared motors (£8.49) (we will use 2 motors)
- 9.5 mm diameter ball bearings (£5.99) ((We will only use about 7 ball bearings but it is difficult to buy such a small quantity. You may decide to omit these. If so, you would have to use blu-tack or something in order to adjust the robot's balance))
- mini breadboard (£5.94) ((we will use 1 breadboard))
- mini USB (£2.27) ((for uploading the code on to the Nano))
- Black electrical tape (£3.65) ((for the line))
- soldering iron + solder
- 3D printer
- PLA and TPU filament (the TPU is semi-optional)
- a dozen male to female jumper wires
- old USB cable (that you don't mind mutilating)
- Wire stripper
Soldering
Cut 4 wires to about 80 mm in length each. Strip the wires around 10 mm on both sides, using a wire stripper. Solder these wires to both contacts on each of your motors.
Circuitry
You must strip your USB cable and identify the positive (red) and negative (black) wires. Wire the circuit as shown. You can open the stack terminal blocks using a screwdriver. You may find it difficult to push the wires into the stack terminal blocks. If so, you can melt some solder on to the wire in order to make it stiffer. It's better to wire the circuit with a range of coloured wires so they're easier to tell apart from one another.
Uploading the Code
Upload this code to your Arduino Nano. If you are using an unofficial board, there's a chance that you'll have to use the old bootloader. In the Arduino IDE, you will find this under "tools" and then "programmer".
This code makes it so that if no line is detected by the sensors (and so the line is between them), the robot will keep moving forward. If a line is detected, the motors will turn in such a way that the robot turns in the direction of the line. If both sensors detect a line, the robot is programmed to stop.
Downloads
3d Printing
Print the attached files, 20% infill should be sufficient; don't forget to add supports! You should print all of them in PLA with the exception of the wheels, which should be printed in TPU. If you have no TPU then you can still print them in PLA, but the wheels won't work as well on some stiffer and smoother surfaces, like some floors.
If prompted to, you should choose "import models".
"grate", "wheel cover" and "head" are all parts of the casing and so are optional, should you decide to make your own or forego casing altogether.
Preparations
- Press fit the each of your M3 nuts into each of the 18 hexagonal divots on the 3d prints. You can use needle nose pliers to press them in. If needed, you may choose to use a soldering iron to heat the nut whilst it is in position, and then press it down.
- Press one of your ball bearings into the print named "castor". If you have some difficulty doing this, you can use something like a sturdy rod to press the print on to the ball bearing- through this method, you are able to more easily exert some of your body weight on to the print.
- You should also press-fit some of the ball bearings in to the space between the thin protrusion and circular indent in the print named "head" - this is to better balance the robot
Assembly
- Slot "framepart2" on to the end of your power bank as shown in the attached photo
- Slide "framepart1" on to the power bank. Make sure it's orientation aligns with that in the photo
- Take off the rubber seals on both of your geared motors, exposing the bare motor
- Slot the motors into "framepart2" as as shown, then reattach the gearboxes and rubber seals around the framepart
- (Casing) Assemble the wheel covers and "grate" together, using 4 of your 27 mm screws
- Align the holes on the motor driver board with the holes on the frameparts, and then screw in the parts from the last step into these same holes
- Slide on "castor" (the steel ball should face away from the motor driver) and your other "framepart1", as shown in the picture, then screw both your framepart1's and "castor" together, using 2 of your 27 mm screws
- Slot your mini-breadboard between the two identical frameparts
- Use a 20 mm screw to screw "breadboard holder" into the framepart behind the breadboard, in the orientation indicated in the picture
- Use your 8 mm screws to screw in the sensor modules into the framepart in front of the breadboard
- (Casing) Use 2 of your 27 mm screws to screw "head" into "breadboard holder"
- Press-fit your wheels on to your geared motors
- Then, simply plug your USB into your power bank
Troubleshooting
Wheels turning in the wrong direction:
- Swap the affected motor's wires connected to the terminal blocks- now when both sensors are covered, both wheels should go clockwise:
The robot should follow the line:
- If the ground is a similar colour or lustre to the line, the robot may not be able to differentiate between them
- Make sure the sensors' LEDs are perpendicular to the floor and unobstructed
Robot bobbing up and down:
- You may have installed the castor wheel backwards, the steel ball should face away from the motor driver
Experiment...
Now that you've made your line-follower, you might want to try using Tinkercad in order to make new casing or add a third IR sensor. Maybe you could write your own arduino-code? Make something...