Go Down

Topic: Turn on an LED when certain voltage has been reached? (Read 5235 times) previous topic - next topic

pantzmaster

Aug 17, 2013, 05:47 am Last Edit: Aug 17, 2013, 05:53 am by pantzmaster Reason: 1
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!

CrossRoads

Code: [Select]
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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

charredgrass

#2
Aug 17, 2013, 05:58 am Last Edit: Aug 17, 2013, 06:04 am by charredgrass Reason: 1
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 (http://en.wikipedia.org/wiki/Voltage_divider) 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 (http://en.wikipedia.org/wiki/Zener_diode) to the wire, and the cathode to arduino GND.

pantzmaster


Code: [Select]
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.


Quote
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 (http://en.wikipedia.org/wiki/Voltage_divider) 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.

charredgrass

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

pantzmaster


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!

cmiyc

Why do you need to add anything back in?  If the voltage is cut in half, just set your threshold values at half.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

pantzmaster

#7
Aug 17, 2013, 06:46 am Last Edit: Aug 17, 2013, 06:51 am by pantzmaster Reason: 1

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)

x50505

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

Things

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.

polymorph

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.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Go Up