Our schematic is fairly simple, we will have one pin (GPIO #13) monitor the door sensor.
We can put the ESP8266 in low power mode and then 'wake up' every few seconds. This is way better for battery life than just keep the ESP8266 awake forever. To do that, tie pin GPIO #16 to the RST pin, that way the auto-wakeup will work.
We will also keep track of the battery level by creating a high-resistor-divider on VBat to reduce the voltage of the battery from 220KΩ/1220KΩ = 1/5.5 times. This means a max voltage of the battery (4.2V) is 0.75V, well within the range of the ESP8266's 1.0V-max ADC
Pin 16 to RST (this lets us use the low power mode)
- Pin 13 to one side of door sensor
- GND to opposite side of door sensor
- VBat to the battery +
- GND to battery -
- GND to one side of the 220kΩ resistor
- VBat to one side of the 1MΩ resistor
- Pin A to the opposite side of the 1MΩ resistor and 220kΩ resistor