How to detect discrete voltage levels with a simple circuit? - Page 1
Forum section: electronics / beginners

author: SharpEars
author_rank: Unknown
timestamp: August 14, 2015, 08:04:52 pm
content: Imagine I have the following voltages available as references:0 V (i.e., Gnd)2.3 V (We'll call this VRef1)2.7 V (We'll call this VRef2)5 V (i.e., Vcc)Now I have a contact point that is either 2.3 V, 2.7 V, or NC.I want to use two LEDs to indicate the state on the contact point:NC - Both LEDs off (to show no voltage)2.3 V - (i.e., equal to VRef1) - One LED on (say a green one to show low voltage)2.7 V - (i.e., equal to VRef2) - The other LED on (say a blue one to show "high" voltage). Note that the first LED should be off for this case.What is the simplest way to build such a circuit (I have various transistors, 741 ICs handy and practically all passive parts within reason handy)?

author: Paul Moir
author_rank: Frequent Contributor
timestamp: August 14, 2015, 08:13:37 pm
content: Got an LM339 quad comparator? That's where I'd start.

author: nfmax
author_rank: Super Contributor
timestamp: August 14, 2015, 08:44:22 pm
content: The LM3914 was designed for exactly this purpose - LED dot/bar graph driver with built-in comparators & resistor string. Still available as far as I know.

author: SharpEars
author_rank: Unknown
timestamp: August 14, 2015, 09:24:24 pm
content: Quote from: nfmax on August 14, 2015, 08:44:22 pmThis looks overkill, but I will VERY SERIOUSLY consider it if no simple solution exists...

author: Richard Crowley
author_rank: Super Contributor
timestamp: August 14, 2015, 09:27:13 pm
content: You can use the 741 op-amps as comparators, and use discrete transistors, resistors and maybe diodes to do the display logic.The practical schematic is left as an exercise for the reader.

author: SharpEars
author_rank: Unknown
timestamp: August 14, 2015, 09:35:35 pm
content: Quote from: Paul Moir on August 14, 2015, 08:13:37 pmSo, maybe like the limit comparator example in the datasheet which uses two of the four comparators. Perhaps with both the low and high set to the same voltage.

author: denelec
author_rank: Regular Contributor
timestamp: August 14, 2015, 09:43:43 pm
content: The simplest would be to use a microcontroller. Most have A/D converters built-in.Almost no external parts required.If you're not familiar with microcontrollers, the 8 pin PICAXE 08M2 is very very easy to program (BASIC).

author: eetech00
author_rank: Regular Contributor
timestamp: August 14, 2015, 10:34:31 pm
content: HiLM3914 probably wouldn't work to well since its really designed for linear measurements.LM339's configured as window comparators probably would be a better choice.

author: fivefish
author_rank: Frequent Contributor
timestamp: August 14, 2015, 10:37:40 pm
content: 2 sets of window comparator for your 2 voltages.orAtmega168/328 (Arduino). Setup for Analog in, read voltage, do an if...then statement, turn on specific LED you want based on input voltage.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 14, 2015, 10:42:39 pm
content: Question:Whatvoltage rangedo you want it to work over?Because it's intrinsically impossible to state that a voltage isexactly2.3000... V, which your reference certainly isn't to begin with! It's reality's version of:Code:double num = 15.0d;if (num == 3.0d * 5.0d) {printf("equal");}Which might never execute, because in general, floating point operations are not self-consistent on the bit level (which the equality test demands), even if printing the numbers shows them to be equal (i.e., "15.000000000000000", usually rounded to just "15").In reality, there is noise when you try to zoom in very very far, normally in the microvolt to nanovolt range if you have very good devices in an electrically clean environment. A signal might be "equal", but only momentarily, and randomly.In pure mathematics, there isabsolutely no notion of equality among real numbers, unless the two numbers have been constructed in an exactly equivalent way. Using rationals (i.e., anything that can be expressed as a decimal or fraction), as the above example does, is one such example. Another is equating the infinite series for pi with the ratio of a circle's circumference to diameter: it's an equivalent definition (although why that should be equivalent is a very interesting but unrelated question).So in short, be very, very careful when you talk about equality or inequality of real numbers: this is, at its heart, a deep mathematical subject, worthy of some discussion!On a much more practical note, you should want a range anyway, because inevitably there will be voltage loss along the wires, and errors in source, path and measurement. So you definitely need a window comparator (from practical as well as theoretical grounds). If you're okay with splitting it down the middle, between the Vrefs, then technically you only need three comparators, but you need logic to resolve the two LEDs from that, so you might as well build two separate window comparators, which is handy enough anyway, because four is a standard package size (as mentioned -- a single LM339 or etc.).ADCs and bargraph displays are equivalent: these convert real numbers to integers, in effect. Necessarily, each step is a range, not an ideal voltage level. The steps are obviously wider in a 10-bar bargraph display than a 10+ bit ADC, but they still act the same -- indeed, you could call the window comparator idea a two-bit ADC. The ADC has enough steps that you'd probably have to resolve a range of them (using inequalities in the software) for practical use, and might have to combine a few states to use the bargraph route as well.The LM3914 being an ADC is interesting, as it's a unary converter: when configured for bar (versus "dot") mode, the number of active outputs corresponds to the numerical count (unary counts 1, 11, 111, ..., while binary counts 0, 1, 10, 11, ...). Which can be very useful for certain applications, if you think about it.Tim

author: Paul Moir
author_rank: Frequent Contributor
timestamp: August 14, 2015, 10:45:43 pm
content: Quote from: SharpEars on August 14, 2015, 09:35:35 pmThat's the idea, but maybe we can optimize a bit. Also we'll want to open the voltage window up a bit so it's not trying to turn off exactly when it's trying to turn on. Just roughly thinking here:You got 2.7v and 2.3v already right? Let's just use 2.3 to start. Feed to 2.3 into a divider to reduce it by roughly 10% say. 1k/10k or 10k/100k or whatever. Feed that and the "Sense" signal into a comparator1 so that when the voltage is higher than 2.1v it turns it's output low.Note that the output of an LM339 is open collector rather than totem pole, so it can't source any power, just sink power into it. So grab an LED and a current limit resistor (say 470 ohms). Hook the 470 to +5v and the other side to the LED, then the other side of the LED to comparitor_1. Now when the sense line goes higher than 2.1v, the LED turns on.Now do the same thing you did with the reference voltage with the sense line, reduce it by ~10% and feed it into comparator2, along with the original 2.3v. Rig it so it turns it's output low when the reduced sense voltage is higher than the original 2.3v.Time to cheat. Take the output of comparator2 and hook it between the LED and it's current limiting resistor. So now when comparator2 goes low it "shorts out" the LED, turning it off.Repeat this circuit for the 2.7vThere's better ways to do this, like ones that waste less power. Something to think about. Right now the BOM is something like:LM3391K*4, 10K*4, 470*2LED * 2The LM3914 is a simple and elegant solution though. And they're fun to have around anyway. Richard Crowley mentioned using the 741s you have for comparators; they have totem pole outputs which could allow a better solution than the above.

author: SharpEars
author_rank: Unknown
timestamp: August 15, 2015, 02:48:01 am
content: Quote from: Paul Moir on August 14, 2015, 10:45:43 pmI have to say, out of all of the ideas so far, yours sounds optimal parts wise and I sort of understand it, but I don't have any LM339s at the moment, but lots of 1458s (dual 741s), so I would have to revise the circuit you described for that. All in all your idea sounds really good, I just need to figure out how to implement it.You gave a pretty detailed description using the LM339, now I just have to figure out how it would work with the LM1458 chips I have.