# how to build a circuit that compares two potentials?

I want to build a circuit that compares two potentials, in principle, it works like so:

basicly, the circuit gets 3 intputs, p1, p2 and input, and has one output, output. the potential of p1 would be, p1 and the potential of p2 would be, p2. when p1 and p2 are not equal, output's potential is 0, which means, no potential. when p1 and p2 are equal, input and output are "connected" and output's potential equals to input's potential. but if p1 and p2 are suddnly not equal (after they were equal, which means that input and output are "connected") input and output will still be connected, up until input's potential turns into 0. (if its more comfortable, i wouldn't mind adding a four'th input that would "disconnect" input and output. for example whenever it has a certain potential, input and output will be "disconnected")

EDIT: Some information: input's volt is 5V. the potentials vary based on the resistance the wires go through when they connect the p1 and p2 inputs, the resistance comes from a simple photo cells.

• Perhaps you could describe the practical application you are trying to implement: There may be various ways of achieving the desired result. Jan 30, 2013 at 7:53
• When you say 'equal', what exactly do you mean: how much difference would still be considered equal? And what voltage levels are you talking about, and how much current from input to output? And how fast must things happen? Jan 30, 2013 at 8:17
• Lots of ways of skinning this particular cat, from purely analogue to any small microcontroller with 3 ADC channels. You need to define a few more details / requirements. Jan 30, 2013 at 8:52
• You might have better results considering this as two problems, and two questions: 1) comparing two potentials, 2) connecting the input and the output. Still, as Wouter van Ooijen says, you need to be more specific about how you want to compare, and what you want to connect. Jan 30, 2013 at 13:51
• There is no such thing as equal signals. -1 Mar 1, 2013 at 19:18

You need a window comparator like this:

If R1 and R3 are equal and 10 times R2 you have reference voltages around 0.48 and 0.52 times the input voltage of the divider. Then use a :2 divider to get the other input voltage at 0.5 times its value. Then if the difference between the two voltages becomes larger than about 5% the output will go low. You can use the output to drive a small relay through a transistor.

Like ThePhoton comments the comparators have to be open drain/open collector types.

• cool trick +1 for this. Mar 2, 2013 at 14:06
• Probably a good idea to point out that IC1 must be a part with open drain or open collector output; which is very common for comparators, but not universal. Mar 2, 2013 at 15:22
• Window comparator does seem to be a likely start, however my reading of the desired behavior is that it also needs state, such as some sort of flip-flop to keep it in the "connected" mode after the satisfying condition is lost, until the reset condition is met. It would be interesting if it could all be done with a quad op-amp package; though that's already at the point of complexity and carefully chosen support passives where an 8-pin (or even sot-23) micro seems tempting. Mar 17, 2013 at 19:27
• On the schematic that posted Johan.A how can be that at the same time Vout is equal Vcc (IC1A) and 0V (IC1B), when Vin=0? Jul 5, 2013 at 11:02
• @user16401: if the outputs are push-pull and the levels would be different you would have a short circuitfrom V+ via the high level transistor and output, then the low level transistor to ground. It won't oscillate, but you'll damage the outputs before the power supply dies. Aug 5, 2013 at 16:18

What you ask for can't be realized. There is no way to determine equal voltages, and in reality no two signals are really ever equal. It is possible to detect whether they are within some voltage difference, but that wouldn't be detecting "equal".

As for the overall logic, there are various possible approaches. The best way to solve this is to pop up two or three levels and explain the problem you actually want to solve. It seems you have for some reason latched onto this solution that requires this strange box, but most likely the best solution is a different approach at the high levels.

In any case, you will have to specify the voltage levels, error tolerances, and speed reuired. The simplest way to implement something like the box you asked for is with a microcontroller. However, I can't recommend that or any other implementation without knowing how fast the system must respond, what the error tolerance on "equal" really is (if you have one, if not this can't be done).

For the comparison you need two comparators. One that checks that p2 is at least a little more than p1 (as Wouter van Ooijen said, you need to allow a range around p1). The other checks that p2 is no higher than a little more than p2. Then an AND gate to see if both are true. Some TI comparators will help.

• thank you very much, but after the AND gate will return to false, the current will stop, maybe I can use a switch that can be shut on and off so when the AND gate turns true, even for a second, it will switch the switch on, and that how I can connect "input" and "output" and disconnect them without any connection to p1 and p2. so, do you know that kind of switch? that can be shut off and turned on electrecly? Jan 31, 2013 at 11:20