Blog Entry

The LM324 Quad Op-Amp Line Follower Robot with Pulse Width Modulation

January 14, 2011 by , under Robotics.

Designing a simple and yet functional Line Follower Robot (LFR) is always a fascinating and challenging subject to be learned, the LFR actually could be implemented in many ways start from a simple two transistors to a sophisticated PID (Proportional, Integrate and Differential) which take advantage of the programmable feature of microcontroller to calculate the PID equation to successfully navigate the black track line on a white background surface.

Designing a non microcontroller based LFR is quite challenging tasks as we need to limit the electronic components numbers so the LFR will not too complicated to be built by most average robotics beginners or electronic hobbyists, but at the same time we need to have a good speed control mechanism in order for the LFR to navigate the black track line successfully. The microcontroller based design LFR in the other hand is a popular choice because it reduces a number of electronic components significantly while still providing a flexible programmable control to the LFR.

On this tutorial we are going to build yet another LFR using just the standard analog components easily found on the market but use the same speed control method technique found in many good microcontroller based Line Follower Robot design. As the result we could get a good precision analog line follower robot that comparable to the microcontroller based Line Follower Robot design. On this tutorial you will also learn many useful information of how to use the operational amplifier.

The Line Follower Robot

This Line Follower Robot basically use a Cadmium Sulphide (CdS) photocell sensor or known as Light Dependent Resistor (LDR) and the high intensity blue Light Emitting Diode (LED) to illuminate the area under the photocell sensor to sense the black track line and the DC motor speed control technique to navigate the black line track as shown on this following picture:

The easy method to navigate the black track line is to turn ON and OFF the left or the right DC motor according to the sensor reading (black turn OFF and white turn ON), but using this method will make the LFR to move in zigzag way. By proportionally control both left and right DC motor speed according to the light intensity level received by the photocell sensor (reflected back by the black track line) we could make the LFR easily navigate this track. The common technique to control the motor speed efficiently is to use a pulse signal known as the pulse width modulation or PWM for short.

PWM basically is an ON and OFF pulse signal with a constant period or frequency. The proportion of pulse ON time to the pulse period is called a “duty cycle” and it expressed in percentage. For example if the proportion of pulse ON time is 50% to the total pulse period than we say that the PWM duty cycle is 50%. The PWM duty cycle percentage is corresponding to the average power produced by the pulse signal; the lower percentage produces less power than the higher percentage.

Therefore by changing the PWM duty cycles we could change the average voltage across the DC motor terminals, this mean we could vary the DC motor speed just by changing the PWM duty cycle. Therefore to make the LFR smoothly navigate the black track line, we have to adjust the PWM duty cycle according to the photocell sensor reading. The brighter light intensity level received by sensor (sensor is on the white surface) will result in higher PWM duty cycle percentage and the darker light intensity level (sensor is on the black line) received by photocell sensor will result in lower PWM duty cycle percentage.

By converting each of the photocell sensor light intensity level reading to the corresponding voltage level we could achieve this objective by using what is known as the Voltage Control Pulse Width Modulation principal.

Actually generating the PWM signal is easier with microcontroller instead of discrete components because all you have to do is to program the microcontroller PWM peripheral to do the task. On this tutorial we will learn of how to build this LFR with Voltage Control PWM using the same working principal found in many today’s modern microcontroller but using just the analog electronic components.

Now let list down the necessary electronic and other supported components to build this awesome LFR:

1. Resistors: 220 (2), 1K (2), 15K (1), 33K (1), 47K (2), and 100K (1)
2. Trimpots: 100K (2)
3. Two Light Dependent Resistor (dark above 100KOhm and below 5KOhm  on bright light intensity)
4. Capacitors: 47uF/16v (1) and 0.1uF (5)
5. Diodes: 1N4148 (2)
6. High Intensity 3 mm blue Light Emitting Diode (2)
7. Optional 5 mm auto flash RGB LED with 330 Ohm resistor for the power indicator
8. Transistors: BC639 (2)
9. IC: National Semiconductor LM324 Quad Operational Amplifier (1)
10. DC Motor: Solarbotics GM2 Geared DC motor with Wheel (2)
11. Prototype Board: 52 x 38 mm for main board and 50 x 15 mm for sensors
12. 3xAA Battery holder
13. CD/DVD ROM (2)
14. Plastic Beads and Paper Clip for the castor (the third wheel)
15. Bolt, Nuts, Double Tape and Standard Electrical Tape for the black line

The complete Line Follower Robot electronics schematic is shown on this following picture:

