Hi – my first post here!
I’m trying to design a setup which updates my raspberry Pi LAMP server with the orientation of my garage door. I’ve got a couple of mercury ’tilt’ switches, which would do the job of triggering the pins. I also toyed with the idea of using the hall sensor.
However, I can’t work out how to use either of these methods whilst also keeping my ESP32 in deep sleep mode? I’d like the device to run on battery power.
Ideally, the board should only wake up and post the new door orientation when it changes.
As I understand it:
- Hall sensor cannot be used to wake from deep sleep
- Using one mercury tilt switch will be ON when the door is open and OFF when it is closed, however I don’t know how to awaken from deep sleep when there is a CHANGE in pin state from both high to low OR low to high?
- I thought perhaps using two tilt switches at right angles to each other might do it, however this means that one switch is always high and the other is always low. As one switch is always HIGH then, from what I have tried, this means the board is constantly woken from deep sleep.
I’m a novice at this, and have a feeling I’m taking the wrong approach altogether – any thoughts?
Thanks in advance,
You can use ext0 as a wake up source.
This function accepts as first argument the pin you want to use, in this format GPIO_NUM_X, in which X represents the GPIO number of that pin.
The second argument, level, can be either 1 or 0. This represents the state of the GPIO that will trigger wake up.
You can set the level to 0 for one reed switch and to 1 for the other reed switch. This way, the ESP will wake up when one of reed switches change state.
Alternatively, you can use ext1. To use this wake up source, you use the following function:
This function accepts two arguments:
- A bitmask of the GPIO numbers that will cause the wake up;
- Mode: the logic to wake up the ESP32. It can be:
- ESP_EXT1_WAKEUP_ALL_LOW: wake up when all GPIOs go low;
- ESP_EXT1_WAKEUP_ANY_HIGH: wake up if any of the GPIOs go high.
So, I think this is not the best approach.
Use ext0 for both of your reed switches, but set a different level for each of them.
I hope this helps.
Thanks Sara – this looks promising! I will give it a try and let you know how I get on! 🙂
@Steve Thanks for the post. I’d love to use the Hall Effect sensor with this project, but I don’t believe it can (easily) be used to wake from Deep Sleep mode? I saw a github project which tackles this problem somewhere, but it looked a bit technical for me.