Analog Line Follower

Analog Line Follower

I discovered BEAM robots a few months ago and was inspired to try building an analog robot myself. BEAM is a style of robot building that doesn't use micro-controllers, the behavior is hard-wired into the electrical circuits.  I considered a number of different projects including an inverted pendulum balancing bot, line follower, beacon finder and even an analog mini sumo.  While a fully analog mini sumo would be most impressive, I decided to go with an analog line follower as it would be a good challenge yet simple enough that I could actually make it work.

Control Loop

Line follower robots can be very simple.  The most basic type of line follower has "bang-bang" control.  Line following robots with bang-bang control tend to be jerky and slow and I wanted a fast and smooth robot, something that would surprise people when I told them it had no brain.  Line Followers that are fast and smooth generally use PID control, so an analog PID controller would be the heart of my design.

Analog Line Follower Control Loop

The control loop starts with the sensors.  Each sensor outputs an analog voltage depending on how much of the line it sees.  The analog voltages from all the sensors are combined into a single analog voltage which is the error.  When the line is in the middle there is zero error, and if the line is in the right or left sides of the robot then the error should be positive or negative.

Once we have an analog voltage that represents the error, that can be fed into the PID controller.  The job of the PID control is to convert the error signal into a desired action or response.  In this case, we need to transform the error signal into a desired turn rate so that the robot can turn towards the line until it is in the center and the error is zero.

The robot has wheels on the left and right sides.  In order to turn left, the right wheel must speed up and the left wheel must slow down.  The Turn Rate is added or subtracted from the Forward Speed in order to produce the left and right wheel speeds, respectively.

The analog signals in the control loop are low voltage and low current signals that must be boosted in order to drive the motors.  When the motor driver changes the voltage and current going to the motors, the robot changes its course.  The position of the line underneath the sensors also changes and the whole process starts over again.

Mechanical Design

I had a lot of leftover parts from all my mini sumo robot building and this project was a great opportunity to put the extras to good use.  Digging through my parts boxes I found a couple extra Fingertech mini sumo tires, Pololu 50:1 micro metal gear motors with mounting brackets and a spare 2 cell 350mAh LiPo battery pack.

Analog Line Follower Motor and Battery

My plan for the analog line follower was to have two wheels and no casters.  Most of the weight would be right over the wheels and the nose of the robot would simply slide along on the ground.  The PCB would serve as the chassis to keep it very light, but there was one mechanical part that needed to be designed from scratch.

The line follower course at the Atlanta Hobby Robot Club (AHRC) is not perfectly smooth.  There may be slight bumps as the robot transitions from one piece of foam core board to another while following the line.  Using SketchUp, I designed a scoop that wraps around the front of the robot.  The leading edge is angled at 45 degrees to help it slide over any bumps in the course.  The scoop mounts to the PCB using a few screws.

Line Follower Front Scoop

The line sensors are infrared, so ambient lighting from the room can interfere with the sensors ability to see the line.  The scoop has cylindrical cutouts for each line sensor so that ambient light is blocked.  The scoop and PCB are both black to further block as much ambient light as possible.  I had the scoop printed at Shapeways out of their Strong and Flexible nylon plastic.  The dimensions of the printed part are very good but the finish is a bit rough.  I sanded the bottom with 220 grit sandpaper which helped smooth it out.

3D Printed Line Follower Front Scoop

I tried out a new PCB supplier named Elecrow.  Their circuit boards are very cheap and they don't charge extra for routing complex shapes.  Routing the PCB helps to shave off any excess weight and looks much nicer than having a square bot.


The control loop above requires a lot of math functions to be performed using analog voltages.  The design needs electronic circuits that can add, subtract, amplify, integrate and derivate signals at various points in the circuit.  Fortunately there is an electronic circuit that can accomplish all of these tasks, it is the operational amplifier, or Op-Amp for short.

Analog Line Follower Schematic
Full schematic.  Click to enlarge.

I started by drawing up a circuit in EagleCAD that was full of Op-Amps and all the other parts that I thought it would take to build the control loop.  Next I used a circuit simulator, LT Spice, to simulate the circuit.  Unfortunately there is no way to export a schematic from LT Spice to Eagle or vice versa, so I had to draw it twice and maintain the changes in both programs.  By running a transient simulation and checking the graphs, I found a number of issues and the first version would not have worked at all.  Some of the initial problems were:

1. High frequency oscillation due to instability of the Op-Amps
2. High noise levels coupled onto the power rails and virtual ground
3. The sign of the Derivative was backwards
4. Unmatched output and input impedances of Op-Amp circuit caused significant non-linearity
5. The resistor and capacitor values on the I and D sections of the PID were way off from what they needed to be

Analog Line Follower SPICE simulation 0.5 Hz
Controls simulation with error oscillating at 0.5Hz.  Click to enlarge.

Analog Line Follower SPICE simulation 8Hz
Controls simulation with error oscillating at 8Hz.  Click to enlarge.

