lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Device which shuts down the Raspberry Pi if Voltage is low

Mon Oct 21, 2013 9:24 am

Is there a simple (=cheap) device which can shut down the Raspberry Pi if voltage goes under a certain value?
My project uses solar energy and batteries BUT
if the batteries starts getting down after hours, then the Raspberry freezes (red light on, but nothing working) and even if the energy from the panels become sufficient, it doesn't boot.
I have to phisically disconnect it and reconnect it.
At the point it works.
Is there something that would help me doing that automatically?
Thanks!

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Device which shuts down the Raspberry Pi if Voltage is l

Mon Oct 21, 2013 10:28 am

You basically need a low voltage cut-off circuit something similar used to protect li-ion batteries from excessive discharging.
This could be salvaged from an old battery pack but it may not be possible to modify to change the cut off voltage.
If you're handy at building circuits then perhaps something like - http://web.mit.edu/3.082/www/team5/elec ... esign.html would be viable option.
The MOSFET used in this circuit is an IR510 but you may find the IRF540N is better due to lower Ron resistance, just be aware that you're switching the ground rail on/off, +vcc remains connected to the battery supply at all times.
There is another alternative this can switch off the power supply when the Pi has fully shutdown, however I have no idea if it would work under a crash situation - http://www.mosaic-industries.com/embedd ... controller

To be honest I wouldn't let the Pi run before it crashes (increased file system corruption) I think using the above switching circuit combined with a low voltage monitor circuit would be better, at least your could shutdown gracefully if the supply voltage drops too low.
If I was building a low voltage detection circuit I would use a voltage comparator running on the 3.3v supply rail, then feed the output to one of the GPIO input pins for safe 0v/3.3v TTL levels.
A looping script with a sleep command or a script called via crontab periodically could check the GPIO input pin and then shutdown the Pi if a trigger occurs.
The comparator circuit would use the 3.3v supply rail for input reference since it's regulated and the other input the +5v supply rail which has been reduced with a voltage divider (2 resistors / variable resistor) to appear just above 3.3v i.e. 3.5v.
When the +5v supply drops the output from the voltage divider would be less than 3.3v and thus trigger the comparator to go high at the GPIO input pin (binary 1) and alert the script.

Richard S.
Last edited by redhawk on Mon Oct 21, 2013 10:34 am, edited 1 time in total.

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Mon Oct 21, 2013 10:34 am

Thanks Richard.

I agree on your doubts about the Raspberry running out of power.
To avoid issues to the SD card I've put everything on a read-only filesystem. For the moment that's the best option I could think of.

As per the circuit I have to say I'm pretty ignorant in the matter and not capable at all.... anything I could buy which does the same?

Thanks

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Device which shuts down the Raspberry Pi if Voltage is l

Mon Oct 21, 2013 10:52 am

Sadly there isn't a market for circuits like these so no one is willing to mass produce them with a possibility of selling at a loss.
Basically in nutshell if you want something specific then it's pretty much DIY electronics. :)

I believe you can buy li-ion discharge protection boards on eBay or DX (deal extreme) but whether they provide the require cut-off voltage level or current supply I don't know.
If you have an old dead/bad mobile phone battery lying around or one of those li-poly batteries in the silver foil wrap then you could salvage a protection board from there.

Richard S.

User avatar
Douglas6
Posts: 4050
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Device which shuts down the Raspberry Pi if Voltage is l

Mon Oct 21, 2013 12:38 pm

I'm working on using a microcontroller to monitor voltage, drive an LED fuel gauge, and alert the Pi if it's getting low. Seems like overkill, but $8 bucks for a Trinket (an ATiny85 with a bootloader on a breakout board) is cheaper and easier for the electronically challenged (me) than a bunch of discrete components.

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Mon Oct 21, 2013 12:44 pm

Thanks Douglas,
it looks interesting.
Could you provide me more details?
Eg: where/what to purchase, how to connect, where to get and put the signals?
Thanks a lot.

User avatar
Douglas6
Posts: 4050
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 4:25 pm

I'm afraid I'm still in the conceptual phase of this project (and learning EVERYTHING as I go, like, how to use a multimeter). But the idea is simple: Connect the battery+ to an analog pin on the Trinket, connect a digital pin on the Trinket to a GPIO on the Pi through a voltage divider. Connect up the grounds. Run a program on the Trinket to monitor the battery voltage and when it dips below a threshold, raise the digital pin. The Pi will be monitoring this and initiate a controlled shutdown.

Sounds easy. We'll see, and I'll let you know, but I've got a ways to go, and life keeps distracting me from the important stuff.

Oh, you can find out about the Trinket here: http://learn.adafruit.com/introducing-trinket/

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 4:31 pm

Thanks Douglas, please let me know if you get there. I'm very interested. Only concern would be the power consumption of the Trinket....

User avatar
Douglas6
Posts: 4050
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 5:09 pm

