9

Doing some DIY as a hobby, I'm making a small humidity-temperature radio sensor.

An ATmega328 is reading from a DHT11 sensor and then transmitting data to a Raspberry Pi by an STX882 radio transmitter. It is powered by a 9 V battery using a 7805 5 V regulator with 10 µF and 100 µF capacitances.

The C code on the ATmega is reading humidity and temperature and then sending it every 30 minutes:

const unsigned long DELAY = 30*60*1000UL;    // 30 minutes
void loop() {
    delay(DELAY);
    send_data(); // Maybe a little overcomplicated, but I think it is not the point
}

This was working like a charm, but the battery life has been unexpectedly short. It was brand new, and I made some sporadic tests with a short delay, with no abnormal heat coming from anywhere.

When I was satisfied, I put the 30 minutes delay and leave it alone (which was maybe a bit hazardous?), but after less than 24 hours the battery was 5.4 V dead. The 30 minutes delay was approximately respected for its lifespan though.

What could explain such a short battery life? Could it be the 5 V regulator? How could I build a long-lasting circuit?

PS: I'm still trying to Fritzing some diagram, but this takes age for noobs like me...

I used a 6lp3146 generic brand alkaline 9 V battery which apparently provided 300-500 mAh at 100 mA current, which is far more than what my circuit use.

Here is all information I could gather from the datasheet:

+-----------------+-------------+----------+-----------+---------+
|                 | DHT11       | STX882   | ATmega328 | 7805reg |
+-----------------+-------------+----------+-----------+---------+
| Voltage         | 3-5.5 V     | 1.2-6 V  | 2.7-5.5 V |         |
+-----------------+-------------+----------+-----------+---------+
| Active current  | 0.5-2.5 mA  | 34 mA    | 1.5 mA    |         |
+-----------------+-------------+----------+-----------+---------+
| Standby current | 0.1-0.15 mA | <0.01 µA | 1 µA      | 4-8 mA* |
+-----------------+-------------+----------+-----------+---------+
*"bias current"

If I understand correctly, my system is active for a few seconds every 30 minutes, so the standby current is all that should matter, and it is indeed driven by the 7805 regulator.

So yes, in the worst case, with 300 mAh I should be able to keep the system alive for only 40 hours.

Is there a way I could feed my system 5 V for a much longer time without a much bigger size?

For the record, here is a very good video about LM regulators vs. buck converters: Buck converter vs. linear voltage regulator - practical comparison

