# Turn on an LED when certain voltage has been reached?

Hey guys, still in the learning stages so bear with me.

So, as the topic asks - How can I send current to an LED only when a certain voltage elsewhere has been reached. For example, a solar panel or adapter charging a 9.6v battery, and when the battery is actually charged to 9.6v or more, light the LED. I know it will probably involve transistors, but don’t really know how to go further than that.

Thanks! Edit: Let me add that I would like to learn how to do this through methods of both using and not using an Arduino!

``````voltageLevel = analogRead(A0);
if (voltageLevel >= triggerLevel) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}
``````

Use two 5K resistors in series from solar panel output to Gnd.
The junction will be 1/2 the solarpanel output level.

I guess you could use analogRead to read the voltage, but 9.6V would be too much, so you'd probably want to use a voltage divider (Voltage divider - Wikipedia) to lower it down to something the arduino can handle.

EDIT: This is what I'd do: attach battery to arduino analog pin. Then attach the anode of a Zener diode (Zener diode - Wikipedia) to the wire, and the cathode to arduino GND.

``````voltageLevel = analogRead(A0);
``````

if (voltageLevel >= triggerLevel) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}

``````

Use two 5K resistors in series from solar panel output to Gnd.
The junction will be 1/2 the solarpanel output level.
``````

I guess you could use analogRead to read the voltage, but 9.6V would be too much, so you'd probably want to use a voltage divider (Voltage divider - Wikipedia) to lower it down to something the arduino can handle.

Ok cool, thanks guys.

When I lower the voltage so that the analog pin can handle it, would I just be able to just re-add the "lost" voltage value back inside the program? I.e if my voltage divider halves the voltage before the analog pin reads it, just doubling the value it reads in the program? Just for readabilities sake.

Yep, that would probably work, as long as your not expecting too much voltage (i.e. halving 10V will still overload the board.)

charredgrass:
Yep, that would probably work, as long as your not expecting too much voltage (i.e. halving 10V will still overload the board.)

Yeah, I'll look more into voltage dividers and probably cut it more than half to be on the safe side and just add back on whatever I lost.

Thanks for the help!

Why do you need to add anything back in? If the voltage is cut in half, just set your threshold values at half.

I could, both would work. But like I said earlier it's just for readability. Just so I can visually see the "actual" voltage of the original source. (And maybe even print out the value to an LCD)

I am also new to electronics, so test the circuit at the breadboard first.

I need voltage at pin 2 to be 9.docx (43.6 KB)

Did you want to use an Arduino for this? Because you can do the same thing with a comparator, a few resistors and a potentiometer.

If you want to use an Arduino, and it's a 12V solar panel (Although remember their open circuit voltage can reach over 20V), I'd be aiming for at least 1/4 resistive divider, and yes, you can compensate for it in code, since all you're doing is dividing the voltage so you don't blow up your Arduino, multiply your value by whatever divider you use, done.

You are going to get a digital value between 0 and 1023, so it isn't easily readable as a voltage, anyway. You'll have to use a bit of math to convert it to a voltage, anyway.

You -would- have multiplied the binary value by 5V/1023. That would give you the actual voltage on the Arduino pin. However, the resistor divider network divides it by 2, so you need to multiply by 2 to get back to the voltage going into the resistor divider network, so multiply the binary value by 10/1023. Make sure you use a floating point variable.