"At 8 MHz the current draw is about 9 milliamps. That number includes the green power LED which draws about 3mA so thats 6mA for the microcontroller itself."

Not excessive, I don't think. especially if that power LED can be yanked. But I realize this may be more of a learning experience than a practical solution. I know on battery, every little bit counts.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 6:02 pm

Using a ATiny85 chip seems a bit excessive for monitoring the supply voltage but then again why not I suppose. :)
I did find an interesting device today while searching online called a micropower voltage detector MCP111/112 .
They're a basically low powered IC (around 1uA) and contain a voltage comparator circuit, they trigger a high or low output depending on the support voltage and internal threshold.
Unfortunately their threshold levels are fixed and vary by part number, however with the right component (and maybe tweaking the Vdd supply rail) you could get one working for the Pi.
The only problem I can see using this device would be the TTL levels are likely to be at the Pi's supply voltage rather than the required 3.3v, the levels would have to be converted.
Sadly I don't have much time at the moment to experiment on my Pi but it would be interesting to know if anyone had much joy using the MCP111/112 as a low voltage indicator for the Pi.

Richard S.

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 6:34 pm

Well, to be honest, in my project I don't need a big accuracy... as long as the Pi can be shut down COMPLETELY at a certain point in time I should be fine.

The scenario would be: normally combination of batteries and solar light will power the Raspberry. In case there is bad weather for many days maybe the batteries will not be enough and they will give a lower tension (scaling down ideally to zero?).

At a certain point the Pi will be not powered but ... once the solar Power is enough to start it again it will go up....

Very theorical of course :?

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 7:25 pm

So if I'm to understand this correctly the Pi is connected to the battery supply / solar charger at all times and runs down the power until it shuts down or crashes.
If that's the case the Pi is never going to turn itself back on if a shutdown is requested unless the power been turned off and on.
Furthermore if the batteries are charged with sufficient voltage and you use this voltage level to trigger the Pi to start the batteries wouldn't be fully charged and discharge very quickly.

Now I'm not sure what kind of data you're collecting but I would personally run the Pi on a timer switch: i.e.
a)
-A timer circuit is used (or modified) and set to a period of 1 hour or any time of your choosing.
-When the alarm is triggered this sends a signal to a MOSET based switch and the Pi is turned on.
-The Pi boots up the operating system, checks to see if there is sufficient battery power and shutdown if supply voltage is too low.
-If batteries are super good, data is then collected, transmitted or stored, the Pi then goes into shutdown mode.
-When the Pi has reached the end of shutdown mode the MOSFET switch kills the power completely and the batteries go back to being charged again.
- back to a)

Richard S.

User avatar
Douglas6
Posts: 4050
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Device which shuts down the Raspberry Pi if Voltage is l

Tue Oct 22, 2013 7:36 pm

redhawk wrote:Using a ATiny85 chip seems a bit excessive for monitoring the supply voltage but then again why not I suppose. :)
I agree. :) Full disclosure; I'm a programmer, not an electronics guy, so setting a threshold by typing in a number comes much more naturally to me than "tweaking the Vdd supply rail" :) . But the approach has SOME merit, I think. The microcontroller can do other useful things like driving a fuel gauge. Delays and on/off thresholds can be set programatically. Potentially it can reset the Pi via the P6 pins if needed(?). All of which could be done electronically, I'm sure, but I wouldn't have a clue.
That said, I'm also interested in hearing about other approaches. The MCP11x sounds promising.

User avatar
mikronauts
Posts: 2621
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Device which shuts down the Raspberry Pi if Voltage is l

Thu Oct 24, 2013 3:05 am

Instead of monitoring the Pi's 5V or 3V3 rail, I'd monitor the raw battery voltage (divided down to something an analog input on an ADC or microcontroller can read) and write a daemon to do a shutdown when the battery voltage drops too low.
lupa wrote:Well, to be honest, in my project I don't need a big accuracy... as long as the Pi can be shut down COMPLETELY at a certain point in time I should be fine.

The scenario would be: normally combination of batteries and solar light will power the Raspberry. In case there is bad weather for many days maybe the batteries will not be enough and they will give a lower tension (scaling down ideally to zero?).

At a certain point the Pi will be not powered but ... once the solar Power is enough to start it again it will go up....

Very theorical of course :?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Fri Oct 25, 2013 4:22 pm

Something similar to this?

Controlled shutdown duration test of Pi model A with 2 cell lipo
http://raspi.tv/2013/controlled-shutdow ... -cell-lipo

It seems not too complex....

User avatar
mikronauts
Posts: 2621
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Device which shuts down the Raspberry Pi if Voltage is l

Fri Oct 25, 2013 4:36 pm

Exactly like that!

I tend to use MCP3008 ADC's where I don't need more than 10 bits of resolution, and the MCP3208 where I do instead of the two or four input versions - more inputs never hurt :)
lupa wrote:Something similar to this?

