Line follower, obstacle avoider, photovore and photophobe in $40

Line follower, obstacle avoider, photovore and photophobe in 40$





This tutorial details the construction of a simple and low cost robot. The robot is mainly a line follower but can also be used as a photovore, a photophobe, and obstacle avoider!And all this for less than 40$. The best part is that the robot does not use any microcontroller, which means you need no expensive programmer or even a computer to program your robot. This tutorial is mainly aimed at beginners, hence I have tried to keep the robot as simple and cheap as possible. With only a few parts you can get this robot up and going. Here is a video of the robot following black line.


Specifications and Features

• The sensor used are four LDRs and LEDs.
• The steering method used here is differential drive.
• The actuators used are two 100 rpm DC motors.
• One 9V battery provides power to the robot.
• The robot can follow a dark line on a light surface or a light line on a dark surface.
• A LED is switched on when the robot is on the line (this makes things easier during debugging).
• It can also be used as a photovore, photophobe, and obstacle avoider.

The $40 Line Follower - Step 1: Parts List

Parts List

Below is the list of parts needed to build the robot.




Vendor, Part no.

BC548 transistor



CdS Photoresistors




5mm Blue Led



PC Board(Experimenters Board)



100uf 25V Electrolytic Capacitor




270 ohm resistor




5mm Green LED




16 pin DIP socket






Free Sample


Male Header Pins



20K Preset




5mm Red LED




1K resistor




1 Inch Standoff




100 rpm DC motor





Wheels (7.5 cm diameter)




L-Bracket (to mount motor) 












I bought the motor, wheels and L-Bracket from a local store. I’m not sure if you can buy the same parts online. But similar parts are available at
Other optional parts

9cm x 8cm HDPE Plastic




Velcro strip




Old mini  CD’s (instead of expensive wheels)




0.22uf Ceramic Capacitor





NOTE - Please go through the complete tutorial before buying the parts.


Apart from these parts you will also need the following tools and materials, if you don’t have them you may consider buying or borrowing them-
• Soldering Iron
• Desoldering Pump(optional)
• Crimper
• Drilling machine
• A 9v battery and battery clip
• Wires
• Cardboard or wood(instead of the HDPE Plastic)

The $40 Line Follower - Step 2: Mechanics


In this section of the tutorial I will explain the construction of the robots chassis(base, motors etc).

Designing the Chassis

For designing the robot chassis I used Google SketchUp, which is a free 3D modelling software. I didn’t include much detail in the model like the electronic components, wires etc.







The robot uses differential drive as its steering mechanism. When the sensors sense the black line the corresponding motor is stopped until the sensors are back on the white surface. Thus, the robot is able to stay on the line.

Constructing the Chassis

Before building the chassis, you will have to add 0.22uF decoupling capacitors across the motor terminals. This not only increases the life of the motors but also reduces noise in the circuit. This is an optional step.

Now lets move on to building the actual chassis. To make the base of the robot you will need a 9cm x 8 cm HDPE Plastic.

8cm x 9cm HDPE base

Paste the following template onto your 9cm x 8 cm HDPE plastics sheet and cut drill holes through the grey dots.
Make sure that you print the template to size (8cm x 9cm). To print the template to size, save the template in your PC. Once saved, right click on the template and select ‘Edit’. The template should open in Paint, where you have to click on the Print option under the File menu to print the template to scale. This is only for Windows users.

The template

Once the holes are drilled, attach the L-Brackets to the base with the help of screws. The L-Brackets will be used to mount the motors to the base. You may also use other materials like clamps and rubber bands instead of L-Brackets if you can’t find the right L-Bracket for your motor.

Next you will have to mount the DC motor to the L-Bracket. The DC motors I used are rated as 100 rpm, 12V and 250mA.

As I told before, I bought the wheels from a local store. The wheels I used had a diameter of 7.5 cm. To attach the wheel to the shaft of the motor, I forced the shaft of the motor into the extended shaft of the wheel and tightened the setscrew. 

You can also use ‘mini’ CDs’ as wheels and reduce the cost of your robot by 3-5$. The mini CD’s have a diameter of 8cm - perfect for our robot.

Screw the 2cm spacers to the base through the holes, previously drilled. These spacers will be used to attach the sensor module to the chassis.

Screw the four 2 cm spacers to the other side of the base. These spacers will be used to mount the main circuit board.

Stick a strip of Velcro to the base as shown in the image

The Velcro will be used to attach the 9V battery so attach another Velcro strip to the battery.


This completes the chassis construction; the next part is the electronics.

The $40 Line Follower - Step 3A: Electronics (Circuit Explanation)

The Electronics

The Circuit explanation

In this part of the tutorial I will explain the circuit and the different parts used by the robot.
As told before, the robot uses a combination of LDRs and LEDs to sense the presence to a line. An LDR is a resistor whose resistance is proportional to the light falling on it- greater the light, lesser the resistance and visa-versa. The basic principle underlying this project is that objects light in colour radiate the light falling on them while dark coloured objects don’t. So when the sensors are above the black line the light emitted by the LED is not radiated by the floor, hence the resistance of the LDR increases. The opposite happens when the robot back on the white surface.

