fbpx

Line-following robot – part 1

A line-following robot is a car-like robot that can drive on the floor or a table, and without human intervention it will detect and follow the path of a line drawn on the surface it is driving on. Its a fun and popular introductory robotics project that you can build from pretty low-level electronics like this guy, with an Arduino like this gal, or if you have the cash with the always-awesome Lego Mindstorms EV3 kit like this example here.

When we were designing our CanDo Creator Kit and the Project Day expansion kit (which you’ll have received if you attended on of our project day workshops), we hadn’t anticipated being able to build a line-following robot from their parts. However we were tinkering recently and were pleasantly surprised to realize that it is entirely possible to build a line-follower with a combination of our kits, so you may already have everything you need to tackle this fun and super-educational project!

I should point out though that while it is totally possible to build a line-follower from our kits and learn a ton in the process, we are missing one or two pieces that a dedicated kit would include. We have the ultra-powerful Cube and servo motors, but are missing some things like a little coasting wheel to balance the bot. So we’re kind of like a super-buff Spongebob who always misses leg day at the gym!

If you get stuck at any point in this project, drop a question in the forum and we’ll help you out. Comments and suggestions for improvement are also welcome! 👍

Here’s what our leg-skipping-bot will look like when its done!

What you’ll need

Our ‘bot is made using parts from both our standard CanDo Creator Kit as well as the expansion kit we use at our Project days, so you will need both kits to build the bot.

Below is a picture of the components you’ll need to assemble the physical part of our ‘bot. Starting from the top-left and moving clockwise, we have:

  • 1x CanDo Cube (obviously! 😎)
  • 2x wheels that come with the servo kits. Red or Green doesn’t matter – whatever looks good to you
  • 2x 360 degree servo motors from the Project Day kit. Its important to have the 360 servo motors from the red box, as these guys can spin around and around a full 360 degrees. If you recall from the Dino project of the Applied Tech course, the 180 degree servos from the green box can only be moved to, and stay at, an angle between 0 and 180 degrees. This makes the 180’s unusable for wheels – but maybe you can build a future robot car where the 180 servo steers the front wheel? 🤔
  • 2x grove connector adapters to adapt the 360 servo motor connector into a grove-connector compatible cable (as we saw in the Dino project)
  • 1x Light sensor
  • Some rubber bands, or twist-wires, or string, cable-ties. These don’t come in the kits – but will be useful to tidy up the cables when we assemble our ‘bot
  • 3x grove connector cables. Take these from the Light/Env/Soil/etc sensors in your kits
  • 8x black plastic connector pins (there are four in the 180 servo kit and another four in the 360 servo kit). You can get away with less than 8
  • 2x grey plastic rectangular frames (there is one in the 180 servo box of the CanDo Creator Kit, and another in the 360 servo box of the Project Day kit).
  • What we are missing from a ‘normal’ dedicated line-follower bot is some kind of wheel or ball for the back of the robot to roll around on, plus a light source to improve the light sensor performance. But fear not! Vee vill make it verk ja?

Assembling the ‘bot

Step 1

We’re going to build the chassis (or frame if you prefer) of our bot, to which the motors, Cube and other pieces will be connected.

Take the two grey rectangular frames and arrange them next to each other so that the short sides of the rectangles are close to one another.

Put two of the black connector pins in one of the frames, then press these pins into the holes of the other frame to join the two frames together in one longer frame. This frame is the chassis of our robot

Line up pins on the one frame with the holes of the other…

… and clip them together

Step 2

Connect one of the wheels to a servo motor, and mount the servo motor to the top right corner of the chassis as shown.

Note: Its important to mount the servo motors correctly, otherwise the ‘bot won’t move properly. Its not obvious at first glance, but the motor shaft (the little white gear that you connected the wheel to) does not come out the center of the motor – but is offset all the way to one side of the motor. You want the shaft offset to the left as shown by the green arrow in the picture. If you accidentally mount the motor so that the wheel is offset to the right as shown by the orange arrow, then you will find that the edge of the motor casing will drag on the ground when you flip the frame right-way up and try move it.

