ESP deep sleep

some news here?

updated code here: Just my battery operated ESP8266 enviro sensor node with OTA update

1 Like

hello!

i know this is an old topic, but i wouldn’t wanted to open new one, because my question is very similar:

i’m designing some kind of semi-automatic bicycle shifter for internal gearing hub.

for mcu i use d1 mini pro. among other things, it monitors the wheel and crank cadence with 2 reed relays + magnets on the wheel and crankset. the gear shifting is made with a stepper motor + driver. the whole system is powered from lithium battery, so power consumption and reduced weight is critical.

everything works fine, and after lots of bench testing now i think the system is mature enough for some road tests. but here battery life comes into play.

to save power, i would like to put the wemos into deep sleep, if no wheel or crank rotation detected in the last x minutes. as i understand, this is relatively easy, with “ESP.deepSleep(0);” command.

however, what i want, that when the bike begins to move again (receives a signal from the reed relay), the system should startup automatically.

i thought i could hook up the reed relay to the RST + GND, it would be ok to wake up the esp, but after that every time the magnet passes near the reed relay, it would reset the system… not usable.

i would like to wake up the esp from deep sleep, but then to ignore further RST activations until I programmatically send it into deep sleep again.

any ideas how i can do that?
thank you!

@Costas, maybe you had bad results beacuse of some fake 18650 cells!

these cells are the oldest lithium battery standard, and are the most widely used in all kind of applications (laptop batteries, electric cars, power banks, etc) so they are high target for fakes. look at this!

if original cell, this size can have the highest capacity / weight / volume ratio!
recently i have bought from tme.eu some (hopefully) original panasonic cells, and they seems quite good, so far.

this guy has very extensive and professional testing done with all kind of 18650 cells, it worths a look! (also, some info here)

what i know for sure, everybody should definitely avoid the ULTRAFIRE brand, any color, model, because the are 100% fake!

I’m sure mine were fakes. The 9900mAh was 1000mAh at best.

What is the mAh’s of yours and approx cost?

i have link in my post.

they behave nicely on the tests:
http://lygte-info.dk/review/batteries2012/Panasonic%20NCR18650B%203400mAh%20(Green)%20UK.html

after the research i have done in this field, i have the conclusion that the above cells are the best price (including shipping) / capacity / weight ratio. if anyone find some better, please let me know.

by the way, afaik, at the currently existing best technology and materials, it is physically impossible to go beyond 3600 mAh in the 18650 size! so anything above 3600 is very probably FAKE!

The fake ones are the cheapest for their actual mAh, approx $1 for 1mAh compared with approx $1.40/mAh for the real thing. It’s just that you need plenty of space to wire up the fake ones as they are only around 10% of their stated capacity.

i do not know, how did you calculated 1$ / mah… [quote=“Costas, post:47, topic:5622”]
approx $1 for 1mAh compared with approx $1.40/mAh
[/quote]

because than one original 3350 mah should cost 3350mah x 1.4usd = 4690 usd. that would be a little expensive, even for tesla :smile:

i have bought mines with ~6usd, that would be 6 / 3350 = 0.001791045 usd / mah

Should have been Ah not mAh, I’m having a bad day :slight_smile:

i see. but how do you know, that the fakes have at least 1000 mha capacity?
the guy in the test says thay had only around 750-600 mah…

Wanek have been studiyng a similar need for external wake up and have found a thread that solves the issue rather well electronically.

Looky here for his way of using deep sleep
http://electronut.in/esp8266-desk-draw-protector/

With proper transistors and hookup you can have the reset get triggered only when your device is in sleepmode.

If you can’t get where I’m going with this, tell me and I’ll try to explain some more.

1 Like

@wanek our tests showed 1000 to 1200 mAh for the fake 9900mAh 18650’s.

thanks, i will look into this.
also, @saurabh47 recommended this method: https://www.youtube.com/shared?ci=72kIb1SPB-U
what do you think about it? i will try later today i think.