The Voltage Control PWM

The main brain of this Line Follower Robot is lay behind the LM324 quad operational amplifier from National Semiconductor. The dual in line LM324 packages contains four identical op-amps and is specially designed to operate as an analog device.

The voltage control PWM could be generated by first using the triangle signal generator which provide the basic PWM pulse frequency and the necessary ramp voltage (rise and down) to produce the PWM signal. Next by continuously comparing this ramp voltage according to the voltage level produced by the photocell sensor using the comparator circuit we could produced the exact voltage control PWM as shown on this following picture.

When the triangle rise ramp signal reaches the voltage threshold point it will turn ON the comparator because the comparator non inverting input (V+) voltage is greater than the comparator inverting input (V-) voltage and when the down ramp signal reaches the voltage threshold point it will turn OFF the comparator because now the comparator inverting input (V-) voltage is greater than the comparator non inverting input (V+) voltage. You could read more about how the comparator works on Working with the Comparator Circuit in this blog.

If we set the threshold point voltage higher, then the ON period will be shorten; and if we set the threshold point voltage lower, then the ON period will be longer. Therefore by varying the threshold point voltage we could also vary the ON and OFF period of the comparator which is the exact behavior that we are looking for to produce the required PWM signal to drive the Line Follower Robot geared DC motor.

The ramp signal is provided by the two op-amps (U1A and U1B) that generate the triangle wave signal while the comparator for producing the PWM to each DC motor is provided by the other two op-amps (U1C and U1D) that receipt its input from the voltage divider circuit (VR and LDR) which provide the voltage threshold point and together with the triangle wave to produce the required PWM pulse

The PWM principal explained above is also used in many today’s modern microcontrollers PWM peripheral; but instead of processing the analog signal it process the digital signal. The ramp signal is replaced by the digital counter (TIMER peripheral) that will count up from 0 to 255 and start from 0 again, while the threshold point voltage is provided by threshold point register that hold the digital value (e.g. 100).

Microcontroller uses the digital comparator to compare these two digital values, when the digital counter counting up and reach the threshold point (i.e. 100) then the PWM peripheral will turn on to the output port and when it reach the maximum value (i.e. 255) it will turn off to the output port. Therefore by changing the threshold point register value we could change the PWM duty cycle output. You could read more about microcontroller based PWM on H-Bridge Microchip PIC Microcontroller PWM Motor Controller and Introduction to AVR Microcontroller Pulse Width Modulation (PWM) articles on this blog.

When designing the electronic circuit is a good habit to prototype it first, the prototype circuit enables us to fine tune the electronics design and give us the picture (signal wave) of how the circuit really works. The following picture is the Line Follower Robot circuit prototype on a breadboard complete with sensor (LED and LDR pairs) and the GM2 geared DC motor from Solarbotics.

The Triangle Wave Generator Circuit

Now as you understand the principal of how the Line Follower Circuit works than let’s take a look at the triangle wave generator circuit. In order to make it easy to understand I redraw the electronic schematic circuit separately as shown on this following picture:

To generate the triangle wave we need to use the Schmitt Trigger circuit (also called a comparator with hysteresis) that act as ON and OFF switch to the Integrator circuit input. The integrator uses the R5 and C2 to produce the necessary triangle linear ramp (up and down) on its output.

When the power up we assume the U1A output is HIGH (Vcc); the C2 capacitor will start to charge through the R5 resistor. Because the R5 and C2 is connected to the U1B inverting input (V-), therefore the U1B output will start to ramp down. The U1A non inverting input (V+) get the positive feedback from R3 and R4, when the U1B output voltage reach the threshold voltage below Vref than it will turn the U1A output to LOW (0). This bottom threshold voltage could be calculated as follow:

Vth = (R4 (Vout-u1a – Vout-u1b) / (R4 + R3)) + Vou-u1b; Vout-u1a = Vcc; Vcc = 4.5 Volt

Vth <= Vref, Vref = 0.4 Vcc

(R4 (Vcc – Vout-u1b) / (R4 + R3)) + Vout-u1b <= 0.4 Vcc

Now putting all the resistors value then we will get this following result:

(47 (Vcc – Vout-u1b)/ 147) + Vout-u1b <= 0.4 Vcc

1.4 – 0.3 Vout-u1b + Vout-u1b <= 1.8

Vout-u1b <= 0.6 Volt

