I am using my ESPLive (ESP8266) board (without the mains power supply) and hooking it directly to the 12 V battery supply available on the controller board. I am in the process of implementing firmware with the following features:
- MQTT over WiFi for monitoring and control
- Output to trigger the gate to fully open
- Output to trigger the gate pedestrian open
- Monitor the gate's battery voltage (when it's low on charge, needs replacing, etc.)... it really sucks having a power failure and being stuck outside!
- Monitor the gate status LED to determine whether the gate is closed, opening, open, closing, faulty, etc.
All of the features are pretty straight forward, requiring simple IO and ADC. The trigger outputs could use a relay, but since the ground connection is the same for the ESP and the gate I am simply using an open collector transistor to pull the "PED" and "TRG" inputs low for pedestrian and full open operation.
The battery voltage monitoring is also simple. I am using a 10k and 150k resistor divider to the ADC input. This provides a nice round 0.0625 division of the battery voltage which is nominally 13.5V (0.84V at the ADC which has a 1V reference) and can safely measure up to 16V to cater for charger over-voltages, headroom, etc. If the battery measures less than 12.5V when the charger is connected then it's on it's way out or dead already.
The most interesting feature is monitoring the STATUS LED. According to the datasheet, this LED flashes at a different frequency, representing different things. I have summarised the statuses from page 45, below:
- Off: gate is closed (if the gate lost power and didn't fully close, will it show as open or closed?)
- On: gate is open
- Slow continuous flash (frequency to be determined): gate opening
- Fast continuous flash (frequency to be determined): gate closing
- 1 flash/s: pillar light on
- 2 flash/s: no mains
- 3 flash/s: battery low
- 4 flash/s: collision detected (need to wait 60s before trying to open/close again)
- 5 flash/s: microprocessor reset
I need to do some testing to determine what "continuous flashing" entails. Hopefully the frequency of fast flashing is less than 1 flash/s - that way it's easy to tell the difference between the states.
I plan to implement a simple finite state machine to determine the statuses. I'll write more details when it's done!