Turn on D1 mini when battery reaches a certain charge

I have been experimenting on and off with a solar powered set of sensors for the garden and a Wemos D1 Mini, and I have a power problem.

Using a fully charged 18650 battery, it will run for around 2.5 days before failing, at which point the battery measures 2.86v. I added a small 0.6W solar panel and a cheap TP4056 board, which in good sunny weather can keep it going for 2-3 weeks if the battery is charged first. However when eventually it fails the battery voltage is always 2.86v. Once it fails, it never comes back.

What I suspect is happening is that just above 2.86v is enough to power up the D1 mini and indeed I sometimes see the indicator light flashing, which is the first bit of my code. However after 2 seconds it dies as the power level in the battery drops just below the threshold. The sensor reading an upload takes just under a minute before going into deep sleep for 15 minutes.

What I want to do is wait until the battery has a bit more juice, say 3v, before powering up. What is the best way to do this?

Remembering back to school and potential dividers, the circuit below should give 0.7v Vbe across the transistor when the total voltage is 3v. I'm aware that is is current that matters and a transistor is not a hard switch, which is why I have doubts about this being the best approach.

Looking through my draws of components, I do have a few mosfets, a few different types of voltage regulators and a 3.3v step-up voltage board, but I suspect I'm only going to drain the battery quicker. I'm open to suggestions.

Are you using any battery protection or battery charging circuit as 2.8v is a bit low for a LIPO battery.

Just a TP4056 board

I think my first suggestion would be to get the average power consumption down. Then the solar panel might be enough to keep the circuit going except in the darkest winter days. My weather station contains a Wemos mini and is powered by an 2,400mAh 18650 li-ion battery. It lasts 12 weeks on a charge and so I have never bothered to add a solar cell, but I imagine a good sized cell would extend that time greatly.

You said that your circuit takes around a minute to read its sensors. That seems like a very long time. My weather station has 6 sensors and they can all be read, WiFi connection established and data sent in around 5~6 seconds. So what type and number of sensors is your circuit reading? Why does it take so long? Is your Wemos in normal mode (consuming around 80mA) during that whole period? Are you making use of Modem Sleep mode (20mA) while the sensors are being read, and then only enabling WiFi for the data transmission?

The Wemos in my weather station also deep sleeps for 15 mins between readings. This is a problem because some of the sensors (wind speed, direction, rainfall) are simple mechanical sensors containing magnets and reed switches. These need to be monitored continuously, so I added an attiny85 to monitor them and send the data on request to the Wemos over a software serial line. The tiny runs at 1MHz and spends most of its time in "idle sleep mode" and consumes around 500uA.

Looking at it again, It is more like 10 second than 1 minute! The main sensor I'm experimenting with is a soil moisture sensor, which if left powered can corrode one of the pins. I use one digital out to power it up then one to take a reading, and I have found it more reliable to wait a few seconds between. With a push up to a web source too, that gets it closer to 10. I could shave a bit off by not having a blinking series of lights as it starts - though that has been very useful for debugging.

In an ideal world, I'd like to be able to run off solar for months and not have to change and charge the battery. My battery says 4000 mAh, but was a cheap unknown brand so may lie. Even if in winter, I can only get one sensor cycle every 2 days, that is still enough for my needs.

That's a lie as that's technically impossible for LiPo batteries. More likely it's 500-1000 mAh. Get a proper quality battery first, preferably one with charge protection.

You'll also have to look into sleep modes for your WeMOS. Then upon wake-up you measure Vcc, and if too low go back to sleep immediately, to try again some time later.

Do remove any on-board LEDs as well.

I'm not sure having a settling time for the soil sensor is a good idea. You will probably get a different reading after a settling time compared to taking the reading immediately, but neither reading is more accurate than the other, they are both equally representative of the soil moisture level. I think what is happening is that the soil in contact with the probes acts as a capacitor which gets charged up when the current flows, resulting in an initially higher current and so a different reading. Certainly, having a settling time means the current flows for longer and the sensor corrodes faster.

But even if the sensor reading takes 10s, plus a few more seconds for WiFi connection etc, your battery should be lasting way more than a couple of days. I would use a multimeter to measure the actual current drawn during sleep (should be less than 200uA) and while transmitting (should be around 80mA).

Poor quality batteries could certainly be part of the problem. The first 18650 batteries I purchased were sold as 9,000mAh, which I soon learned is an utterly preposterous figure. They were branded "TrustFire" or similar. Avoid batteries with brand names sounding similar to that. In fact, I built a circuit to test their capacity, using a Nano, 16x2 LCD display and an array of around 10 or 12 330R resistors in parallel as the discharge load. The TrustFire batteries proved to have around 5%, yes, 5% of their claimed capacity! I then purchased some LG branded 2,400mAh batteries. My circuit measured the capacity of those as just over 2,400mAh, so I was then confident that I had not been swindled again, and that my test circuit worked well.

Another way to spot poor quality 18650 batteries is their weight. The TrustFire batteries I purchased weighed only around 20g each. The LG batteries weighed 40~45g.

Don't worry about the led on the Wemos mini. It is not a power indicator and only blinks briefly at startup, consumes around 0.5mA. It consumes nothing during deep sleep. Removing it won't gain anything and could result in damage to the board.

The TrustFire batteries I purchased weighed only around 20g each. The LG batteries weighed 40~45g.

Was that charged or discharged. :grinning:

Following this since I have the same issue with a solar powered setup. After a complete drain it looks like the battery first needs some charge because if the the arduino setup boots the voltage sags and this is a loop where it gets stuck into.

Hope something will come out of this.