Therefore the U1B output will ramp down to about 0.6 volt than the U1A output will turn OFF. Next the C2 capacitor will discharge through R5 and the UA1B output will start to ramp up and it start to increase the voltage across the R4 (Vth – threshold voltage) until the Vth voltage above the Vref voltage then the U1A output will turn to HIGH and the whole cycle will repeat again. This upper threshold voltage could be calculated as follow:

Vth = (R4 (Vout-u1a – Vout-u1b) / (R4 + R3)) + Vou-u1b; Vout-u1a = 0; Vcc = 4.5 Volt

Vth >= Vref; Vref = 0.4 Vcc

(R4 (- Vout-u1b) / (R4 + R3)) + Vout-u1b >= 0.4 Vcc

Now putting all the resistors value then we will get this following result:

(47 (- Vout-u1b)/ 147) + Vout-u1b >= 0.4 Vcc

– 0.3 Vout-u1b + Vout-u1b >= 1.8

Vout-u1b >= 2.6 Volt

Therefore the triangle voltage will ramp up from 0.6 volt to 2.6 volt then ramp down to 0.6 volt repeatedly. The frequency of the triangle wave could be calculated as follow:

Frequency = (1 / (4 x R5 x C2)) x (R3/R4) Hertz

Now putting all the resistors and capacitor value then we will get this following result:

Frequency = (1 / (4 x 15,000 x 0.0000001)) x (100,000/47,000) = 354.61 Hz

As you might guess the actual frequency measured on this Line Follower Robot prototype circuit above is about 292 Hz, this is due to the electronic components tolerance value (resistors and capacitors). Therefore if you want to have the exact frequency you could put a 100K trimport in series with R5 resistors. The voltage divider R1 and R2 provide the voltage reference (DC bias voltage) to both U1A and U1B op-amps.

The Sensor Circuit

As mention above this Line Follower Robot take advantage of the photo-resistor (CdS) known as Light Dependent Resistor (LDR). The LDR will decreases its resistance in the presence of light and increase its resistance in the dark. The region under the LDR is illuminate with a high intensity blue LED, the white surface will reflect most of the light to the LDR surface while the black track line will absorb most of the light, therefore less light will reflect to the LDR surface.

As the robot move on the black track line the LDR will continuously capture the reflected light and convert this light intensity into the corresponding voltage and feeding it to the inverting input (V-) of U1C (left sensor) and U1D (right sensor).

The 100K trimpot and LDR basically is the voltage divider circuit when the LDR detect the black track line it will receive less light intensity (LDR resistance increase) and the voltage (V-) will increase; this will decrease the PWM duty cycle output and as the result the geared DC motor will turn slowly or stop. When the LDR on the white surface it will receive maximum light intensity (LDR resistance decrease) and the voltage (V-) will decrease; this will increase the PWM duty cycle output and as the result the geared DC motor will turn fast.

You could simply exchange the comparator V+ and V- input source to make the Line Follower Robot detect the white line on the black surface instead of normal black line on the white surface. By using two DPDT (Double Pole Double Throw) switches you could achieve this behavior as shown on this following picture:

The geared DC motor driver uses the BC639 transistor and the base terminal is connected to the comparator output through the 1K resistor. The transistor is operated as a switch which turns ON and OFF the geared DC motor according to the PWM pulse current it received from the comparator. The 0.1uF capacitor across the geared DC motor’s terminal is used to reduce noise generated by the DC motor. For more information about using transistor as switch you could read Using Transistor as Switch article on this blog.

The Line Follower Robot Construction

The Line Follower Robot construction could be constructed freely but the easiest one is to use the discarded CD/DVD ROM as shown on this following pictures:

I glue the two CDROM together in order to make more room and attached the two DC motors, 3xAA battery holder, main board and sensor board using the double tape. The sensor sensitivities and the Line Follower Robot speed could be controlled by adjusting the 100K trimport. After putting all the parts together now is time to watch how this nice Line Follower Robot in action:

The Final Thought

As you’ve seen from the demo video above this Line Follower Robot design is capable to handle and smoothly navigate a quite complex black track line. This prove that a good analog Line Follower Robot design sometimes could outperform many microcontrollers based Line Follower Robot.

Building the Line Follower Robot (LFR) is one of my favorite projects as I enjoy designing and making this kind of robot, it also gives much joy and fun to my kids as well. I hope this project will give you as much joy as I did; building, watching, and playing with this analog Line Follower Robot.

Bookmarks and Share

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

110 Responses to “The LM324 Quad Op-Amp Line Follower Robot with Pulse Width Modulation”


Comment by UJ.

Very nice article. Just one question, how did you get the formula for the integrator frequency?
Thank you for the good work.


