Simple UPS

I'm thinking that it might be possible to build a simple UPS for arduino - one that will give maybe less than a second's warning, but plenty of time to flush your data to SD - with a capacitor for storage and an op-amp to tell you when the power is about to do down (comparing the voltage on the supply and on the cap).

Is this the kind of thing that might work? Maybe the connection to the + side needs a little voltage divider so that the amp comes on when the voltage on the cap is more than 80% of the supply voltage.

No real need for a feedback resistor to control the gain - ideally, we want either 0v on the output or the full 5v as a digital signal.

The powerbank route,

There is a percentage of celphone powerbanks that charge at 2A or more and have a 1A device port.

The issue with just sticking any powerbank on is the possibility that whatever's on the device port pulls more than the thing can charge which can be dangerous. Most powerbanks charge themselves at 1A.

I'm sure others can be more precise but that's the gist of it.

Not being discussed much is the fact that charging something that's already at 100% isn't all that great either. I've seen , in PI forums that there's a way to read how full some powerbanks are through the device usb port. Haven't done that.
If making a program that's doable on an arduino without having to write a full blown usb driver ( even then I'm sure ppl have done that ) you can add a relay that disconnects power when it's at 95% and let the powerbank discharge to 80% then charge again to 95%.

For your alarm output why not a simple 5v relay on the 5v supply line
Sometime we try and over-complicate matters
The relay will also give an output command to the micro to commence the shutdown process

Firstly you need to compare the capacitor voltage with a fixed theshold, otherwise a slow descent of
the supply voltage won't be detected at all.

Secondly you use a comparator, not an op-amp, to compare voltages and provide a logic signal. The
ATmega chip has an onboard analog comparator even, but its tied to particular pins so isn't necessarily
available.

You can also sample the voltage in your loop() function with analogRead() and make a decision there,
saving hardware (no comparator). You will need to use a fixed analogReference such as the INTERNAL
1.1V reference for that though.

jackrae:
For your alarm output why not a simple 5v relay on the 5v supply line
Sometime we try and over-complicate matters
The relay will also give an output command to the micro to commence the shutdown process

Hmm. You'd need to find a relay that shuts of at juuuust the right point. Or maybe not - all I'm really interested in is the situation where the power gets turned off.

You know what? Just stuffing that 5v on the upstream end of the diode into a digital input will do the job! When the input goes LOW, then oops - power is about to say bye bye. Maybe. It's simple enough to try.

You know - maybe the Vin and +5v pins of the arduino will do the job. Provided that Vin is regulated power, of course, coming from a USB connection. I'd assume that the onboard voltage regulator will do the work that the diode does in my circuit above.

OMG, totally bloody works.

  • connected Vin to pin 12. Vin is from the USB, so it's 5v regulated. In any case, INPUT is high impedance so it ought to be ok.
  • dropped 6 * 470uF capacitors across 5v and ground - just the electrolytics in my box 'o parts

Sketch is

void setup() {
  pinMode(12, INPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  if (digitalRead(12) == LOW) {
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13, millis() % 3000 < 100 ? HIGH : LOW);
  }
}

The sketch flashes pin 13 once per 3 seconds. When I pull out the USB cable during the 'off' cycle, pin 13 lights dimly and then fades out as the power dissappears.

You only get half a second or so of power, but it works, and it's as simple as can be. Amazing.

As I said "sometimes we overcomplicate things"

You might want to fit a charge control resistor into the capacitor bank since a "flat" capacitor is effectively a short circuit. Something around 10ohms will do