representative of the soil moisture level. I think what is happening is that the soil in contact with the probes acts as a capacitor which gets charged up when the current flows, resulting in an initially higher current and so a different reading.

That'd mean it's a huge capacitor - and there's no charge left after you switch off the power.

More likely: the current flows through an ionic watery solution (as nothing else in soil actually conducts). Those ions migrate to the probes, and this migration causes the change in apparent resistance. This is also why you should use high frequency AC (1k-1M Hz) to measure the resistance, than way this migration doesn't happen and measurements are stable over a long time. It also helps preventing corrosion.

For a soil measurement using a cheap two-pronged soil moisture sensor a half-second measurement is more than long enough. No use to bother with AC and so, the variation of dissolved minerals in the water will cause a much larger error anyway. Just disconnect he sensor (so power it through two pins that can then be set to high impedance, or use two transistors: one on either side of the sensor in the power lines - probably BJT rather than MOSFET as the body diode may still allow for ground loops).

Another way to spot poor quality 18650 batteries is their weight. The TrustFire batteries I purchased weighed only around 20g each. The LG batteries weighed 40~45g.

Price is another very good indicator.

I use pairs of short (~100mm) lengths of thick galvanized steel wire to make my probes, clamped in a larger size terminal block which holds them together and connects them to the flexible wire leading back to the circuit board. I use 10K resistor to form a voltage divider with the probe, and use an Arduino pin to source the voltage to the divider. The output pin is set to OUTPUT, HIGH, the analogRead() is performed immediately and then the pin is set back to INPUT. Works well enough and corrosion is not visible even after several years of use.

@wvmarle, your migrating ions theory sounds more convincing than my cap theory. But isn't that how electrolytic capacitors work anyway?

Good question, I actually don't know how those capacitors work.

The theory comes from my work on EC probes which show that exact problem strongly, and where it's definitely the migration of ions that is to blame.

To offer a suggestion to the OP’s question. Could you use a small super capacitor across the power lines to the D1 with a small resistor to prevent high current draw to charge the capacitor. Then the cap output supplies a MAX6326 to keep the D1 in reset until a suitable voltage level is reached.

Or maybe dispence with the super cap and just use the MAX6326?

Thanks, not come across a MAX6326, I will research further.

In answer to the other questions, the batteries are UltraFire, which is a similar name. Given the reputation of bad batteries bursting into flames, in hind sight it is not a name that fills me with confidence! I could get better batteries but that still just pushes the problem further down the road. I quite like the idea of solar charging, run forever.

The soil sensor I am using is one of the small soil moisture sensors that fill ebay, with two sharp prongs. I find these corrode quickly but the little IO board that comes with them is quite useful. As I have a couple spare now, I have found using a pair of tent pegs (which I plan to have coming out the bottom of the enclosure as mounting spikes) does a pretty good job. If I leave the D1 running on USB power inside and read every 10 seconds, I do find the first one can be a bit wayward one read in 6 where as the rest of the readings settle down into a nice steady amount.

Does anyone know if the circuit in my original post is a good idea or if there is a better way of doing that? I'm tempted to see if I can get my hands on a variable power supply and give it a go.

For that circuit, the voltage divider will help drain your batteries quite quickly... and I doubt it will work at all.

I think you should forget these ideas of firing up the Wemos when the battery has charged and focus on reducing the consumption, investing in some decent batteries and that should get you to the point of having to recharge the batteries a couple of times in the winter. Effort much better spent, in my opinion. :slight_smile:

Did you measure the current draw of your circuit as I suggested?

UltraFire batteries: I suggest you dispose of those in an environmentally safe way...

The modules that come with eBay soil sensors: how do you find them useful, exactly? I understand they contain a comparator which provides a digital output with an adjustable threshold, which could be useful in circuits that don't involve a microcontroller. But with an Arduino, you can attach the analog output from the module to an analog input so that you can see how the moisture level varies over time, as well as triggering some action when the level passes a threshold (the threshold can even be remotely set over WiFi). In this case, you are making use of a single component on the module - a resistor, probably 10K.

I just wanted to say thanks to those who contributed and advised.

With a bit of work I trimmed down the code to drastically reduce the time per sensor cycle.

The D1 mini I was using was not a genuine one, and while it seemed fine for most operations I suspect some of the cheapness was in things like the voltage controllers. I had spells where even with a full battery it would never fully power up and get stuck with a flashing blue LED on boot. I was not 100% convinced by the TP4056 board either. I replaced these with a genuine Wemos D1 mini and the battery shield (which also stacks nicely).

I have just had it running for a month without the solar panel attached. That was with a 2000mAh LiPo battery that I had bought for something else. It arrived a few days before some Samsung 18650s so I thought I'd give it a go. It is running on those now with the solar panel, so even on a windowsill in winter, I'm hoping for more than a month.

My multi-meter was not sensitive enough to measure much current draw.

I think the idea of only acting on a certain battery level is flawed because any detection circuit I found is always going to drain the battery. If I had not been using the analogue pin, I could have measured the battery level and extended the sleep cycle when low, in the hope the solar panel would have more time to recharge the battery.

Considering the issue of the battery going flat, as I'm busy trying to decide between logging on Thingsboard and Adafruit IO. Both should be able to mail me if there have been no readings in a while.

The main lesson was, saving a few quid on components and batteries resulted in a lot of time being used on a unreliable system.

Mind: the WeMOS has a voltage divider on the analog pin, so that always draws some current (not much, the resistors are 100k and 200k or so), it's still more than the bare ADC pin would have. This as the ADC8266's ADC has a range of 0-1V, and it uses an internal fixed reference rather than Vcc. This is something to keep in mind, it's one of the major differences with the ATMega processors.