Comment by rwb.

Thanks, Actually you could find this formula in any good Op-Amps textbook. Here is the simple explanation:

The half of triangle ramp slope time (t):

t = 2.R5.C2 . (R4/(R3 + R4))

Therefore for one period (T = 2t):

T = 4.R5.C2 . (R4/(R3 + R4))

f (Frequency) = 1/T, and assume R3 > R4, then we could get this following equation:

f = 1 / (4.R5.C2) . (R3/R4)


Comment by ankur619.

thanks a lot for this tutorial sir…it helped me a lot…
Sir can we use any ordinary geared motor for this project


Comment by rwb.

Sure, you can use any low RPM geared DC motor.


Comment by jp1238.

sir,can v use an input power of 12 volt.


Comment by rwb.

This LFR circuit is designed to work within 4.5 to 5 volt.


Comment by jp1238.

sir then its movement will be very slow isnt it. how to increase the speed.i bought a motor of 200 rpm dc 6volt, will that work???..


Comment by rwb.

If you compare with “Build Your Own Microcontroller Based PID Control Line Follower Robot (LFR) (Second Part)” project; yes it slower but if you compare with “Build Your Own Transistor Based Mobile Line Follower Robot (LFR) First Part” project; this LFR is faster. Because in this project I used a simple sensor such as LDR and control for tracking the black line, therefore you could not get a “fast” LFR; I would say this LFR speed is moderate.

Anyway you should experiment with your motor and adjust the geared DC motor speed with the trimport (i.e. VR1 and VR2). My suggestion, don’t afraid to experiment with electronics, this is how you gain your experiences and knowledge.


Comment by jp1238.

thank you sir..ur tutor is more helpfull to me..i need more of this stuffs..if you have any new electronics projects please sent it to me it will be more helpfull to me,as ur explanation is more understandable to me than others.My email id is…these projects helps me a lot…


Comment by j-pal.

what was the cost to build this robot?


Comment by rwb.

The most expensive parts is the DC geared motor, it will cost about USD 20 for two motors with wheels. The LDR, Resistors, Trimports, LEDs, Transistors, LM324 Quad Op-Amp, Cables, Prototype Boards and 3AA battery holder are less then USD 15. Therefore the total cost to build this LFR should be less than USD 40.


Comment by jyothinath.

Can u please give a circuit having “obstacle sensor ” coupled along with this line follower robot..


Comment by rwb.

Currently this circuit is mainly designed as LFR without the obstacle sensor to keep it simple.


Comment by jyothinath.

ok..but when we place some aditional features like obstacle sensor , will this be able to move smoothly ?


Comment by rwb.

Its depend on the robot design e.g. the priority level that you assigned to the line sensor and the obstacle sensors. You could read more regarding this matter on “Building BRAM your first Autonomous Mobile Robot using Microchip PIC Microcontroller – Part 1” and “Behavior Based Artificial Intelligent Mobile Robot with Sharp GP2D120 Distance Measuring Sensor – BRAM Part 2” articles.


Comment by ankur619.

sir..I Can’t find the BC639 transistor in the local market..
Please suggest any possibe substitutes for this transistor..

Thank u


Comment by rwb.

You could replace it with 2N2222A


Comment by Sangeeth.

Sir,we tried this circuit,but the sensor part did not work wit a supply of 5v.sir,what’s d rpm of the dc geared motor using here??pls reply…


Comment by ankur619.

sir..i have connected all the components as the circuit mentioned above..but there is no deflection in the motor..
The motors,leds and the ldrs are allright..but still no deflection…
Please help me sir
i would be really grateful to u


Comment by rwb.

@Sangeeth, @ankur619: You need to recheck and recheck again all of your electronic components connection, make sure you follow the exact circuit diagram above. In this project I used Solarbotics GM2 geared DC motor.


Comment by Sangeeth.

Thanks sir 4 d rply.i checkd d ckt again nd again.we got d motors working(usd toy motors)bt d sensor part shows no o/p at al.d led’s didnt glow..can we use ny other motor other than solarbotics,as it s nt available in kerala..pls do rply sir


Comment by ankur619.

sir…my leds are glowing but the motor are nt showing any deflection..i think there is some mistake in the..U1A and U1B part. I guess the polarity should be interchanged which is shown in the ckt diagram you mentioned above


Comment by ankur619.

I am using a trimpot which has 3 which 2 terminals should i use to connect in this circuit..plz help me sir


Comment by rwb.