In our robot the LDR is used part of a voltage divider circuit. To know more about voltage dividers and LDRs visit The circuit diagram of the voltage divider used in this project is given below

The resistor whose value is 20K is a potentiometer. A potentiometer (pot or preset) is a resistor whose resistance can be changed. In our project, we will be using 20k presets, that is, we will use presets whose resistance can be changed from 0K to 20K.
When the robot is on white surface the light emitted by the LEDs fall on the LDRs and decreases its resistance. This in turn reduces the voltage at Vout. When the robot is on the black line, the light emitted by the LEDs does not reach the LDRs, hence its resistance increases. This in turn increases the voltage at Vout.
During both the cases it is necessary to adjust the 20K preset in such a way that, when the robot is on white surface, voltage at Vout is <0.8V (so that the voltage at the emitter of the transistor is LOW) and when the sensor is on the black line the voltage is >0.8V (so that the voltage at the emitter of the transistor is HIGH).
For controlling the two DC motors, I have used the L293D motor driver. The reason I used this is that it has high noise immunity (that is, it considers voltages upto 1.7V as LOW), perfect for a robot which deals with analog signals.
The pins 4, 5, 12 and 13 are connected to ground. Pin 8 is the motor power supply pin and is connected to Vcc (9V) along with Pins 1, 16 (the two enable pins) and Pin 9. The left and right motors are connected to Pins 3, 6 and Pins 14, 11 respectively. Pin 2 (Input A), Pin 7 (Input B) and Pin 15 (Input A), Pin 10(Input B) are the input pins for controlling the left and right motor respectively. The truth table for controlling the motors is given below

Note in all the above cases the voltage at the enable pins is high

The complete circuit of the robot is given below.

In both the sides of the robot two sensors are used to sense the presence the line. The output of both the sensors of each side are connected together and connected to an LED. So that, the LED glows even when one of the sensors detects the line. The output of the left sensor is connected to Input A (Pin 2) of the left motor and the right sensor to Input A (Pin 15) of the right motor. The other two inputs are connected to Vcc.
When the robot is on white surface only one (Pin 7 and 10) input pin in each channel is high. The Pins 2 and 15 are low as the sensors are on white surface. Hence this makes the robot move forward. When the left sensor is on the line, Pin 2 is high. But Pin 7 is also high. Hence the left motor is switched off as both the inputs are HIGH(refer to the truth table above). But the right motor is still turning forward. This brings the robot back on the white surface.
Similarly when the right sensors are on the line, the right motor is switched off until the robot is back on the white surface.
This circuit works fine for black line following and using the robot as a photovore and obstacle avoider, for following white line and for using the robot as a photophobe, there is a slight change in the circuit. The left sensor output is connected to Pin 7 and right sensor output to Pin 10. Pins 2 and 15 remain unconnected. The rest of the circuit remains unchanged.
When the robot is on black surface (when following white lines), the input pins 2 and 15 are high. This makes the motors turn forward. When the left sensors are on the line the output goes low and stops the motor until the sensors are back on the black surface. Similarly, when the right sensors are on the line, the right motor is stopped.

The $40 Line Follower - Step 3B: Electronics (Building the Circuit)

The Electronics

  The circuit will be mounted on two different boards- The main circuit board and the sensor board.

First, cut the PC board such that the main circuit board and the sensor board have a dimension of 8cm x 8cm and 8cm x 1cm respectively. 

The Main Circuit Board

Drill four holes at the corners of the 8cm x 8cm PC Board (main circuit board). These holes will be used to attach the circuit board to the base of the robot with the help of the 2cm spacers.


The 8x8 PC Board


Solder a 100uF capacitor as shown in the figure. It is always a good practice to use capacitors whose voltage ratings is twice the voltage in the circuit. Since we will be using 9V in the circuit, I used a capacitor rated as 25V. You may also use a 16V capacitor, anything less than that is not recommended.


Solder the red and black wire of the battery cap to the positive and negative lead of the capacitor respectively. The 100 µF capacitor provides power supply decoupling, that is, it prevents spikes in the circuit. The capacitor plays a very important role because we will be dealing with analog signals in our circuit. 


Next place a 270 ohms resistor in the board in such a way that its leads are inline with the positive lead of the capacitor.



Once the resistor is soldered, connect its lead, which is closest to the capacitor to the red wire of the battery cap.



Then solder a Green LED to the board such that its positive lead is inline with the other end of the 270 ohms resistor. This green LED will be used as a power indicator. Whenever the circuit is powered the green LED will glow. If the LED does not glow it is a clear indiacation that something in the circuit is wrong(most of the time it is a short circuit). The LED becomes really useful during debugging.


Be carefull while soldering LEDs, they are easily damaged by heat

Connect the LED’s positive lead to the end of the resistor closest to it and connect its negative lead to the black wire of the battery clip(Gnd).



Plug in your battery to the battery cap, and if you have done everything right, the green LED will glow.



