Line-following Robot

by Froggyman in Circuits > Robots

328 Views, 3 Favorites, 0 Comments

Line-following Robot

45.png
IMG20231113215529~2.jpg
IMG20231113215543~2.jpg
IMG20231113215548~2.jpg
IMG20231113215538~2.jpg

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))


  • 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

IMG20231114173219~2.jpg

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

circuitronics.png
IMG_20231114_185826.jpg

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.

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

4.jpg
5.jpg
6.jpg
7.jpg
8.jpg
9.jpg
1.jpg
11.jpg
13.jpg
14.jpg
16.jpg
19.jpg
  1. Slot "framepart2" on to the end of your power bank as shown in the attached photo
  2. Slide "framepart1" on to the power bank. Make sure it's orientation aligns with that in the photo
  3. Take off the rubber seals on both of your geared motors, exposing the bare motor
  4. Slot the motors into "framepart2" as as shown, then reattach the gearboxes and rubber seals around the framepart
  5. (Casing) Assemble the wheel covers and "grate" together, using 4 of your 27 mm screws
  6. 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
  7. 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
  8. Slot your mini-breadboard between the two identical frameparts
  9. Use a 20 mm screw to screw "breadboard holder" into the framepart behind the breadboard, in the orientation indicated in the picture
  10. Use your 8 mm screws to screw in the sensor modules into the framepart in front of the breadboard
  11. (Casing) Use 2 of your 27 mm screws to screw "head" into "breadboard holder"
  12. Press-fit your wheels on to your geared motors
  13. 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...