@Sangeeth: As long as it has the same specification with Solarbotics GM2 geared DC motor and you could always experiment with other geared DC motor.

@ankur619: Follow the electronic schematic! For the trimport you could use three terminals as shown on the schematic (an arrow is for the center terminal) or just two terminals i.e. the center terminal and one of the other two terminals.


Comment by Sangeeth.

Thanx 4 d rply sir.ny idea abt y d sensor part nt workng??should we use dual supply or sumting??


Comment by rwb.

Make sure you connect all the electronic parts correctly i.e. LED and LDR


Comment by ankur619.

i have one question…….for eg we have a straight black line over a white surface and another black line which is intersecting the first black line at 90 degree….will this robot be able to cros over the crossed path…..or it will stop? please help me with the robot which can perform this task…….


Comment by rwb.

Yes, you could watch the LFR crossing the black line on the video link above.


Comment by polaris589.

thanks for the last time about whetherif we could applied logic gates in based line transistor line follower .I’ve searched all over the net and is said we can used the comparator ic which compares the sensors voltage applied to one input with a preset reference voltage on the other. The output changes polarity when the sensor voltage exceeds or falls below the reference voltage…is it possible to apply? ..thanks again ..


Comment by rwb.

This project use the PWM method (more advance) to control the geared DC motor speed instead of just ON and OFF. You could read more information about using a comparator on “Working with the Comparator Circuit” article.


Comment by polaris589.

okie thanks again but were planning to used the comparator transistor in the transistor based follower.


Comment by polaris589.

and also without using a microcontroller…just a comparator


Comment by a2p4r1l.

hi, do u have any idea on how to connect lm393 or a comparator instead of the transistor used in ur transistor-based line follower? or how will the schema look like if we replace the transistor into a comparator?

i really need ur help. thank u in advanced :)


Comment by rwb.

@polaris589 and @a2p4r1l, study and read the basic principal of using the LM339 comparator in “Working with the Comparator Circuit” article! Remember you could not drive the geared DC motor directly with LM393 dual comparator output because the output sink current is only about 16 mA (the LM339 output sink current is about 18 mA), you have to use a transistors for a larger current.


Comment by Sangeeth.

Sir i am about to cmplete dis prjct as per ur instructions.everything s working fyn xcept d sensor part.i mean that d motor speed s nt changing wit d light intensity sensd by ldr.pls help sir.thanx in advance


Comment by rwb.

Recheck your circuit and adjust the 100K trimpot until the DC motor response to the sensors (LDR)


Comment by Sangeeth.

thanx 4 reply.checkd d ckt again.tried adjustng d trimport but stil d motors dnt hav ny idea of wat s goin on n tinking abt droping dis prjct.if u hav ny informatn dat helpd u during ur prjct pls mail


Comment by rwb.

Did you use the same operating voltage (i.e. 4.5 Volt to 5 Volt) as shown on the schematic? When you adjust the trimpot wiper toward the Vcc, the inverting input (V-) of U1C/U1D Op-Amp should be about Vcc and this will turn off your DC motor. The average voltage measured on the triangle wave generator output (V+ of U1C/U1D Op-Amp input) should be less then Vcc. If your DC motor keep spining then you have to recheck your circuit again.


Comment by Sangeeth.

thanx.jst 1 mre questn.we r using vega robokit 12 v dc geard motor of 45 rpm.cud dat b d pblm y we r nt able 2 change speed??its rotating pretty wel,but d speed cant b changd basd on light falng on d ldr.pls reply


Comment by rwb.

The LM324 LFR circuit above, especially for the triangle wave generator is designed for 4.5 volt to 5 volt operation, if you use 12 Volt its possible the triangle wave generator will not work.


Comment by Arwah.

i just try to modify your Analog LFR schematic and add someting at motor dc power supplay. and get schematic like this :

at your schematic, motor get 4,5 volt power supllay, but in mine motor dc get 9 volt. can it work?
i’m not yet try this one.
thanks sir.


Comment by rwb.

Yes, you could try to use 9 volt to power the geared DC motor. Just make sure the operating current is within the BC639 transistor specification.


Comment by Arwah.

it’s so supprise know that you from indonesia.
saya Arif Wahidin dari bandung. salam kenal.
Terimakasih bantuannya.


Comment by with_my_dreams.

dear rwb,
I’ve done everything that you have told but still the motor is not showing any deflection.Its a micro geared dc motor,6v rating.I didn’t get the 5v geared dc motor and the only option left for me I guess is to provide 6v to the motor and 4.5 v to the other part like Arwah mentioned in his circuit.I am confused about BC639 current specification…could you please help me about that?