Controlled shutdown duration test of Pi model A with 2 cell lipo
http://raspi.tv/2013/controlled-shutdow ... -cell-lipo

It seems not too complex....
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
Douglas6
Posts: 4050
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Device which shuts down the Raspberry Pi if Voltage is l

Fri Oct 25, 2013 5:29 pm

That should work to shut down the Pi gracefully. But I think your problem is restarting the Pi. When the Pi is shutdown, it doesn't power off (red light stays on, but the OS is not running) unless power is lost completely. So you still need 'somebody' else to wake it up at the appropriate time (when the battery has charged sufficiently). Right now that's you, unplugging and plugging. Or, and this is a question for the EE guys here, you need a circuit to detect the drop in current load from the PI, or easier, a GPIO output, and switch off (and sometime later, on) power completely, to effect a reboot. Sounds like a job for a MOSFET (or a relay, but they're no fun), but I'm over my head here. Still, component count is starting to rise. (Just realized, that's basically what redhawk described above.)

OR, (my plan) a microcontroller to pulse the Pi's reset pin to wake it up (I know, circuit could do that too)

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Device which shuts down the Raspberry Pi if Voltage is l

Fri Oct 25, 2013 5:59 pm

If you know how long the batteries take to charge (which could be difficult with solar panels) then you could have a one shot astable multivibrator or a 555 timer circuit to ensure the Pi doesn't turn back on until a specific duration has passed i.e. 4 hours.
As for the MCP111 and MCP121 I had another look at the datasheet and it would appear their output requires a pull up resistor.
This actually makes interfacing the GPIO even easier since I could simply use the pull up resistor on the 3.3v supply rail and not worry about frying the input pins.
In a nut shell you need 1 MCP chip, 1 resistor and maybe a schottky or silicon diode in series with the Vdd supply to adjust the voltage detection.
I have some on order from eBay to test out next week so I'll keep you posted on their effectiveness. :)

Richard S.

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Fri Oct 25, 2013 6:13 pm

@Douglas6
You are right! I need something to wake it up.. but even more than that the problem is again what happen if I find again a situation of partial voltage before the raspberry is totally on. To be failsafe I Probably need something not driven by the raspberry itself.
@redhawk
I'd really love to see if can make any progress!
:)

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is l

Sat Oct 26, 2013 11:30 am

What about a zener diod?

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Device which shuts down the Raspberry Pi if Voltage is l

Sun Nov 17, 2013 5:19 pm

Right I had some time to mess around with the MCP devices today, so far so good they've working pretty much as I expected.
When the detected voltage goes above the set threshold the output of the MCP is high (open circuit) when this drops below the threshold the output pin goes to ground.
Since the part I'm using has no internal pull up resistor (some MCPs do) I can connect it directly to the 5v supply rail and interface the GPIO input without damaging it.
Despite the MCP having fixed internal voltage detection you can change the trigger levels by messing around with the Vdd supply rail as already mentioned earlier.

In a nutshell I believe the MCP is a viable low current device for detecting low battery or pending failure from a 5v regulated power source. :)

Richard S.

User avatar
Douglas6
Posts: 4050
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Device which shuts down the Raspberry Pi if Voltage is l

Sun Nov 17, 2013 6:28 pm

Following with interest. I've perused the MCP111 datasheet, but again I'm not an electronics guy and have a lot to learn and any help is appreciated. Care to sketch out a simple schematic of your prototype? By 'messing around with the Vdd rail' do you mean a voltage divider between the Pi's 5 volt supply and the MCP111 Vdd? And finally, any suggestions on learning more about 'open-drain' circuits, which I've researched but so far am not quite 'getting'.

My own efforts have stalled when I determined that my power supply (a single 1200mAh lipo cell and a 600mA max boost converter) will not reliably power my model B. I've got a model A on order, and in the interim I hacked together a power meter with a Uno, an INA219, and a couple 7-segment displays.

UDude
Posts: 1
Joined: Mon Sep 25, 2017 2:50 am

Re: Device which shuts down the Raspberry Pi if Voltage is low

Mon Sep 25, 2017 3:12 am

This is a very old thread. Nonetheless, if anyone just wants to shut down their pi when the voltage is too low, then use one of the adc gpios, just remember to place a large resister inline or you'll fry you mcu. Works with my odroid pi clone just fine. A simple cron job scheduling the gpio test with a shutdown command and you're all set.

lupa
Posts: 19
Joined: Wed Feb 20, 2013 11:57 am

Re: Device which shuts down the Raspberry Pi if Voltage is low

Wed Sep 27, 2017 2:10 pm

Hi, yes still interested.
If you could post more details, schemas and code it would be great :-)
Thanks
Luigi

Return to “Recommended peripherals”

Who is online

Users browsing this forum: No registered users and 4 guests