Line Following Sensor (DIY)

Line Following Banner
This is my attempt to create a simple line following sensor on my own. These sensors can be easily bought but it can be quite expensive considering that the components on it are quite simple.

It’s been some time since I’ve played with passive components and analogue design. I will be using the humble op-amp (operational amplifier) to compare the input signals and translate it into digital output. It will save CPU resource for other important tasks.

A line following robot will detect a contrasting line, meaning black line on white background or white line on black background.


Black colour will absorb all the light while white colour will reflect all the light. By using these characteristics, we can utilize the LDR (light dependent resistor) to detect how much light is available at that instance. When it is on black, the resistance will be very high because there is very little light reflection from the black surface. When it’s on the white surface, the resistance will be low because white surfaces reflect most of the light.


Be sure to get all of the LDRs from the same shop at the same time to ensure that they are manufactured in the same batch. Doing this will ensure all of them will behave the same way and eliminates the need of tuning each sensor individually.

Let’s start with a simple comparator circuit.


A voltage reference is being sent into the inverting input while an external signal is sent to the non-inverting input. When the non-inverting input is higher than the inverting input, Vout will saturate to V+. Otherwise, Vout will saturate to V-.

With this basic idea, we can compare the input level of the LDR to a reference level.


Case study



Comparator output conditions


Timing diagram


This is my test circuit and video for a single sensor.



I’ve used two LM324 Quad Op-Amp IC to get eight comparators.


This is my circuit on a donut board. It has 8 LDR sensors.


Super bright red LEDs to illuminate the surface. There are 9 of them so that each LDR has uniform coverage.





The reason why I didn’t use a normal copper PCB because this kind of circuit will require two layers and it’s quite a hassle.


Instead I just have jumper wires flying around the board. Very messy but it works.


A single 10k ohm potentiometer to calibrate all 8 sensors at once.


Turned on.


In the dark.


Here’s a demonstration video.

Print Friendly
  1. Jeric01-11-2018

    Hi how to get the average sensor reading in your program?

  2. Anderson11-29-2016

    Can u give me a circuit for reference?

  3. Shreyesh Desai09-13-2015

    any specific reason for using red leds..can white leds be used

  4. Shreyesh Desai09-13-2015

    Any specific reason behind using red leds..would white leds do..??

  5. krish06-04-2015

    can i know why u have used 9 sensors instead….

  6. vick06-05-2013

    Awesome!! Gonna try it out soon !

    • http://www./12-24-2016

      Beautiful post, Elaine. I especially like the line, “Because the understanding birthed in our long ago and far away can be the sure and vital anchor that serves us in our now.” I really love that. If ever an anchor was needed, it’s now.

    • That’s 2 clever by half and 2×2 clever 4 me. Thanks!

    • who is who? who came up with that one? did they tell you they wanted to do that or does it come in your package??? one more question, do ask your costumers what kind of music they prefer or do you just go with the flow??? I love your videos mikey mike i learn allot from them thankxxxxx

  7. Kwong Ming You06-02-2013

    Hi, can you tell me where you buy that 10k ohm potentiometer?

    • Wai Hung06-02-2013

      Most shops in Jalan Pasar will have it. Just mention for PCB mount, they will understand 🙂

Leave a Reply