Comment by rwb.

First you need to make sure the triangle generator is working using an oscilloscope or LED in series with 330 Ohm resistor (the LED will dimly glow). Next connect the LDR, Trimpot, Comparator, Transistor, and the DC motor; adjust the trimpot until the DC motor response to the light intensity received by LDR.

What I mean by BC639 transistor current specification is the BC639 maximum collector current is about 1 A, usually we only used half of its maximum current specification. Therefore by rising the working voltage to 9 volt it will possible this maximum current will exceeded (i.e. depend on the DC motor you used). You could read more about using transistor as switch on this following articles:

Using Transistor as a Switch


Comment by with_my_dreams.

I connected the LED with 330 ohm resistance in series at 7 no pin and it glowed dimly,connected to pin 8 & 14 and LED glowed quite brightly…but I just dont know why I did not get any voltage output across Vcc and collector of BC639. what could be the possible reason?I have my project submission deadline coming up and I am being frustrated more than ever…please suggest me anything that might work…


Comment by rwb.

Try to connect the BC639 transistor base terminal with 1K Ohm in series directly to Vcc, this should turn ON the DC motor. If not check your BC639 transistor terminals connection.


Comment by with_my_dreams.

this doesn’t turn on my motor :(


Comment by rwb.

Try to lower the BC639 transistor base terminal resistor value from 1K to 150 Ohm and connect it directly to Vcc. If this connection doesn’t make the DC motor to turn ON, then maybe you are wrongly connect the BC639 transistor base, collector and emitter terminals or you used a broken transistor (assuming the DC motor is working well).


Comment by with_my_dreams.

yes the motor is NOW showing some movement :D what should i do now?should I connect 150 ohm in series to base instead of 1k?thank you so much for your advice :)


Comment by with_my_dreams.

i think my transistor burnt or something because now the motor is not moving again :(


Comment by with_my_dreams.

please forgive me if i am wrong but the motor actually rotates when I connect BC639 reversely!in your picture of bc639 its ECB if the black dot is in front of me but if I connect considering it BCE then it works fine!


Comment by anotech.

sir, i have made this robot and waiting for that chip.
so i want to know something…
how can i program this robot?
is this robot need programming? (b’cos there aren’t any
ports to connect this with computer.)
if it needs programming which type of programmer must be
and the source code….
please reply me sir..
you can contact me with my mail add.


Comment by anotech.

…EBAY…LM324…(link removed)

is this is the ic used above, please clear my doubt sir.


Comment by rwb.

You should read the project article above carefully to really understand of how the LM324 Line Follower Robot (LFR) work. This LFR is designed using the Quad Op-Amp LM324, this chip is not a microcontroller, therefore you don’t need any programming nor programmer in order to make it work.

About the ebay link (removed), yes that’s the IC I’ve used in this project but the price is unbelievable (US$ 8.99), this chip should be less than US$ 1. Try to find it at your local electronic component store.


Comment by anotech.

thanx a lot


Comment by anotech.

PIC 16f877A
how can i connect these 2 ics???
plz help mee sir


Comment by anotech.

and also do they need programming


Comment by rwb.

You could read “Building BRAM your first Autonomous Mobile Robot using Microchip PIC Microcontroller – Part 1” and “Behavior Based Artificial Intelligent Mobile Robot with Sharp GP2D120 Distance Measuring Sensor – BRAM Part 2” articles in this blog for connecting the L293D dual H-Bridge chip to microcontroller, and yes the Microchip PIC16F877A microcontroller need to be programmed in order to work.


Comment by anotech.

Thank you sir :)


Comment by anotech.

thanx a lot sir, and i want to make a circuit board, i want a electronics schematic to make a circuit board…
sir can u help me…….


Comment by rwb.

There are a lot circuit board schematic for the Microchip PIC16F877A microcontroller, just google it.


Comment by jahangir.

Hello sir, first of all thank you so much for this tutorial. I really value your hardwork and effort that you have put in. Secondly i have following questions:

– I have followed your tutorial properly with only diff that i was not able to find 6v DCGM as you suggested but i have 12v DCGM. The issue is the speed of the motor is NOT changing w.r.t light intensity and it either goes ON or OFF. The trimport is also no help as it makes no diff. Is using 12v is the issue here or my sensitivity of LED/LDR has something to do with it?

In the end, again thank you for this tutorial it helped me alot in my project.


Comment by rwb.