Unplug the battery from the battery cap and place the DIP socket into the board as shown and solder it. The DIP socket is used as a base to the L293d motor driver IC. Since ICs are damaged by heat, you will have to first solder the DIP socket into the board and then place the IC in the socket. By using DIP sockets in your circuits, you can use the same IC in different circuits.


The next step is to solder pins as shown in the follow images. Refer to the graphical representation, given later in the page, if you are not sure about the connections.




Once the above connections are made, insert four male header pins as shown in the next image(refer to the graphical circuit diagram given later in the tutorial). 


Connect each header pin to the DIP socket’s pin closet to it. 


In the next step we will solder the two 20k presets. The preset we use has three pins. The two pins that are together are the track pins. The pin that is separate from the track pins is the wiper.The presets will be used to adjust the sensitivity of the sensors. 


After soldering the presets to the PC board, connect one track pin of one preset to the track pin of the other. 


Then connect the joint to the red wire of the battery cap. 


Then place two BC548 transistors such that each of their bases is inline with one of the two presets wiper.


  Be careful while soldering transistors, they are damaged by heat.


The next step is to connect the two emitters of the transistors together. I used red wire for connecting the two emitters. 



Similarly connect the two collectors of the transistors together and finally connect the joint to the track pin of the preset.

   Similarly solder two more presets and transistors on the other side of the DIP socket. And connect them as you did previously for the other two presets and transistors.




Then connect the wipers and bases of transistors as shown below with the help of blue wires.




You will have to insert two 1K resistors into the board as shown below, once you have soldered all the four transistors and presets as shown above. Solder the resistor such that its leads are inline with the emitter of the transistor. Connect one end of the resistor to the emitter of the transistor. 



Next insert two red LEDs such that their anodes are inline with 1K resistor’s leads. Solder their anodes to the other lead of the 1k resistor and connect their cathodes to the black wire of the battery cap. 


Once done, cut five 5 cm long wires and add molex connectors to each using the method given at




Solder two of these wires to the 1K resistors. From these wires we will get high or low inputs from the sensors to drive the motor 


Solder the remaining two wires to the red wire of the battery cap.
With this the circuit board is complete. The graphical soldering and wiring diagram is given below.


For polarized components - Capacitors and LEDs – the red pin is the positive lead and black is the negative lead.


The Sensor Module

The Sensor Module comprises of four LEDs to emit light and four LDRs to sense the intensity of light.
For the sensor module we will make use of the 8cm x 1cm PC Board which we cut at the beginning of the tutorial. Normally, 1cm of PC Board would have four rows of holes. Just for the sake of convenience I named the four rows A, B, C and D.



Insert the four blue LEDs into the module such that their anode is in row B and cathode in row C.

Note that all the anodes & cathodes of the LEDs are inserted in the same row.

Don’t cut the leads but bend them as I have done here.


Once the leads have been bent solder them as show below.What I have done here is connected the LEDs in parallel.  


After soldering the LEDs, insert the LDR next to a LEDs such that its leads are in the rows A and D (outermost rows). 


Solder the remaining LDRs in the same manner. 



Once done, solder 10cm long blue wire to one lead of each LDR 


Connect the other leads of all the LDRs together and solder it to a 10cm long black wire. All that we are doing here is connecting one lead of each LDR to the Ground through the long Black wire.



In the nest step, solder 10 cm long red and black wires in the rows B and C respectively. These wires will provide current for the LEDs.



Once soldered to the board connect the red wire to the anode and the black wire to the cathode of a LED.



The sensor module is now complete. A graphical representation of the sensor module and its wiring diagram is given below.


The $40 Line Follower - Step 4: Putting everything together

In this part of the tutorial I will explain the process of connecting the sensor to the main circuit board and mounting them to the robot’s chassis.


There will be 7 wires coming out of your sensor module. Solder the two black wires and one red wire to the black wire and red wire of the battery cap respectively. The remaining four blue wires should be connected to each presets wiper as shown below. Note that wires from the left sensors and right sensors should be connected to the presets to the left and right of the DIP socket respectively.


I advice you to add a 270 ohms resistor between the red wire from the sensor board and Vcc(red wire of the battery clip) to limit the current reaching the LEDs. I have not fried a single LED but some SOR members have fried their LEDs for not having used the resistor. 


Solder the motor wires as shown in the image below (Refer to the circuit diagram if you are confused about the connection).


Next mount the sensor module and the circuit board to the robot’s base through the spacers. Before mounting the main circuit board make sure that you have attached the 9V battery to the base.


Sensor board mounted to the base


The main circuit board mounted to the base


This completes the construction of the robot. But there is still one step left , which I call “Pin Plugging”. You may have noticed (if you have gone through the circuit diagram) that all the input pins of the L293D are left unconnected (apart from being connected to a header pin) in the circuit board. The reason I did this was because the connections change every time you want the robot to achieve a different task (line following, obstacle avoiding etc. )  

To use the robot as a black line follower, obstacle avoider and photophobe, make the following connections in the main circuit board.



To use the robot as a white line follower and photovore  make the following connections.




Time taken to build the robot - 


Research :-10-15 hours

Designing:-  4 hours

Building the chassis:-  < 1 hour

Electronics :- 3 hours

Click here to view the shake test.