Over many iterations I tried different ways to improve the circuit.  Op-Amp stability was improved by adding small feedback capacitors in the few dozen pico-farad range for each Op-Amp.  Offsets on the virtual ground were decreased by eliminating bulk capacitance.  The derivative section was fixed by routing its output to the opposite input of the PID summing amplifier.  The impedance issues were fixed by ensuring any resistors in series with Op-Amp inputs were at least an order of magnitude higher in value than the output impedance of the prior stage.  I played around with many different resistor and capacitor values on the integral and derivative circuits.  I wanted the robot to be able to oscillate left-right at up to 8Hz without saturating the derivative output.  In addition, I wanted the robot to be off-center for up to 4 seconds before the integral output saturated.  The biggest learning here was that the potentiometers should be moved out of the Op-Amp's feedback path and placed at the Op-Amp's output as a resistor divider. Otherwise the potentiometer would not only changing the amplitude of the output but also the frequency response which is undesirable.

Analog Line Follower PID Circuit

Once the PID portion of the control was worked out and the left and right wheel speeds looked good, the last step was to design the motor driver.  For the sake of efficiency, I wanted to drive the motors with a PWM signal instead of an analog voltage.  An analog voltage can be converted into a PWM signal by using a comparator to compare the analog voltage to a triangle wave.

Analog Line Follower Motor Driver

Analog Line Follower Motor Driver PWM Graph

Whenever the wheel speed analog voltage is greater than the triangle wave the PWM output is high and whenever the wheel speed analog voltage is lesser than the triangle wave the PWM output is low.  The PWM signals output from the comparators are used to drive MOSFETs that turn the motors on and off.  Some line following robots have the ability to turn their motors backwards but that is not typically necessary unless a robot completely loses sight of the line and needs to back up to find it again.  Since this analog robot would have no memory and no way of dealing with losing sight of the line, there was no need to give it the ability to turn the motors in reverse.

PCB Layout

Every time I start to layout a PCB in Eagle I always think "Wow, how am I ever going to get all of those parts into such a small space?"  The ratsnest always seems daunting at first but once all the components are grouped together its amazing how small the circuit boards can be.

Analog Line Follower Ratsnest

Analog Line Follower PCB Layout

Almost all of the components used are surface mount with the exception of the potentiometers, battery connector and an electrolytic capacitor.  All of the surface mount components are on the underside of the board while the through hole parts are on the top side because they are too tall to fit on the underside without hitting the ground.

Analog Line Follower PCB

To keep the PCB cost low, I wanted it to fit within 10x10cm since that's what all the low cost PCB houses have standardized on.  To minimize weight and rotational inertia, all of the components were kept as close as possible to the centerline of the wheels.  Any extra PCB material was to be removed leaving just enough space in the front to hold the line sensors in the right places.  I ordered the PCBs from Elecrow and they looked great when they arrived.  I ordered on a day they were having a sale and purchased 10 copies of the board for less than $18 including shipping.

Analog Line Follower PCBA


After stuffing all the components onto the PCB, I tried setting it down on a line to see if it would work.  The robot spun in circles and hardly reacted to the line at all.  At first I thought I had screwed up something in the design but after a bit more investigation I found that each sensor would put out significantly different amounts of current even though they see the same thing.  I was able to tune the output voltage of each sensor by using different strength pull-down resistors.  After swapping out a few resistors the robot was able to stay on the line.  The response of the Error signal versus the location of the line is still far from ideal, but at least the output voltage crosses the 0V threshold in the middle of the sensor.  In the future I may buy more resistor values to fine tune the response better.

Analog Line Follower Sensor Response

The robot has 5 potentiometers that can be used to tune the behavior.  One sets the forward speed (Speed), one attenuates the output of the PID control (Turn), and the other three set the P, I and D values.  I started out by setting the Speed, I and D potentiometers to zero, the P potentiometer to maximum, and the Turn potentiometer to around 50%.  I adjusted the amount of Turn until the robot would follow a straight line without oscillating.  From there, I began turning up the Speed and making small adjustments to the Turn until the line follower could navigate sweeping turns quickly without losing the line.

The Speed and Turn Rate had to be turned way down for the robot to work on an advanced line follower course.  Finding just the right balance of Speed and Turn took patience but it was possible to come up with a combination that could consistently navigate the course.  Surprisingly, reducing the Speed down beyond a certain point caused the line follower to fail at the course's intersection, turning right or left instead of going straight.  It seems a bit of forward momentum is needed to get the robot through the intersection without turning the wrong way.

2016 Robot Rally Competition

I plan to compete the analog line follower in the Atlanta Hobby Robot Club's annual Robot Rally.  I'll be sure to update this page with the results!

Update: The analog line follower competed at the 2017 AHRC Robot Rally under the name "If I Only Had a Brain".  It completed both the simple and advanced courses and the results can be found at:

Making an analog robot was a fun and challenging project.  I learned how to use SketchUp to design 3D parts which I'm sure will come in handy for future designs.  Prior electronics projects were hardly complex enough to need to simulate a circuit, but this project was definitely harder than any I had done in the past.  I learned a lot about non-ideal Op-Amps and the analog line follower simply would not have worked if I hadn't taken the time to learn how to simulate the circuits and refine them.

If you like this project or have any suggestions, send me a note, I'd be glad to hear from you.
William Moore,
Sep 26, 2016, 6:58 PM
William Moore,
Sep 29, 2018, 1:57 PM
William Moore,
Sep 23, 2016, 5:53 PM