Wake up device with blynk app


in one of my ongoing projects i have to build a motion sensor, operated from 18650 batteries. the motion sensor doesn’t has to be active all day, only at specific hours.

the user should be able to turn the unit on / off from his phone, and also to receive a notification when motion detected, about battery level, etc.

i thought to use an esp8266 as mcu. to minimise power consumption the unit should be in deep sleep, and when the pir sensor detects any motion it can wake up the mcu, connect to blynk server and send notification to the phone.

what i can not figure out, is how to arm / disarm the unit from the phone, while it’s in deep sleep? (it is not possible to set a fixed schedule, because the user will need to turn it on / off at random intervals.

the only option i can think of, is to wake up the esp at regular intervals (say every 2 minutes), connect to blynk server and check for button states. this could work, but not too good for the batteries…

any ideas are welcome!

1 Like

I faced the same issue for my solar powered moisture sensors in the garden.
I ended up making it check for connection every 5 min, or when the lid was opened.
Once it had connection, it would check a specific virtual pin and then disable the deepsleep function. In my case set it as a timer for 5 min to save battery.

I had deepsleep on a timer that checked the virtual pin every 30 seconds while it was connected.

thanks, @Jamin. what battery (capacity) did you used for this, and what is the average lifetime with one charge @ 5 minute checks? how long it takes to connect?

i wonder if it is possible to wake up the esp via wifi (even on local network with local server), while it’s in deep sleep?

A possible solution albeit different from the one you wish for is to use 1 ESP device as a “master”, combined with 433 Mhz receiver. Then make your motion sensing devices run of some chip like the attiny85 combined with an rf transmitter

An esp is a “waste” of power only to monitor a PIR sensor id say :stuck_out_tongue:

Attiny85 power consumption in deep sleep that i dug out

Normal 0.7mA 3.6mA
Sleep 0.2µA 0.2µA

You can have it sleeping until motion detected then it wakes up and transmitts.
Esp connected to wall outlet anywhere just waiting for signals.

then expand if you need some more. ESP wise you can simply toggle notifications on/off as your “arming” action


the idea is not bad…

but the thing is, that i’m not sure about the range of these rf modules inside a building. these units are planned to be used in a large building (hotel), several units (10-20 or even more).

i have to design a base device with motion sensor, but it has to be expandable (maybe later we will add temp / hum sensors, rfid readers, light sensor, etc). most of the units inside the building will have access to a wall 5v psu, but some should work standalone from battery. this is why i would like to design a universal unit (the pcb will have included by default a 18650 battery holder and a lithium charger unit) and if it needed, can be used from battery.

if the rf range is not big enough to cover all the building, i will have to use more esp master devices… further complicating things. but i know for sure, that the whole building and surroundings have wifi coverage, this is why i initially thought to use esp modules.

Ah then I understand your need for it to be an Wifi device, I guess you could run multiple WiFi points all reacting to the signal for redundancy, you can always use bridges and vpins to avoid every unit spamming the messages to your phone.

If I remember correctly the lower the frequency of radio signals the better penetration/range hence why 5GHz Wifi is weaker but faster than 2.4ghz. So 433mhz should be good for range provided a good antenna

I’ve ordered some attinys going to try this it out myself instead of relying on ESPN everywhere since they are power hogs in comparison :stuck_out_tongue: (for battery projects ofc)

@wanek, Just a thought. Have you looked at the different types of sleep the ESP can offer? While the power consumption wouldn’t be as low as a deepsleep, the other types of sleep may give you the features you are looking for.


thanks @Toro_Blanco, i’ve checked the docs. but unfortunately, acording to this table on page 1., in all sleep modes the wifi is turned off, so theoretically it doesn’t matter which sleep mode i choose…

Item Modem-sleep Light-sleep Deep-sleep
System clock ON OFF OFF
CPU ON Pending OFF
Substrate current 15 mA 0.4 mA ~ 20 μA

But with the CPU on, say in modem-sleep. Couldn’t you still detect the motion sensor, then have it wake-up and connect to the wifi to send the notification?

To be honest, it is a bit confusing to me so I could be way off. Just thought it may possibly be useful.

no, not this is my question.

the question is, that the user should be able to turn on / off the motion sensor (it will not work continuously). but if the whole mcu is in deep sleep, with the motion sensor turned off, how can he turn it on from his phone, with blynk app?

this is why Jamin and i thought that the only solution is to wake up periodically (every 5 minutes), and check if the user had turned on or off the motion sensor.

10-4. Probably should have read the original post a little better. Sorry about that.

no problem :wink:

maybe i can not explain very intelligibly what i wanted to do. english is not my native language. but, at least, i’m a patient person, and can explain several times :slight_smile:

I was thinking a bit about this. I’m not sure how the server to app communications work when hardware is offline, but if it is the case that you can send information to the server even if your esp is offline then you could just read a virtual pin value every time the esp wakes up by a motion.

If value is set to on alert user else just go to sleep again…

@Dmitriy can you confirm how app to server communication works when a device is offline? Is it possible to use projects if hardware is offline? Sort of queue up events that can be handled next time hardware gets online?
Haven’t really tested it myself…

  • pir wakes esp up on any motion event
  • esp syncs a virtual pin to check whether or not device is “armed”
  • if armed, alert user and go to sleep.
1 Like

Yes this does work and we have used it with deepSleep i.e. change the sleep time whilst the ESP is asleep and it collects the new sleep time when it wakes up. Not exactly what OP wants but server will take data when MCU is offline.


thanks for the info, guys!