The triangle generator circuit is designed to work within 4.5 to 5 volt operation, in other world you could use 12 volt motor (supplied to the transistor) but use 4.5 to 5 volt for the LM324 op-amp circuit.


Comment by jahangir.

Thank you so much for such a prompt reply dear. My problem is that i have only 12v available. I have done extensive search in market and not able to find 6v DCGM, my question is , can i modify this circuit (like a fellow up there tried to do with 9v with a FACEBOOK url given in his reply) to make it operate on 12v or not?

An instructor suggested to use an external source for 12v motor and 4.5 for your circuit. If this is possible , how i can do it? Is the circuit given by the 9v-guy correct? Can i attempt similarly to extend it to 12v ?

I am sorry but the place i live is not much developed and finding project parts is very difficult. Your usual help will be much appreciated


Comment by rwb.

Yes, you could try that circuit.


Comment by anotech.

LM324 IC
L293 IC

Sir i wanna circuit diagram to make a circuit.. its a thing to make a circuit with these IC’s….
can u please help me sir…..
if u wish to help me please send the diagram to my mail address

iam waiting for your reply…………. :)


Comment by rwb.

I really sorry, as the ermicroblog policy, I could not provide you the electronic schematic nor programing for any personal project or school assignment.


Comment by nikeagg18.

sir how will this behave if it is placed on a square track instead of 8 track.


Comment by rwb.

This LFR design is not intended for sharp bend (e.g. 90 degree).


Comment by nikeagg18.

thanks alot sir but how can i make a lfr for this purpose


Comment by rwb.

Need more sensors as well as the controller, you could read about this LFR on this following articles:

Build Your Own Microcontroller Based PID Control Line Follower Robot (LFR) – Second Part


Comment by nikeagg18.

thank u sir, actually i am begginer for lfrs, can u tell will it make any difference if i used white led instead of blue and what should be the minimum witdh of the track for the lfr??


Comment by rwb.

No it won’t make any different, the minimum track width for this LFR is about 18mm (standard electrical tape).


Comment by nikeagg18.

thanks alot sir


Comment by Ankush Thakur.

Dear Sir….
1.Did I have to ground this I.c.??
2.Can you suggest me a method to check sensor part on bread Board without an Oscilloscope??
Actually according to connections sensor part is not working
there is no delflection.
3.And instead of trimmpot may I use preset(variable resistor) of 100 k ??


Comment by rwb.

1. Absolutely you have to connect to GND (Pin 11) and V+ (Pin 4) of the LM324 IC to the power source (i.e. 3xAA battery).
2. The oscilloscope in this article is used for showing how the circuit work and is not intended for checking the sensors, therefore you could check your sensors by observing the DC motor response.
3. Used electronics components exactly as shown on the schematics above. The trimpot is needed for adjusting the sensors response.


Comment by Ankush Thakur.

Respected Sir..
Can’t we use anything else instead of trimpot as it is not avaliable here of 100k ??
can I use 5 trimpot of 20k its is the only avaliable rating here but I guess this becomes complicated to use…

And can i use ordinary dc motor of 12volt as geared motor is not avaliable here??

Suggest me some way sir..plz..?? :-)


Comment by Ankush Thakur.

DEar Sir…
Plz Do reply…. As i have to submit my project as soon as possible…. Plz Sir Plz…..
Thank You


Comment by rwb.

You could experiment to use 20K instead of 100K trimpot. Used geared DC motor and again this LM324 LFR circuit is designed to work with 4.5 to 5 volt voltage supply not 12 volt.


Comment by Ankush Thakur.

Dear Sir…..
THank You for your Help and this fantabulous illustration……
Everything is working Nicely…
I used normal Dc Motor as geared Dc motor is not avaliable here and 10kTrimmer potentiometer instead of 100k trimpot…..
But Everything is working nicely but sometimes motor got start by puuting black surface in front of sensor and it remains on…….
Can U plz help me in tha what’s going Wrong??
Thanks Once again………


Comment by yogeshkothiya.

Very very Thanx…….!!!!!!!
I will surely gonna make this project……for my college!!!!!
and keep updated with new pro……!!!!!
kk.thnx in advance!!!!!!!1


Comment by rwb.

@Ankush Thakur, Adjust the trimpot to make it stop.


Comment by aini666007.

is there a way to make the lfr stop when both sensors hit black??(w/o using microcontroller)

thnx in advance… :)


Comment by rwb.

The LFR design on this article will stop when both LDR sensors above the black line. Basically when you use microcontroller you could easily put in your program that “if both LDR sensors above the black line then stop the DC motor”.


