# Forum: µC & Digital Electronics ATmega328 + ESP-01s low power brainstorm

Rate this post
 • ▲ useful ▼ not useful
Hello

I am completely new to electronics and microcontrollers so please bear
with me while I try to explain.

My current working project controls my plant grow light depending on the
brightness (eg. sun is up/very cloudy/blinds are down).
It does so by using an AZDelivery Nano V3.0 with Atmega328 CH340
(Arduino compatible) to poll a light sensor on an analog pin.
It then compares that value to a calibrated value to decide whether the
plant light should be on or off. This then gets sent by means of serial
communication with a ESP-01s over WiFi to my RaspberryPi** which
switches a TP-Link HS100 smart switch on or off.

Although convoluted, it works fairly well but uses a lot of power as I
never put anything in sleep mode and it's constantly connected to WiFi.

Now I would like to implement some means of saving power so that I can
maybe even run this thing on a 9V battery for, I don't know, weeks at a
time?

Additionally I would like to compare the value from the light sensor not
against a single value because a cloud moving in for a few seconds would
unnecessarily switch the light quickly. I thought that maybe I instead
use an upper and lower bound and only switch when the value exceeds
either, and do nothing in the middle range. I could easily do this in
code however with the power saving I thought that maybe there is a nice
way to do this with some additional parts.

Here are some of the points I'm having trouble with as I have no
experience in electronics:

1. I've read that putting the ATmega328 in sleep disables the ADC,
enabling the ADC in sleep so that it can be used as interrupt consumes a
lot of power. Is there a way to make the lower/upper bound check in
discrete* parts (while not using a lot of power?) so that I just use one
or two digital pins which can wake up the ATmega328 for processing the
brightness change.
2. I've also read that the ESP-01s does not have the means to wake up
from deep sleep without soldering to the extremely tiny chip or by doing
a reset (RST to GND). I would maybe just trigger a reset by pulling the
RST pin of the ESP-01s to LOW through a 330 Ohm resistor and through an
ATmega328 digital pin. Does that make sense?
3. Maybe there is even a way to accomplish the whole thing without even
having to use the ATmega328***. The ESP-01s has a fairly capable
microcontroller that can be programmed and two GPIO pins, so if I was
able to do the brightness comparison in discrete* parts and then use one
or two GPIO pins of the ESP-01s I could technically read the light level
(not the exact value, just whether its below or above the lower and
upper bounds) directly on the ESP-01s and then trigger the RaspberryPi**
from there. Although that leaves the problem with the ESP-01s not being
able to wake up from deep sleep without a reset, or maybe this can be
implemented in discrete* logic too?

I hope that I have explained my issue in a comprehensible manner and
that maybe you guys could give me some pointers what could be possible
or even a completely different and more power saving approach. My main
concern is the ability to save power to be able to run the whole thing
on battery power, although the lower-upper-bound-thing would be a
necessary addition in the future anyways.

For the lulz I have added a picture of the thing that I've made so you
can point and laugh at some shitty beginners project ;) Note that right
now I am using USB to supply power as the 9V battery has already
drained.

Gachl

\* Excuse my probably misuse of the term "discrete logic" or "discrete
parts" - I don't just mean and/or gates and the likes but rather
comparators and other parts outside of the two microcontrollers that I
am currently using.

\*\* I'll probably be able to implement talking to the HS100 directly
from a microcontroller so I can even skip having to talk to the RPi
first but that should not be of concern right now. The Pi right now is
necessary as it contains a real time clock which checks whether the time
is between 8am and 8pm because the plant light should not be on outside
of these hours.

\*\*\* I suppose an even better approach would be to use a variant of
the ESP8266 that has more pins available but I already have three
ESP-01s so I'd like to stick with them now.

Rate this post
 • ▲ useful ▼ not useful
first step to save power is to reduce the chip count. Reading the sensor
can be done with an ESP8266, so you can save the arduino board
completely. Deep sleep the ESP8266
https://www.esp8266.com/wiki/doku.php?id=esp8266_power_usage
and you achieved your goal.

Rate this post
 • ▲ useful ▼ not useful
drm wrote:
> first step to save power is to reduce the chip count

Absolutely, that would be the idea described in point #3 but...

drm wrote:
> Reading the sensor can be done with an ESP8266

...can it be done using specifically the ESP-01s? It's got no A0 pin.

Although I could probably use an external ADC and hook it up to the
ESP-01s, then wake up every 30 seconds to get a reading and, if a
brightness change has occurred, connect to WiFi and trigger the Pi.

As far as I know using deep sleep throws away all variables so I
wouldn't know if the value has changed and if it would be necessary to
connect to WiFi at this point. Or is there a way to persist the last
status through deep sleep cycles?

Rate this post
 • ▲ useful ▼ not useful
Gachl wrote:
> then wake up every 30 seconds to get a reading

Uh, never mind, that won't work as the ESP-01s doesn't support waking up
by itself.

Although for specifically this purpose I could probably do the soldering
job required to do this. It's still doing a reset tho so I wouldn't know
the previous state of the light.

• $formula (LaTeX syntax)$