0
\$\begingroup\$

I want to wake ESP8266 when the light turns on, send information to the server, go to deep-sleep for a few seconds and then send the information again and keep doing that. If the server stops receiving the information, it would mean that the light is tuned off back again.

This is my schematic: enter image description here

Will it work?

I'm asking specifically about the part where I connect my photoresistor to the RESET pin.

Additional question (optionally to answer): If I'd like to swap resistor with potentiometer, how should I connect it?

\$\endgroup\$
  • \$\begingroup\$ What kind of photoresistor is it? What it looks like you've made here is just a voltage divider. If the resistor is extremely high resistance when dark and low when light, it may work depending on the resistances. I'm guessing the resistor is not an open circuit when dark, it really depends on the resistance and what voltage gets applied to the reset pin. \$\endgroup\$ – Ron Beyer Jan 15 '17 at 19:24
  • \$\begingroup\$ Perhaps swapping R6 resistor with potentiometer would solve the problem? I could just adjust the resistance experimentally. \$\endgroup\$ – Defozo Jan 15 '17 at 21:13
2
\$\begingroup\$

I'd recommend not doing that. Photoresistors are slow devices, and you might be oscillating around the point where a reset is triggered, so this might not work that great.

I'd instead recommend using something that has a clear threshold and issues a single reset impulse instead of a constant high, so this doesn't happen. In any case, RESET should be driven with a binary signal, and not something like "well, I was 0.1 V below threshold, I'm 0.05 V above, so better reset".

Anyway, I don't know the ESP8266 very well, but are you sure you want to reset the device? That's like switching your PC on and off with the power switch, just to wake it up. Maybe the ESP8266 has a pin that can be used as interrupt instead and a sleep mode to wake up from, and your would prefer that.

Your idea seems to be that you hold the ESP8266 in reset mode while it's dark – I'm not even sure that is in any way power-efficient.

\$\endgroup\$
  • \$\begingroup\$ Yes, my idea was to hold the ESP8266 in reset mode while it's dark. In general, the idea is to get information about the state of the light in the bathroom (generally there's either perfectly dark or totally bright - it will be mounted with really close distance to the light) - so I was wondering about different approaches and this seemed minimalistic and yet power-efficient. AFAIK ESP8266 has power mode which enables ESP to be waken up using interrupt from a pin but this mode needs about 0.5 mA while deep-sleep needs only a few µA. How about using phototransistor instead? \$\endgroup\$ – Defozo Jan 15 '17 at 21:10
  • \$\begingroup\$ What can wake it from deep-sleep? \$\endgroup\$ – Marcus Müller Jan 15 '17 at 21:12
  • \$\begingroup\$ I guess only RESET pin and interrupt from internal RTC which sends the signal to RESET through GPIO16. \$\endgroup\$ – Defozo Jan 15 '17 at 21:15
  • \$\begingroup\$ Hm, I somehow doubt that. If your only way to exit a sleep state is a complete reset, then that sleep state is completely useless – you could as well completely turn the device off. \$\endgroup\$ – Marcus Müller Jan 15 '17 at 21:17
  • 1
    \$\begingroup\$ By the way, phototransistors are very temperature-dependent. So in the summer, you might wake up more often than in the winter with your reset-approach. With my wake-up approach, you might be able to compensate for temperature by only sending data when the resistor has low resistance for a longer period! \$\endgroup\$ – Marcus Müller Jan 15 '17 at 21:38
1
\$\begingroup\$

As mentioned by Marcus, using an analog value for this isn't advised. If you can I'd suggest changing to a photodiode, and then using it to trigger the one-shot circuit in this answer to a previous ESP8266 question

If you still want to use the photoresistor and a pot to have an adjustable threshold, you're probably going to want to use a comparator. Something similar to this with pin 7 connected to the one-shot circuit.

enter image description here

\$\endgroup\$
0
\$\begingroup\$

In theory: yes, with the right R6. In practice, you will need a slightly different solution.

To reset the EPS8266, REST needs to be pulled below Vcc/4 (usually ~0.8V). It has an internal weak pull-up and most pre-made modules (D1, NodeMCU, etc) add another external pull-up to avoid spurious resets.

Your photoresistor is probably over 1MΩ in the dark and in the 10..100kΩ range in light (measure!). Between Vcc and REST, it acts like another, variable pull-up. To pull the device into reset, you need to choose R6 low enough to overcome all these pull-ups, while at the same time keeping it high enough to avoid spurious resets. In practice, this won't work.

What you could do instead is using a Schmitt trigger (e.g. 74AC14), voltage comparator (with open collector, e.g. LM393) or OpAmp to monitor the voltage divider and use their output to pull REST to GND when it's dark.

As an alternative, I would suggest that you use the CH_PD (ENABLE) pin. Instead of the permanent 10k pull-up (R1), use the same voltage divider and select R6 to be around 3-4 times the 'light' resistance of your phototransistor. This should work without any additional parts. The only drawback is that you can't use the RTC memory as technically your device is off, not sleeping.

PS: To those not familiar with the ESP8266, the 'wake up' is actually a reset (usually triggered by the RTC pulling the reset line low) and the device has to be re-initialized after wake up.

\$\endgroup\$
0
\$\begingroup\$

You can keep the ESP in reset constantly when dark, but check that no additional current is drawn in that unusual state.

An option is to wake up with the light as you wrote, send data, set an automatic wake up to about a minute in the future, go to deep sleep. If light stays on, you wake up one minute later and send data again. If light goes off, you will not wake up and that's ok for you.

This is not the best.

Connect the phototransistor to both an attiny and to ESP, set the Attiny to wake up upon level CHANGE of the pin where you connect the trigger, wait for 1 second (in case the finger slips and light is turned on/off quickly by mistake), have the Attiny turn on the ESP using a P-MOSFET, have the ESP read the Schmitt output and send data.

You wake up only when needed, it costs only one attiny. It fits on the back of the ESP-12. You can also avoid the MOSFET and simply use the attiny to turn on the ESP from its power-off state.

http://ww1.microchip.com/downloads/en/DeviceDoc/doc8126.pdf 7.1, sleep modes: you can wake it up from power down with pin changes. 19.4 power consumption in power down: 0.2 uA. Years of use if you use a Li-Ion with MCP170x linear regulator to 3V.

For info: in deep sleep some memory of the ESP is retained, about 60-100 bytes I think. In power down mode, not.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.