Comment by aditya.

hi sir!
i m goin to use a 6v dc geard motor… wil ther b any problm wth the suply.
or i hav to provide 6 v to the motor itself??
plz do rply!


Comment by rwb.

You could try this LFR with 6 volt power supply.


Comment by aditya.

hello sir!
i hav made the circt bt found that the right motor is workng acordng to the sensor bt not the left one… evn the left sensor is not responding to light..i havnt checkd my circt wth the osciloscop for the PWM.. how can i adjust it.. please help!


Comment by rwb.

If the right motor is working, this mean the triangle wave generator is fine. You only need to recheck your circuit especially the left sensor circuit.


Comment by aditya.

hi Sir!
now both the motors are respondng acordng to the ldr. but the problm wich m facing is that when the ldr recives no light(black suroundng) the motor speeds up but not in the light.
now what i shud do. pleas help me.


Comment by rwb.

Recheck your circuit!


Comment by jjnorth.

Does it matter what size the ldr’s are


Comment by rwb.

Use LDR about the size as shown on this project (diameter approximately 4 to 7 mm) .


Comment by aditya.

hi!! sir
i made the robo… nd found thet using infra red sensors in plac of ldr is much more ssensitiv..
thanks for ur guidnce!


Comment by yogeshkothiya.

I am not getting BC639…..
what should i do…????
plz help.!!!


Comment by rwb.

The transistor is depend on the DC geared motor operating current, for direct BC639 substitute you could use the BFY51 transistor.


Comment by jjnorth.

Was wondering if anyone can help me out. I bought the components exactly as they were listed. i wired half of it on a breadboard like above. I am putting 5V to the breadboard. i am only getting 1.9V to the motor. My led is not lighting up though it is getting 1.9 volts as well. I,ve wired it up like the schematic and messed around with the trimpots resistance and nothing is working.


Comment by rwb.

You should check and recheck your circuit!


Comment by jjnorth.

This is the second time I have rewired it from scratch and switched out op-amps. Does anything sound familiar with the problems i am having


Comment by jjnorth.

Why on your picture(with the breadboard) does it look like pin 9 is going over to the trimpot and ldr when in the schematic it is pin 10


Comment by rwb.

You could find the answer on the LFR article above:

“You could simply exchange the comparator V+ and V- input source to make the Line Follower Robot detect the white line on the black surface instead of normal black line on the white surface”.

Remember the picture on the breadboard is the “experiment circuit” and is not intended as the guidance that you have to follow.


Comment by jjnorth.

Ok. i was just trying to find out whats wrong with my circuit and I just can’t find it. I thought maybe that was it.I don’t know why throughout most of my circuit i am only getting 1.9V


Comment by rwb.

My suggestion is to test your circuit one by one, make sure the BC639 transistor pins (i.e. B,C, and E) and the LM324 pins is correct. For example your sensor LED (series with 220 Ohm resistor) should be light up as is just a simple connection between the Vcc and GND.

Remember sometimes just a tiny mistake can ruin up all the circuit especially when you use a breadboard.


Comment by jjnorth.

Ok my power supply was acting up. Got the motor running and triangle wave form pin 7. My triangle wave is showing at negative 4V is this normal? also from pin 8 should i be getting a square wave on the oscilloscope? It is just blinking a straight negative 4v. I have adjusted the pot and saw no difference in the oscilloscope or the motor speed. any suggestions? thank you


Comment by rwb.

The triangle wave should be on the positive side and the pin 8 should give you a PWM output base on the light intensity captured by the LDR sensor.


Comment by jjnorth.

I am guessing that maybe i should try other phot resistors. Do you have a number for them. Will VT34N1 ones work i think they are close to 9mm. The ones i am trying now are 4mm. The 9mm ones are 4k in bright light and 200k in dark. If not what range should i be looking for.


Comment by jjnorth.

If my motor works and i have the triangle wave but am showing no change in motor speed or direction is LDR the most likely culprit?


Comment by rwb.

Try to measure the voltage between the trimport and LDR, it should change according to light intensity. Study the picture “PWM Duty Cycle Vary Based on The Light Intensity Received by LDR” above to understand the working principal of the Voltage Control PWM.


Comment by sikander39.

sir i have problem in transistor using switch,sir i have use TIP 122 NPN transistor connecting base terminal with 1kohm to 8 th pin of comparator ,DC motor work bt not logically it dont work according to LDR.


Comment by rwb.

Please read all the comments and answers above for the clue to solve your problem.