Step 3

Same same as Step 2, just different 😄. Mount the other motor opposite his buddy, so that the motors are aligned and symmetrical on the frame about the long axis.

Step 4

Nothing much to do here. Just flip your chassis over so that it is right-way up – with the wheels able to touch the ground, and the top of the chassis available to mount the Cube to (shortly).

Note: The robot will pretty much move around as it is now – with its behind (the left side of the frame in the picture) dragging on the ground – whereas a dedicated line follower would have something under the frame like a little rolling ball or castor wheel to keep the frame level while the ‘bot rolls. So now would be a good time to eyeball the edge of the motor housings to see if they are going to drag on the ground – and if so mount them the correct way around.

Step 5

Time to mount the Cube on the frame!

First, take two of the black plastic pins and insert them into the two middle holes of the right-most frame so that they stick up as shown in the image on the left below (you might need to look carefully to see them!). If you were missing a pin or two, you can make a plan here by only using one pin and/or using a rubber band to secure the Cube to the frame.

Second, look at the underside of your Cube. There are two set of three closely-spaced holes running top-to-bottom about the center of the Cube. Align the middle hole from each set with the two pins in the frame and clip your Cube into position is shown below. Take a moment to make sure your Cube is facing the right way now – the three little orange circles on the bottom edge of the face of the screen should be at the ;back’ of the bot – ie: the side furtherest away from the wheels.

Feel free to experiment with different placements of the cube. You might be able to find a clever way to fitting everything onto a single grey rectangular frame instead of the two joined together as we have it.

Step 6

Time to start wiring things up!

Lets start with the bottom motor in the picture. Thread the brown/yellow/red wired from the motor up through the frame, connect in its adapter (remember from the Dino project that the G pin of the adapter board lines up with the brown wire of the motor connector!), plug in a grove cable, and connect the grove cable to Port C on the Cube.

We’ve just connected the servo motor to the Cube’s Port C. When the robot is mobing forward this will be the Right-hand-side motor

Neaten up the cables as best as you can. I gently squish them together and wrap them in a rubber band as shown below.

Protip: You can try hide the cables if you like, but leaving them sticking out the front like shown gives a place to attach the light sensor. In future versions of the kit we might supply some kind of T-piece or Beam piece to make it easier to connect the light sensor, but for this version we are making a plan with what’s available in the kit! 👍

Step 7

Repeat the previous step for the other servo motor (thread the motor wired through the frame, connect all the wires and adapters, tidy up the cabling) and plug the motor into Port B. When the robot is moving forward this will be the left-hand-side motor.

Step 8

Almost done! Lets add the light sensor.

Using the last grove cable, plug the light sensor into Port A on the side of the Cube.

Step 9

Last step! Also a slightly tricky one I’m afraid 😉

In the picture below, the green arrow shows external light reflecting off the ground up into the Light sensor. So we want the light sensor to be facing down towards the ground while it looks for changes in this reflected light as it follows the line.

The kit doesn’t include a T piece or Beam that would have help secure the Light sensor to the frame, so instead I have rubber-banded it (you could twist-tie, or cable tie, or string tie) to the tidied-up motor cables.

The kit also doesn’t have a separate light source that a dedicated ‘bot would have to provide a constant source of light shining at the ground and bouncing back into the sensor.

So we don’t want our light sensor to be too close to the ground where its always in its own shadow and not properly reading changes in the ambient light, and we also don’t want it too far from the ground where the light changes from being over the dark line are not significant.

So! Do your best to attach the light sensor so that its facing the ground, roughly parallel to the ground’s surface – we’ll adjust this later when we get to the coding and experimentation phase!

You’ll see in this pic that I’ve put a spare black plastic pin to lift up the rear of the ‘bot a little and tilt the light sensor a bit closer to the ground.

Step 10

There’s no step 10 😎. We’re done with the physical side of building the bot (apart from inevitable tinkering!). In the next part of the project we’re going to turn our attention to programming the motors that make the bot move.

On to Part 2 – Making our ‘bot move!