Converting a "photovore" circuit to a "self balancing" circuit.

Thread Starter

chaos51

Joined Jun 18, 2011
42
Hi,

(Warning, "dangerous" hobbyist amateur at play in this post, all discussions below are for fun only, and no professional guidelines have been being considered :) )

Below is a quick and dirty picture of the circuit, I made from combining a "Herby" or Photovore circuit, with a L293DNE and a simple transistor based "NOT gate".

The Herby or Photovore circuit (see BEAM robotics), found at: http://members.tripod.com/robomaniac_2001/id75.htm works like this.
If the photodiode on the left gets more light then the one on the right, the right motor will turn, and the "robot" it controls, turns left, following the light.
This actually work quite well, allthough a bit eratic. (I build a few of these so called photovore's before)
It uses the LM386 audio amplifier to get this "hack" done.

My reasoning was, that, light can also be used to detect the angle of a robot, if the photodiode is pointing downward, with a led eluminating the area just below it. The close the photodiode is to the ground, the closer the led is to the ground, the more luminance.

And using the same principle, but reverse. The herby circuite would make the robot "rotate to" the side with least light, since that side is furthest from the ground.

Now for the next step, to do that we need one motor to change direction based on the angle of the robot, instead of having two motors (both spinning in the same direction) being alternated.

So to make that change. I modified the output from the LM386 (marked as A in the circuit), and passed it to a inverter, creating a NOT A signal as well.
The NOT A and A signal drive the D293DNE to change direction of the motor. (A=5v+NOT_A_=0v) is left AND (A=0v+NOT_A=5v) is right.

Here is the pin layout of the D293Dxx
https://www.rakeshmondal.info/L293D-Motor-Driver


Below is the circuit.
upload_2018-8-5_13-43-58.png

It works. Sort of.
The problem is however that when photodiode 1 and 2 get pretty much the same, but not 100% the same amount of light.
Then the LM386, is not generating a clean 5v or 0v signal, but something in between.
I need some way to get the results like this: More then 2.5v is 5v and less then 2.5v is 0v. Nothing in between.

Maybe I could add an opamp or something, but that would clutter the circuit, and maybe I need to replace the LM386.

Any ideas how to get around this problem?
Any help appreciated!!
 
Last edited:

crutschow

Joined Mar 14, 2008
34,285
Why are you using an audio amp to do a comparator's job?

To have the output go to one state or the other with no in-between, you can add some hysteresis (positive feedback).
Try connecting a 1meg or so resistor between the output and the positive (+) input.
Adjust value to get the desired response.
 

Audioguru

Joined Dec 20, 2007
11,248
I agree that the LM386 audio power amplifier has an output that is designed to drive a speaker, some of them will not turn off your inverter transistor. Use a comparator (LM393 is a dual) instead. The comparator has an open collector output that needs a pullup resistor.
 

AnalogKid

Joined Aug 1, 2013
10,987
Or, for the same money and effort, use a LM358 dual opamp. Same pinout, same abiliby to turn off the transistor, but no pullup resistor needed.

AND - you can use the other half as an inverter to eliminate the transistor altogether.

ak
 

Thread Starter

chaos51

Joined Jun 18, 2011
42
Hi,

Thanks for the tips so far.
I will first try with the resistor to create the hysteresis, and if the result is still not satisfying I will check out the LM358 or LM393.

The reason why I went for the LM386, is two reasons.
1. Is I found the circuit in BEAM robotics book, and it had a LM386 in it
2. I have 50 or so LM386s laying around since I bought a "big bag" full of "surprise components" for very little money, just to have something to get started with. And so why not use what I have, if possible, and the results are reasonable.I might check if I have some true comparators laying around. That will be interesting, as I have not used them before (at least successfully).

-C51
 

crutschow

Joined Mar 14, 2008
34,285
One significant difference is that the LM386 has a relatively low gain , which thus requires a significant change in the input voltage to fully switch the output voltage, and that likely causes the behavior noted.
A comparator has a very high gain, so changes state over a sub-millivolt change in input voltage.
Thus its output won't stay at an intermediate voltage (although it can oscillate if there's no input hysteresis).
 

Thread Starter

chaos51

Joined Jun 18, 2011
42
Ok, so the hysteresis experiment with the 50k transistor did work, but only sort of.
When using a 68k ressistor (it was the one I had), switching needed suddenly a huge change in input. When upped the resistor, and finally ariving at 680k, there was a reasonable improvement, but still quite easy you could find a "in between" point. It was like the window between state1(a<b) and state2(a>b) had decreased significantly, but was still there. Also, there seemed to be some more lag right now between the switches.

Next stop, I will try a comperator.
I have in my bag-of-goodies, two of them it seems.
1. LM324N (quad op-amp), and a 2. LM301AN Op-Amp

I think I will try LM301AN first, study the datasheet, and if I get stuck there, go for the one of the comparator or opamps as proposed in the thread
 
Top