Fun fact, some fake 18650 are filled with flour. I laughed when I saw it on YouTube.

1 Like

It’s a good solution as well! I wouldv used it in my build as well if I wasn’t using esp8266-01 with limited pins. I have some 12s that are the same size with more pins but I want to make use of the 01 when I already have them ^^

if has 1000 mah, then indeed theoretically they are cheaper. but in some applications you simply can not afford as much added volume and weight with these fake cells. (one has to use 3 x the volume and weight). in my bicycle project for example i should use 12 fakes, instead of 4 original…

and besides this, the reliability and lifetime of the fake cells is unkonwn.

link please :joy:

FF to 1:30 if you want to see the flour :sweat_smile:

1 Like

ok, if anyone interested, here is of what i came up in the end.

the task was this:

this is the whole circuit: 4 lithium cells (not shown), 12v->30v booster, stepper driver, 433mhz rx module, wemos, adjustable voltage divider aka 1Mohm trimpot :slight_smile: for battery level monitoring on A0, and other misc components.

basically, i’m minimalist, and the empty space on the pcb is not too much. so i’ve opted to use as few hardware components as possible for the standby function.

this is how it works:

when ESP.deepSleep(0); is executed, the wemos turns the D0 pin high. this officially should be wired to the RST pin, to be able to wake up the mcu.
but, because i do not need a timed wake up and according to the wemos schematic the RST pin anyway has a 100k pullup, it is not needed to wire the D0.

i have used a very common 2n2222 transistor and a ~400 ohm resistor. the transistor base via resistor is wired to D0.

the emitter is hooked up to the RST pin, and the collector to D1 (which in my case is the input pin for the reed relay, receiving a LOW signal when the magnet passes near the reed relay)

function:

  1. in void setup D0 is set to output low, so it will turn off the transistor as soon as the wemos starts, and will keep it this way until…

  2. …this code is executed:

    if (deltaRPM > STANDBY && deltaSPD > STANDBY) {
    Blynk.virtualWrite(TRIP, “STANDBY”);
    if (blynkAllowed) Blynk.run();

     ESP.deepSleep(0);
     delay(100);
    

    }

  3. the esp will turn D0 high then falls asleep. D0 turns on the transistor. the RST pin is pulled up high by the built in 100k pullup. the system is in deep sleep.

  4. when the bike begins to move and the magnet on the wheel closes the relay, GND will be connected to the transistor, so the RST pin will receive a LOW signal and will reset the board.

  5. as the board starts up, D0 will go LOW, turning off the transistor, so blocking the further resets every time the magnet passes near the relay.

the standby timer is adjustable from the blynk app.
measured current in standby: ~450 microamperes.

3 Likes

Hi there, I am quite new with ESP and microcontrollers,
I have running ESP8266-12e with DHT22 and it is working well. I am using this code

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * 
 *
 **************************************************************
 * 
 * 
 *
 * WARNING :
 * For this example you'll need SimpleTimer library:
 *   https://github.com/jfturcot/SimpleTimer
 * Visit this page for more information:
 *   http://playground.arduino.cc/Code/SimpleTimer
 *
 * 
 *   DHT22 ----gpio12
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxx";  // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "xxx", "xxx"); //insert here your SSID and password
 
  // Setup a function to be called every second
  timer.setInterval(1000L, sendUptime);
}

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(10, t); // virtual pin 
  Blynk.virtualWrite(11, h); // virtual pin 
}

void loop()
{
  Blynk.run();
  timer.run();
}

I have 2 questions here:

  1. where is the best to put ESP.deepSleep(300000000); to sleep ESP for 5 minutes?
  2. what to do if I need to stop ESP deepSleep, e.g. I need to upload new code into it etc. Is it enough just disconnect RST and GPIO16 or something else. I want to know what are the steps before I use deepSleep in the code to avoid “brick” my ESP

Many thanks for your help