Power consumption of the leonardo

Nick wrote this very interesting article on power consumption for the uno Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors
Is there something similar for the Leonardo?
I'm asking because Nick goes to the barebones arduino quickly because of the huge energy savings caused by

Voltage regulators (for +5V and +3.3V)
A USB interface chip (for the USB port)
A "power" LED

The power led and the voltage regulators are still there but the USB interface is gone. As the leonardo runs another chip the measurements, code and conclusions may be wrong.
Anyone has some experience/understanding on this subject?
Best Regards
Jantje

bump

The numbers are going to be very similar for the Leonardo. If you are really curious, you can buy a teensy board which is the same thing as the Leonardo. With a regulator and an LED you will still have current in the mA though. It is not really worth calculating until you remove all the high power peripherals like Gammon did when he used just the bare chip.

Well if you supply the 5v from usb and don't draw anything on the regulators, all you'll have is the quiescent draw which isn't much, definetly more than a barebons avr but not too bad, the led shouldn't draw much sometting like 5ma,
if your worried about power consumption then you'll probably need a barebones avr anyway as a part of that project,
Are you asking how to do similiar things to the avr to drop the draw? Running it at a lower voltage and slower clock could help that, plus disabling un needed parts of the chip, for that you will have to dive into the datasheet and find out if tthe old code is compatible ( probably need some conversion but shouldn't be hard)

winner10920:
if your worried about power consumption then you'll probably need a barebones avr anyway as a part of that project,

Power consumption is a concern because i want to run as long as possible. I'm running from a12 volt 7Ah battery so a small saving takes me a long way 8).
The problem I see with the barebones is that I expect that the end user will have to update the sketch because it is experimental. So a USB connection is needed. As far as I understand a barebones does not offer this.
I have a leonardo here and the Duemilanove. I just don't like the leonardo's com port swapping. Therefore I'm using the Duemilanove for now. I'm considering swapping to the leonardo when things stabalize. I was hoping to get some input on power-saving on the leonardo as I would expect it to use less power as there is no USB external chip and it is newer.

Best regards
Jantje

I believe it has been done (usb to avr) with something called vusb but that seems hard, atleast to me anyway
But why not give the end user an "update" cord which would be the usb to serial conversion
Or have a usb to serial ic and have it in a low power state or switch off its power when on battery

winner
Thanks for the great ideas. I'm responding quite extensive to give you some feedback on the environment/situation I'm currently in.
Some background on my project:
My project is an automated chicken door closer (dark-> door closed; light -> door open with delay) to save the chickens from the fox.
The chicken run is relatively far away from the house and due to a lawnbot and lots of investment in the garden a power cable is not an option (yet?)
I have considered using sun power but I have little to no experience with sunpower so that might be an add on when the battery charging turns out to be to hard and power consumption low.

Practically the project is urgent. I promised already more than 6 months ago -to my sister- that I would build one and the fox came to visit again last month :~.

The current status of the project is that I have finished the hardware and I'm running tests. I'm using a Duemilanove and a adafruit motorshield to drive the motor. I need to add some electronics for the battery sensing, light sensitivity and delay before opening the door when it is light. Basically I'm looking for a good spot to add 3 pot meters.
I bought a leonardo for this project but I started off with the uno because of the Com port behavior of the leonardo.
Because it is nearly impossible to open the door when the motor is not powered (due to the mechanical construction) I can easily shut down the arduino for minutes when waiting for the sun to (dis)appear, then read the sun light and if no change shut down for minutes. Therefor Nick's article is very valid for me.
However Nick's main advice is to use a barebones. I have never build a barebones and I don't have the components and I'm not a electronics guy and I have little time.
Given Nicks remark on the USB power consumption I was wondering if somebody else had done a similar test on Leonardo.
Mostly because my calculations for a 7AH for the battery with a 80% duty cycle and 90% switching regulator with 46.6mA power consumption (from nicks uno feeding on +5pin) leads me to 10 days operational time. Taking away 10mA for the USB brings me to 13 days. A small extra saving would bring me over 14 days witch is the "standard holiday trip time in Belgium".

I'll do some measurements with Duemilanove and with leonardo when it all runs fine.

As to your ideas:

winner10920:
I believe it has been done (usb to avr) with something called vusb but that seems hard, atleast to me anyway

I'm sorry but I really do not understand this.

winner10920:
But why not give the end user an "update" cord which would be the usb to serial conversion

Sounds great. However I understand this as "starting from a barebones" and "adding development time". I'll consider this in future projects. Thanks for the great idea.

winner10920:
Or have a usb to serial ic and have it in a low power state or switch off its power when on battery

I understand this as the "update cord" on the board and only power it when needed. Again this sounds great but needs a barebones and development time.

Best regards
Jantje

It turns out the adafruit motorshield can not run with the leonardo.
It seems I'm down to barebones.
Best regards
Jantje

@Jantje,
You are running off a 7Ah battery.
So, if you play this right using a self-made breadboard Arduino or a stripboard Arduino (which should take an hour at most), and choose the minimal number of correct components, you can get the circuit working for thousands of hours (especially if you use sleep mode judiciously). But that is excluding the power draw from the motor shields and peripherals you have of course. Also, for the self-made circuit, you can simplify things by even completely leaving out the FT232/USB-interface-chip; you can just put a male six-pin header, and use an FTDI cable when you need to upload code from the computer.

Or if you want to use the official Arduino board, from my understanding (looking at the schematic), the FT232/Atmega16U2 won't even be powered when there is no USB connected, so you should have minimal/zero power consumption by it. The voltage regulator's current draw - yes, this is a problem, but you can either mess around by replacing it with a different regulator, or find some way (as Nick suggested) of directly powering the microcontroller/main-circuit with batteries.

By the way, what is the full list of additional peripherals/components/shields you are using outside of the main Arduino circuit? I am curious how much they contribute to the power draw, and if that needs to be looked into first.

You will most likely need a barebones Arduino such as the RBBB or Arduino mini or some other variant without a regulator and use sleep mode and change fuse settings to lower the clock speed. You could just use a breadboard too since the application is not that complicated. All you have to do is move your current consumption down in to 100uA or less.

At 20mA average current consumption you battery will last (7000 mAh)/(20 mA)/(24 h/day) = 14.6 days
At 100uA average current consumption you battery will last (7000 mAh)/(0.1 mA)/(24 h/day)/(365 days/year) = 8 years.

After 100uA it is not really worth optimizing much since your battery is so big that it probably self-discharges faster than you'll use it.

Hi
Thanks for the feedback.
I've done some more measurements. All measurements are running directly from a 12 volt battery (no switching regulator, using Arduino regulator) All test are running the same Arduino program.
The external devices used in my setup are:

  • IR sensor
  • Adafruit Motor shield running 6V motor (PWM'ed)
  • Light sensitive resistor with 1K in series
  • 3 leds with 330 ohm resistors in series (not yet turned on by the software)
  • Added after last measurement Open delay regulator (10 K pot meter)
  • Added after last measurement light sensetivity regulator (10 K pot meter)
  • planned 1 battery voltage measurement
  • planned adding switching regulator for Arduino.

measurements done:
1: all ports put on output and low 152mA :fearful:
2: added delay of 100 millis in loop 152mA (same result)
3: With leonardo (no support for leonardo for adafruit motorshield)
4: With mega 130 mA; 22 mA saved(note not all ports are put on output (till A5) and low and the device didn't work)
5: Duemilenova only without anything: 25 mA; or 127 mA is used by the devices
6: duemilenova with adafruit motorshield without anything 115 mA; so adafruit takes 90mA
7: duemilenova with adafruit 1 L293D H-bridge removed without anything 71 mA (That is about half the adafruit power gone)
8: duemilenova with adafruit 1 L293D H-bridge removed with other components 97 mA (This points out the IR sensor uses 30mA)
9: duemilenova with adafruit 1 L293D H-bridge removed with other components without IR sensor 70 mA (confirms the IR sensor is using to much power)
=> IR sensor activated by pin (I only need to measure when I open or close the door which is during 1 minute a day) I also put the light sensitive resistor and delay sensor to this pin.
to be done : duemilenova with adafruit 1 L293D H-bridge removed with other components IR sensor on pin ?? mA

From my understanding I have 25mA from arduino left and 45 mA from the motorshield. I considered switching the motorshield on and off with a transistor but as I'll have to go for a barebones anyway I'll probably use a transistor to turn on the engine and a relay to change the direction. That should take away most of the 45 mA.

Going to barebones should make me run in 99% of the time at <1 mA. The power consumption of the motors averages at 1,2mA.
In total that gives me 2.2mA + the leds (I'll make them blink).

Is there somewhere a good component list for a "low power consuming barebone"?

orangeLearner:
At 20mA average current consumption you battery will last (7000 mAh)/(20 mA)/(24 h/day) = 14.6 days
At 100uA average current consumption you battery will last (7000 mAh)/(0.1 mA)/(24 h/day)/(365 days/year) = 8 years.

As far as I understand it depends on whether the 20mA is at 5 volt or at 12 volt. As the arduino regulator burns the "to much voltage" 20mA consumption by arduino will be 20mA for any power supply. Using a switching regulator the formula needs to include a voltage conversion. Assuming a 90% return on investment for the voltage regulator going from 12 to 5 volt and a 80% discharge rate for the battery. I would say:
At 20mA average current consumption the battery will last (7000 mAh * 0.8) *(12/5) /(20 mA /0.9)/(24 h/day) = 25.2 days
At 5mA average current consumption the battery will last (7000 mAh * 0.8) *(12/5) /(5 mA /0.9)/(24 h/day) = 100.8 days
The batteries instructions advice a recharge of the battery every 3 months. So anything below 5mA seems good to me.

orangeLearner:
You will most likely need a barebones Arduino such as the RBBB or Arduino mini or some other variant without a regulator and use sleep mode and change fuse settings to lower the clock speed.

Note that using the slower clock doesn't really help in sleep mode, because the clock is stopped anyway.

Nicks article stated that changing the clock speed has no impact when you are mostly asleep. I prefer not to play with the clockspeed because it scares me 8) Did I understand this right or are it different things?

Best regards
Jantje

Jantje, I think two points are relevant in your case:

  1. Clearly, the Atmega chip is NOT the most power-consuming part, so working on optimizing it (or its clock) won't be as important as optimizing the rest of the circuit. In particular, you said at one point that the motorshield takes 90mA and at another that it averages only 1.2 mA. Which is it?

  2. What exactly are you using the motorshield for? It would help if you clarify exactly what its role is (I've read your earlier post but still not clear), because perhaps if it's only a one-time/occasional action on the motorshield, then it is possible to apply this type of power optimization, which obviously is the most ideal implementation for a device (and which you suggested yourself halfway through your post):
    Atmega wakes up, Sends out X signal on I/O pins, XYZ part receives signal and does its job, then the WHOLE circuit goes to sleep (i.e., including powering-off/sleep of XYZ part).
    Here XYZ part, e.g., could be your sensors and your motors.

By the way, what exactly do you mean when you say the Leonardo is not supported with the Motorshield? Hardware wise, or software? If the former, I would be surprised, unless it has something to do with the geometric pin layout of the shield. If the latter, perhaps we can fix it by looking at the code.

Giantsfan3

giantsfan3:

  1. Clearly, the Atmega chip is NOT the most power-consuming part, so working on optimizing it (or its clock) won't be as important as optimizing the rest of the circuit. In particular, you said at one point that the motorshield takes 90mA and at another that it averages only 1.2 mA. Which is it?

it is 90mA for the shield and 1,2mA averaged out for power consumption for the motor.
I agree the ATmega is not the most power consuming (the motorshield is) but the ATMega will have to be tackled because I am targeting 5mA and absolutely want to go below 20mA for the whole solution.

giantsfan3:
2) What exactly are you using the motorshield for? It would help if you clarify exactly what its role is (I've read your earlier post but still not clear), because perhaps if it's only a one-time/occasional action on the motorshield, then it is possible to apply this type of power optimization, which obviously is the most ideal implementation for a device (and which you suggested yourself halfway through your post):
Atmega wakes up, Sends out X signal on I/O pins, XYZ part receives signal and does its job, then the WHOLE circuit goes to sleep (i.e., including powering-off/sleep of XYZ part).
Here XYZ part, e.g., could be your sensors and your motors.

I'm using the motorshield to control a motor that is connected to a spindel which is connected to the a door. Running the motor in one direction opens the door. running in the other direction closes the door. Here is a picture of a similar solution

giantsfan3:
By the way, what exactly do you mean when you say the Leonardo is not supported with the Motorshield? Hardware wise, or software? If the former, I would be surprised, unless it has something to do with the geometric pin layout of the shield. If the latter, perhaps we can fix it by looking at the code.

here is a link to the adafruit forum where adafruit accepts the software incompatibility and does not provide an outlook for a compatible version. http://forums.adafruit.com/viewtopic.php?f=31&t=31333

Best regards
Jantje

In that case, if you run your design and code like the following, I think you should have no problem reaching well below your desired average 5 mA current draw:

  1. SLEEP
  2. WAKEUP once every X seconds/minutes/hours
  3. TAKE sensor measurements (sensor = light, etc., whatever you want)
    4a) If sensor measurements within desired range, go back to SLEEP
    4b) Else If sensor measurements above/below certain threshold, then POWER-ON motor/servo, then send CONTROL signal to motor/servo, thus OPEN/CLOSE door, then POWER-OFF motor/servo, then go back to SLEEP
  4. => LOOP

This way, the Atmega and Sensors have a very small duty cycle (depending on how often you set the period of waking up and monitoring), and the Motor/Servo have an even less frequent time of operation. So overall your power savings should satisfy your target

On your board, to allow programmability, you could even include an FTDI 6-pin header or an FT232 chip (which by default will be powered only when USB connected, so that won't be a problem), or you could just use ISP.

What I plan to do (but due to an interrupt it'll be for september) is
use barebones arduino, use transistor and relay to power motor.

I've coded it like a state machine. the loop coding looks like
if opening or closing door do whatever needs to be done
else

  1. SLEEP for 5 minutes
  2. power on the sensors
  3. wait for the sensors to be operational
  4. TAKE sensor measurements (light,light sensitivity, battery charge, opening delay)
  5. remove power from the sensors
  6. power on leds
  7. SLEEP 10 seconds
  8. remove power from leds
  9. Change state if needed

Note I'm powering on the leds after I have read the sensors to avoid impact of the led's on the light sensors.

Best regards
Jantje

http://provideyourown.com/2011/cheap-alternative-for-hard-to-find-cds-light-sensor/

The above gives a use of an LED to sense ambient light . It might save you some parts power or a bit of led switching. You can use one of your existing leds . The program switches it off for a few milliseconds while testing for light if you want or you can use a separate one reversed.

Put the first piece of code above setup()
Put the second bit of code in the loop()

It gets a little bit confusing so heres my code but a different application and I have some serial stuff atm so I can see whats happening

In my case
I have a reversed led on digital pin 2 with no resistor which is used to read light only (white wire)(was on 12 in photo)
I have an led on digital pin 6 with 330 resistor always on but brightens if 5 on
I have an led on digital pin 5 with 330 resistor indicates load is on
My switch state sensor is either on or off on pin A0 (yellow wire)
If there is no light and the sensor is on then pin 5 will come on and pin 6 will brighten
led2 is not connected atm but with led and 330 will indicate when dark or light

class AmbientLightSensor {
public:
  AmbientLightSensor(int ledPin) : mLedPin(ledPin), mMeasureAnalog(false) {}
 
  void setAnalogMeasurement(int thresholdLevel); // measure from an analog pin
  void setDigitalMeasurement(); // measure from a digital pin (default)
 
  int measure();
 
protected:
  int mLedPin;
  bool mMeasureAnalog;
  int mAnalogThresholdLevel; // (0 to 1023)
 
  void charge();
  void discharge();
 
  int measureUsingAnalogPin();
  int measureUsingDigitalPin();
};
 
void AmbientLightSensor::setAnalogMeasurement(int thresholdLevel)
{
  mAnalogThresholdLevel = thresholdLevel;
  mMeasureAnalog = true;
}
 
void AmbientLightSensor::setDigitalMeasurement()
{
  mMeasureAnalog = false;
}
 
void AmbientLightSensor::charge() {
  // Apply reverse voltage, charge up the pin and led capacitance
  pinMode(mLedPin, OUTPUT);
  digitalWrite(mLedPin, HIGH);
}
 
void AmbientLightSensor::discharge() {
  // Isolate the diode
  pinMode(mLedPin, INPUT);
  digitalWrite(mLedPin, LOW); // turn off internal pull-up resistor, see http://arduino.cc/en/Tutorial/DigitalPins
}
 
int AmbientLightSensor::measure() {
  charge();
  delay(1); // charge it up
  discharge();
  return (mMeasureAnalog)? measureUsingAnalogPin() : measureUsingDigitalPin();
}
 
int AmbientLightSensor::measureUsingDigitalPin() {
  long startTime = millis();
  // Time how long it takes the diode to bleed back down to a logic zero
  while ((millis() - startTime) < 2000) { // max time we allow is 2000 ms
    if ( digitalRead(mLedPin)==0) break;
  }
  return millis() - startTime;
}
 
int AmbientLightSensor::measureUsingAnalogPin() {
  long startTime = millis();
  // Time how long it takes the diode to bleed back down to a logic zero
  while ((millis() - startTime) < 2000) { // max time we allow is 2000 ms
    if ( analogRead(mLedPin) < mAnalogThresholdLevel) break;
  }
  return millis() - startTime;
}





// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  AmbientLightSensor led(2); // LED to read light level is hooked up to digital pin 2
  int led2;// led to indicate light or dark put one on here if you want an indicator
  int ledVal = led.measure();
  
  if (ledVal >10) {// a decent level of darkness
    digitalWrite(led2, HIGH);}
  else{
    digitalWrite(led2, LOW);}
 
  delay(200); // check every 0.2 secs

  // read the input on analog pin 0:
  int sensorValue = analogRead(A5);
  // print out the value you read:
  Serial.println(sensorValue);
  Serial.println(ledVal);
  
  
  
  analogWrite(6 ,( map(5,0,150,0,1023)));//( map(5,0,200,0,1023))
  delay(500);        // delay in between reads for stability
  if (sensorValue <400 && ledVal <10){
    analogWrite(5 , HIGH);
    analogWrite(6 ,( map(A5,0,150,0,1023)));
    delay(3000);
   analogWrite(5 , LOW); 
  } 

}

PA220003S.JPG