Power management and batteries

My imp device is supposed to control the heating remotely. I use a relay to switch 12V and not surprisingly the 9V battery lost 30% charge in less than 24 hours. That’s not great! I’m thinking about getting a power bank for charging mobiles. The one I saw is a 3Ah one. Since the relay is rated at 0.36W consumption, with 5V I get 0.072A current. Does that mean that a 3Ah (or 3000mAh) battery can provide current for about 41 hours (battery Ah/relay current)? If so, how do I calculate the consumption of the Imp? How could I improve the power efficiency of my imp? I don’t mind if the device wakes up every 10-15 minutes for only a few second if it means much less electricity consumed.

`led <- hardware.pin9;

stillOn <- false;

server.log("Device’s unique id: " + hardware.getdeviceid());

if (imp.getpowersave())
server.log(“This imp is set to power-save mode”);
server.log(“This imp has disabled power-save mode”);

function setLed(ledState) {
//server.log("Set LED: " + ledState);
if(ledState == 0) {
stillOn = true;
server.log("pin state "+led.read());
server.log("pin state "+led.read());
else {
stillOn = false;
server.log("pin state "+led.read());

function timer0(){
if(stillOn) {
led.write(1); //on

function timer1(){
if(stillOn) {
led.write(0); //off

agent.on(“led”, setLed);

Look into latching relays maybe?


Why don’t you use the 12V AC, rectify it, put a voltage regulator and power your imp/relay from it?

There’s no power outlet there I’m afraid.

Thanks Peter, excellent idea but right now I’m using a non-latching relay and I just want to figure out how much electricity it consumes.

I second Peter on latching relays, in fact I suggested it to you yesterday :wink: It does take two imp pins to drive, but its power consumption is zero except while changing state.

You did recommend it but right now I have a non-latching relay at home and I still want to figure out how much electricity does it consume while on.

If you are running the imp off 9v battery, where is the relay getting 5v from? Perhaps it isn’t yet, that is the plan. If you are dropping the voltage with a regulator, make sure you use a switching reg to keep power efficient.

When it is on, the relay looks just like a resistor, so the more voltage you drive it with the higher the current, power consumption increases as the square of the drive voltage. Start with the rated drive voltage, don’t go higher, in fact you could experiment with lover voltage drive to get reliable operation. Then measure the current and that tells you how long that battery is going to last from the battery’s rated mAh.

Excellent, thanks! I’m planning to buy a latching relay and maybe power the whole contraption with a mobile charging bank (3-12Ah) via the USB port.

Glad to hear you are moving to latching! Believe me, you will not need a tank of juice for that, it just sips. It takes power for 20msec to set (ON) and then for 20 msec to reset (OFF). Mine also works with 10 msec. Example:

`// pin 9 is relay SET output
rly_set <- hardware.pin9;

// pin 8 is relay RESET output
rly_reset <- hardware.pin8;

// function to turn on the SET output for 20 msec
function rly_on() {

// function to turn on the RESET output for 20 msec
function rly_off() {

Will I need a transistor for the set and reset pins or can I drive the relay with the imp’s outs?

Definitely a transistor for each pin, plus the resistor and diode. If you were using a MOSFET then the resistor could be left out since the gate current is zero, but a bipolar transistor needs a resistor to set a base current.

Be careful whether you get a single coil or dual coil relay, both types exist and I recommend dual coil. Dual coil means one coil to set the relay and one to reset it, easy to drive with two imp pins and two transistors. The other type has a single coil, and you give a current pulse one way to set and the other way to reset. The still needs two imp pins, but it needs four transistors in an H bridge arrangement and four clamping diodes, so is considerably trickier to drive.

And the “latching relay kit” on eBay has just the right sort of relay with the transistors and resistors and diodes on a neat pcb, and you can drive it from 3.3v or 5v.

Thank you!