Is it possible to have a circuit light one of 2 LEDs depending on what the input voltage is, either 12V or 24V? The idea is that I have a single power connector which can use either 12V or 24V.
If this is possible is there a name for this. My online searches have come up empty so far.
weedpharma:
Is this to be an input to the Arduino? If so just use a voltage divider and analogue read.
If not then a comparator as suggested.
Weedpharma
I have thought about using a voltage divider but this would require 3 pins (one for the voltage, two for the LEDs) and ideally I wanted a solution that doesn't use the Arduino.
The voltage powers the Arduino via a step down converter and also some solenoid valves. The valves can be either 12V or 24V.
MartynC:
It looks like a comparator requires both voltages at the same time. I will not have this. The voltage will either be 12V or 24V.
No it doesn't. Set up a voltage divider for your input voltage, then a reference that corresponds to an input voltage between 12V and 24V.
Assuming your input voltage is on the + input, the output will be low if 12V is connected, high if 24V is connected.
The comparator can directly drive one LED when it's output is low, then when it goes high it can drive the base of a transistor to turn on the other LED.
If you don't mind having one LED on for 12V and two on for 24V then you can use a resistor LED and Zener diode in seriese.
You need two of these across the supply. The Zeners should have a voltage of the voltage you want to detect minus the forward voltage drop of the LED minus a volt or two.
OldSteve:
No it doesn't. Set up a voltage divider for your input voltage, then a reference that corresponds to an input voltage between 12V and 24V.
Assuming your input voltage is on the + input, the output will be low if 12V is connected, high if 24V is connected.
The comparator can directly drive one LED when it's output is low, then when it goes high it can drive the base of a transistor to turn on the other LED.
As Mike says, use 2 leds and a zener. One stage further might be to use a bi-colour LED, one leg attached permanently (colour A) indicating 12 volts. The other leg via the zener lights colour B when 24 volts is available. When 24 volts is available both LEDs will be lit so the colour displayed is actually A+B
MartynC:
It looks like a comparator requires both voltages at the same time. I will not have this. The voltage will either be 12V or 24V.
You would use a resistive divider to bring the voltage down to the 0..5V range and compare
to a fixed ratio divider running off 5V. For instance a 4:1 resistor divider brings 24V down to 4.8V and
12V to 2.4V. Compare this to 3.3V and you have your decision.
Or simply use an analog input and measure the voltage from the divider...
When the voltage is 12V, the LED on the right will illuminate. When the voltage is 24V, the LED on the left will illuminate and the transistor will switch on, more-or-less shorting out the other LED.
Grumpy_Mike:
However I would put a resistor from that base to ground to prevent any leakage current from the zener turning the transistor on.
Good point: I had wondered about that before posting. I have now checked a datasheet for a BZX55C15 (edited) zener diode and at 11V reverse voltage, the leakage should be less than 0.1μA so there shouldn't be a problem even if the transistor has high current gain (assuming not much more leakage at 12V).
When the voltage is 12V, the LED on the right will illuminate. When the voltage is 24V, the LED on the left will illuminate and the transistor will switch on, more-or-less shorting out the other LED.
However the 1k resistor will need to be at least ~1W to avoid it getting very hot. Use 10k and make
the LED a high efficiency one perhaps?
Archibald:
Good point: I had wondered about that before posting. I have now checked a datasheet for a BZX55C12 zener diode and at 11V reverse voltage, the leakage should be less than 0.1μA so there shouldn't be a problem even if the transistor has high current gain (assuming not much more leakage at 12V).
Many thanks for your help and have a question about the size of the zener diode.
Your diagram shows a 15V zener diode and you also mention the 12V BZX55C12. Is the exact voltage important and if so should it be 15V or 12V or any value somewhere between 12 and 24V
When the voltage is 12V, the LED on the right will illuminate. When the voltage is 24V, the LED on the left will illuminate and the transistor will switch on, more-or-less shorting out the other LED.
The response time difference between a 12V zener and a 15v zener is going to be in the order of mS if not less as far as when one led turns off and the other turns on. If you can tell the difference between 2 mS and 10mS I would say if might make a difference but since that's out of the question, I would think any value between 12V and 20V would be indistinguishable from 15V by the human eye.