Dan Chaltiel
  • 323
  • 2
  • 13
  • 3
    I suggest using the LowPower library or similar to put the ATmega to sleep between measurements. – calcium3000 Jun 14 '19 at 19:11
  • 2
    How short is short? – Scott Seidman Jun 14 '19 at 19:34
  • note: a standard 9V battery contains 6 AAAA cells .... those have way less capacity than AA cells – jsotola Jun 14 '19 at 19:57
  • This Tx and uC is best paired with an 18650 Li Ion cell or 3 good quality AA Alkalines. – Tony Stewart EE75 Jun 14 '19 at 20:24
  • I'm not familiar if the ATmega328 has a sleep mode and what current it draws. But for this **sleep mode** (drawing uA or less of current) you'd better feed this (or a better uP) directly from the 9V battery using a resistor and use a kind of wake up signal to turn on (the regulator or better:) the converter when measurements need to be done – Huisman Jun 14 '19 at 20:36
  • 1
    @Jasen According to this [link](http://www.hobbytronics.co.uk/datasheets/DA78L05.pdf), 78L05 has 3mA bias current, which is lower but far from being enough to correct my problem. – Dan Chaltiel Jun 15 '19 at 10:11
  • I thought it was much better than that, I should have checked. – Jasen Слава Україні Jun 15 '19 at 12:11
  • 4
    LP2950 is <140uA. MCP1703 is 2uA. "Here is all information I could gather from the datasheet:" - don't rely on datasheets, _measure_ the standby currents. – Bruce Abbott Jun 15 '19 at 12:55
  • 4
    Are you absolutely married to the 9v battery? Why? – Harper - Reinstate Monica Jun 15 '19 at 14:35
  • why are you calling them "LM regulators"? – Hearth Jun 15 '19 at 18:09
  • The ATmega328 1.5 mA active current you specify is for 3 V @ 4 MHz. You are running at 5V, and don't specify the frequency. The typical active current ranges from ~3 mA @ 4 MHz to ~9 mA @ 16 MHz (see Fig 29-1 in datasheet). Also, unless your code specifically puts the ATmega328 into power down mode, it will be in the "idle" state, not "standby". Typical idle current at 5 V is ~0.5 mA @ 4 MHz to ~1.8 mA @ 16 MHz (Fig 29-2 in datasheet). – echo Jun 15 '19 at 18:11
  • @echo this is very true, I'm going to pay more attention to this! – Dan Chaltiel Jun 16 '19 at 19:29
  • Are you sure your `delay()` function actually puts all those peripherals and the Atmega into their low power sleep modes? If that is code using `avr-libc`, I would expect to see some timer interrupt code setup to wake up the Atmega later, and then some of the `sleep_*` function to actually put the Atmega to sleep. The `avr-libc` `delay` functions are busy-wait functions. – ndim Jun 16 '19 at 00:40
  • @ndim I was sure but according to AndreKR's answer, there is a Deep Sleep mode which I have to dig into. – Dan Chaltiel Jun 16 '19 at 09:30
  • Just wanted to say you might also like the TI LM2736. – Sixtyfive Jun 16 '19 at 18:21
  • Dan If you haven't committed to a solution yet you may find my answer useful. – Russell McMahon Jul 30 '19 at 11:37
  • Aside from current consumption specs from the datasheets, don't forget to measure what your various parts _actually_ draw! It's easy to think you put something in low-power mode, when you actually haven't. – marcelm Jul 30 '19 at 13:41

10 Answers10

27

What could explain such a short battery life? Could it be the 5v regulator?

As mentioned, the 7805 has about 4mA of quiescent current. You need to find a data sheet for the battery (Eveready has nice battery datasheets, if you're using an alkaline cell). It's probably no more than 100mAh -- 100mAh / 4mA = 25 hours, so that should say something to you.

How could I build a long-lasting circuit?

The 7805 is old technology. There are better newer linear regulators out there. You should be able to easily find something that uses 10 times less quiescent current, and with digging even less than that.

To use even less power you'd use a buck converter that's specifically designed for low quiescent current -- but I gather that you're not ready to design one into a board at the component level. There may be a module out there that'll do the job, but you'll need to shop around for it. TI does have some buck converter modules, but you'll want to pay a lot of attention to their capabilities, both for maximum current delivery and quiescent current.

To use less power yet, do everything that you can to minimize the current consumption of your circuit when it is quiescent. This will require careful use of the microprocessor's sleep function, as well as managing how the board is powered (for example, if it only comes on once every 30 minutes, you may well want to turn off power to the radio and the humidity-reading portions of the circuit).

Measure the current consumption in all modes of operation, and use this to determine which modes are the worst offenders overall, then concentrate on minimizing the currents in those modes if you can.

TimWescott
  • 44,867
  • 1
  • 41
  • 104
  • My first thought too: skip to regulator, use a converter as you probably draw more than only the quiescent current. – Huisman Jun 14 '19 at 20:10
  • 2
    The thing sitting quiet for 30 minutes then taking a measurement and sending it, then going back to sleep. So the quiescent current can't be ignored. – TimWescott Jun 14 '19 at 20:13
  • 1
    The 173010578 or the 173950536 from Wuerth or TSR 1-2450 from Traco power are pin-compatible replacements and have lower quiescent current, but it's not that huge difference. – Huisman Jun 14 '19 at 20:26
  • 3
    I meant: in idle mode, the 7805 will still be loaded, so it is not only drawing its own quiescent current but also some load current in a inefficient way. – Huisman Jun 14 '19 at 20:30
  • @Huisman OK -- I see what you mean. Yes, the larger question of how to reduce overall current consumption should include reducing the sleep current of the balance of the circuit. In fact, I'm going to add that... – TimWescott Jun 14 '19 at 21:24
  • 6
    I googled about buck converters and I think I am indeed not ready for this! I think I'm going to try with a [LM2936](http://www.ti.com/lit/ds/symlink/lm2936.pdf) (15µA of quiescent current), does it seem good to you? Turning of the current of other components when idling is very interesting too, I'm going to see if it is simple enough to implement. – Dan Chaltiel Jun 14 '19 at 21:57
  • 1
    The LM2936 should do. Pay attention to the output cap recommendations. – TimWescott Jun 14 '19 at 23:01
  • 2
    @DanChaltiel You can get buck converters marketed as "linear regulator replacements" which contain all the circuitry pre-made for you, including the inductor, and are used exactly the same as you would use a linear regulator. They're not as flexible as making your own, but very handy little things to have when you're not familiar with the design process or just can't be bothered. – Hearth Jun 15 '19 at 18:11
  • 1
    An MCP1703A LDO regulator has 2μA quiescent current. I doubt there are buck converters which can beat that. Buck converters are great for large voltage drops and/or high current. – Michael Jun 16 '19 at 16:20
  • 4
    @Michael it's always good to do a quick web search before saying something definitive in these ever-changing times. The [very first hit](http://www.ti.com/lit/ds/symlink/tps62748.pdf) I got on a search for "low quiescent current buck converter" came up with one that has a 360**nA** quiescent current. And a 9V to 5V conversion via a linear regulator is, by definition, 55% efficient while this thing is 90% efficient. – TimWescott Jun 16 '19 at 18:27
  • 2
    @DanChaltiel RC (radio control) guys often buy buck converter "modules" to power their receivers. RC guys are usually not electronics of even software guys, they are kids, doctors, accountants etc. So these "modules" are plug-and-play. We call them BECs (battery elimination circuit - because it allows us to use one battery instead of two). Google for BEC or UBEC or SBEC (UBEC are supposed to be linear but some manufacturers don't know that and market switching BECs as UBEC) – slebetman Jun 17 '19 at 03:57
  • @slebetman that's not a bad suggestion, but the OP would want to check for quiescent current -- it's not an important parameter for a BEC, which means both that you can't count on it being sterling, and it'll vary from brand to brand and model to model. – TimWescott Jun 17 '19 at 21:05
  • @TimWescott Yeah. Also need to remember that switching power supplies have ideal input voltages. BECs are designed for 7V or 11 V so running them at 9V input would make them less than 95% efficient - still.. significantly more efficient than a 7805 – slebetman Jun 17 '19 at 23:10
12

All those parts can run from 3 to 5V so use a battery that doesn't need a regulator, a 16500 Li-ion cell, or a 3xAAA battery pack are about the same size as the 9V and produce voltages in that range. (or even a Li-po cell)

Without the regulator the microcontroller can shut down and the circuit will only need a few microamps.

  • 2
    Or three “D” cells and change them once a season... D cells are the sweetspot for durability vs cost... – Harper - Reinstate Monica Jun 15 '19 at 14:27
  • 1
    @Harper: or 3x NiMH rechargeable AA batteries. You only have to buy them once, and modern low-self-discharge cells are widely available. +1 this answer: a 9V is good for a smoke detector that actually wants the voltage, and the burst power capability, but bad if you need to regulate it down. – Peter Cordes Jun 15 '19 at 15:03
  • 2
    Careful using a lipo, make sure you get a protected cell or have in-circuit overdischarge protection. At least if you want to ever be able to recharge it again. Then again, if your circuit's load cuts out due to undervoltage you may be fine without it. – Hearth Jun 15 '19 at 18:12
11

The idle current of a 7805 regulator is around 4 mA so, armed with the ampere hour capacity of your battery, work out how long it will last with a continuous drain of 4 mA.

If you establish that is the problem, you will find that there are plenty of regulators having a significantly lower quiescent current.

Once the battery drops to about 7 volts you are on a slippery declining slope because the 7805 regulator requires a couple of volts headroom to regulate properly and I would estimate (a quick guess) that at round about 6.5 volts the circuit will fail.

Given what I’ve just mentioned, I estimate that only 50% of the battery’s stated capacity is usable before the circuit gives up. Bear that in mind.

Andy aka
  • 434,556
  • 28
  • 351
  • 777
10

I'm running similar sensor nodes with much better results. My setup has a few differences to yours:

  • I'm running the µc directly (no regulator) from rechargable 1S LiPo batteries (3.7 V nominal) originally sold (very cheap and with a matching USB charger) for mini-drones. The whole voltage range (4.3 V - 3.5 V) is acceptable for the µc. 1
  • I power the peripherals (the sensor and the transmitter in your case) from a port pin that I can turn on before measurement and turn off afterwards. (I'm using BME280 instead of DHT11 but the power draw shouldn't be a problem.)
  • After transmitting the measurement and switching off the peripherals, I send the µc to deep sleep. 2

1 I'm successfully using ESP8266s, although of course I would never recommend that because their documented absolute maximum Vcc is 3.6 V I think.
2 For my ESP8266 waking up from deep sleep is a reboot, so the code will start running at the top of setup(), but with your ATmega328 this isn't an issue.

AndreKR
  • 2,999
  • 3
  • 22
  • 28
  • Would you mind giving me the reference of your battery? Powering the whole sensor with a port pin is a great idea! (I'd think it would be too much current for the µc to handle). Thanks for the DeepSleep ref too, it will help a lot. – Dan Chaltiel Jun 15 '19 at 18:43
  • 1
    @DanChaltiel Just search your local shopping platform for "1S LiPo" and you should find something like [this](https://www.lazada.co.th/-i9617542-s12060979.html) (4 x 1200 mAh) or [this](https://www.lazada.co.th/-i252850850-s390212811.html) (10000 mAh). – AndreKR Jun 15 '19 at 19:28
  • @DanChaltiel The datasheets you linked say the sensor needs 2.5 mA, the transmitter 34 mA and the µc can handle 40, so no issue there. (And usually they can handle even more for short periods of time.) – AndreKR Jun 15 '19 at 19:32
  • Did you consider putting a diode or something in series with your batteries to drop a fraction of a volt? Or is the current so low that even a diode doesn't drop much? – Peter Cordes Jun 16 '19 at 03:09
  • @PeterCordes Briefly, but I decided against it to reduce complexity and because the ESP8266 is known to act up when the voltage drops when it makes a WiFi connection. – AndreKR Jun 16 '19 at 06:32
  • 2
    One thing apart from current to consider when powering peripherals (sensors etc.) with I/O pins: Make sure the peripheral is not unintentionally powered via bus interface lines etc. We had issues where an I²C sensor was still receiving current from the I²C pull-up resistors. – Michael Jun 16 '19 at 16:13
  • Re “_I didn't check for the ATmega328..._”: The ATmega doesn't reboot on wake-up. – Edgar Bonet Jun 17 '19 at 10:22
4

Very similar to "how come my solar/battery/inverter system has so little range?" > because the inverter is spun up all the time. Use different loads that work on direct battery and eliminate unnecessary voltage conversion.

You've done engineering 101, you've slapped the bits together and they work. Engineering 202 is making them work efficiently enough to be useful.


As above, junk the inverte-—I mean regulator. Select batteries that can run it straight, such as three 1.5V batteries @ 4.5 volts. (Two would not suffice as they would drop below 3V too soon; or maybe; try it!)

Also think about larger batteries - - 9Vs are stupid-small capacity, especially when throwing away 2/3 of the capacity! (The electronics needs 3V, you are taking 9V and throwing the rest away as heat). Think big - D cells are your friend if you want longevity.

Deer cameras typically have two complete banks of D-cells, you can use either or both, and can run a whole season.

Also, the ATMega's sleep current draw is very impressive, but the STX882 and the sensor, not so much. See if you can find a way to have the ATMega physically shut off power to the other devices when not needed. The cheapest, scungiest way to do this is a small relay, but a power transistor should also do the trick.


One last trick. It may not be worth doing depending on what duty cycle the system is powered up, but it's worth mentioning. In recent years CPUs went from 5V to 3.3V. Why? Because they operate on current; voltage beyond minimums doesn't aid operation and just dissipates more heat. As CPUs got more powerful, thermal issues became the limiting factor, so dropping voltage to minimums allowed cooler running and more performance on the same heat sink. The same applies to your electronics.

You are aiming to run at 5V, the high side of the allowable voltage range. My 3xAA proposal puts you at 4.5V but consider making a different battery choice that goes even lower: such as Lithium batteries or three NiCd/NiMH (3.6V). NiMH has more capacity, but NiCD has truly amazing resistance to abuse and deep discharge.

  • You are absolutely right, I'm heading to 202 and your answer is very instructive in this way. I always thought recommended voltage was 5V, being able to operate at 3V will simplify things a lot. Just a thing, how come "ATMega's sleep current draw is very impressive, but the STX882 not so much", when it is 100 times lower? – Dan Chaltiel Jun 15 '19 at 16:56
  • *In recent years CPUs went from 5V to 3.3V*. That was a few years ago now :P These days CPUs program the voltage regulators on the mobo to run at the bare minimum voltage possible for the current frequency, barely more than the band-gap. Power scales with V^2 for CMOS logic (pumping charge into capacitive gate loads). e.g. my desktop runs its i7-6700 Skylake CPU at something like 1.25V depending on turbo vs. idle clock speed. – Peter Cordes Jun 16 '19 at 03:29
  • There was a good talk at IDF2015 about Skylake power management that got into some of the tradeoffs of modern (high end desktop/laptop, not microcontroller) CPU power management. https://en.wikichip.org/w/images/8/83/Intel_Architecture%2C_Code_Name_Skylake_Deep_Dive-_A_New_Architecture_to_Manage_Power_Performance_and_Energy_Efficiency.pdf. There used to be audio to go with those slides (from an Intel architect), but that seems to have disappeared :( Maybe still worth flipping through the slides if you're curious about that sort of thing. – Peter Cordes Jun 16 '19 at 03:30
  • Anyway, since CPUs want a programmable load-varying amount of voltage, but at high current, mobos power the CPU voltage regulars from the +12V supply. Most of the current demand on a modern PC power supply is on the 12V line, with CPU and GPU having their own DC-DC converters. (Modern DRAM runs at 1.2V for DDR4, down from 1.35V for DDR3L.) So again mobos power that from a DC-DC converter located near the DRAM. Or when you said CPUs, were you just talking about microcontrollers like the one the OP is using? If so, sorry for the tangent. :P – Peter Cordes Jun 16 '19 at 03:37
3

Use step up converter instead

This is how I do similar projects. I use 3xAA which gives me 2.5V-4.8V this is within the operational range of atmega, I connect this to a step up converter with disable pin, when disabled the converter consumes near to nothing and passes the voltage through. When atmega wakes up and needs to make measurement it will turn the converter on, finds 5V on VCC, do measurements and transmit, disable converter, go back to sleep. It lasts years.

Cano64
  • 807
  • 1
  • 8
  • 15
2

According to your numbers, you're getting expected behavior, between your sensor, your microcontroller, and your regulator (8ma). If you want better, sleep the controller, switch the sensor off, and get a more suitable regulator.

Scott Seidman
  • 29,274
  • 4
  • 44
  • 109
2
  1. Measure what's the actual current drain in the idle and active states. Use an ammeter between the battery and the 7805 input. A typical new 9V battery has more than 300 mAh, and the 7805 quiescent current alone couldn't really consume it all - something's fishy! I've measured a lot of 9V batteries and they are typically 500-600 mAh. The caveat is that they are all alkaline, and if you're interested in getting the longest lifespan, of course you need to use alkaline batteries.

  2. Is there a real reason to use disposable 9V batteries in your application? Have you considered something like 3× or 4× AA?

anrieff
  • 5,199
  • 1
  • 27
  • 46
  • I genuinely thought that 9v battery would last longer. I was apparently wrong. – Dan Chaltiel Jun 15 '19 at 16:29
  • Isn't there a mistake in the sentence (alkaline twice)? "The caveat is that they are all alkaline, and if you're interested in getting the longest lifespan, of course you need to use alkaline batteries." – Dan Chaltiel Jun 15 '19 at 16:39
  • 1
    It's confusing, sorry. I meant that my measurements are alkaline only, which is the one you should use if you want the longest life. Your battery might have been zinc-carbon, which could partly explain its quick death, yet I think you should first verify what the actual consumption is. – anrieff Jun 15 '19 at 19:28
1

From the delay and loop functions looks like you are using Arduino code. The delay function is a active loop, it will not put the microcontroller to sleep! The Arduino API doesn't have support for sleep mode.

Read the ATmega328P datasheet and see page 34 for how to put the device to sleep mode.

1

IMPORTANT: If you can power down the DHT11 humidity sensor between uses you MAY be able to extend the battery life by a factor of 3 or 4.

The DHT11 has a quiescent current of 100-150 uA in sleep mode. You have to design to the worst case value.
On power up it requires 1 second "to clear its head" (note 4. page 5)
and then there is interface setup time (maybe a few 10's of ms).
It is not obvious from the data sheet whether response time is affected by being powered down, but probably not .

Depending on the time between activations the powering down of the DHT11 could reduce system quiescent current from around 200 uA to around 50 uA.
Well worth looking at.


LM2936 Regulator:

The LM2936 that you mention is a superb regulator if it meets your requirements. Low dropout, low quiescent current, range of output voltages available.

I used them long ago in a product which needed their low Iq and was very pleased with them. Hmmm - that was about 1993 - 25+ years - an oldie but a goody.

Iout max is nominally 50 mA - which meets your tabulated need.
Iq is 10 uA at 100 uA load - and less at much lower loads.
Vin is 5.5 - 40V and in fact probably closer than that to Vout. You can get 5V and 3V3 versions.

Your sleep mode load current is easily under 200 uA.
At 200 uA you'd get 100/.2 = 500 hours sleep operation per 100 mAh of battery.
So about 20 days per 100 mAh.
So say 60 days or two months with an Alkaline "9V" 300 - 500 mAH battery erring on the conservative side. Use 6 x 1.5V Alkaline AA cells (about 3000 mAh) and you should get approaching 2 years.


Direct operation from 3 x AA alkalines gives Vin from 5V initial (up to 1.65V/cell) and 3.3V at 1.1V/cell (about dead). So about as long as 6 AA Alkalines with comnstant voltage output. If you can tolerate 3.3 - 5V input 'just use 3 x Alkalines. AA for almost 2 year operation. AAA for less.

Russell McMahon
  • 147,325
  • 18
  • 210
  • 386