Wednesday, 30 August 2017

Arduino Sliding Gate Controller

As a part of my budding home automation system I am planning on adding some monitoring and control functionality to my home gate. The gate is of the sliding variety, and to be specific is the Centurion D5 which has a nice controller board with several good (and probably quite common) features. The datasheet is here.

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:

  1. MQTT over WiFi for monitoring and control
  2. Output to trigger the gate to fully open
  3. Output to trigger the gate pedestrian open
  4. 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!
  5. 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!


Friday, 18 August 2017

ESPLive v2.0 : The "ultimate" mains connected ESP8266

I decided that although there are many ESP8266 boards out there these days - and even some which are "mains connected" such as the fantastic Sonoff boards - none really fit my requirements for flexibility. As a result, the ESPLive was born.

The ESPLive v2.0 prototype with USB-Serial connected.


The ESPLive is simply an ESP8266 based ESP12F module with all of the pins broken out and a few nifty features. Of course, the most obvious feature is the mains power supply... I opted for a MeanWell IRM-02-5S to supply 5V at 2W (for relays and other power hungry devices).
  1. I like the NodeMCU way of flashing and so I added a couple of transistors so that I never have to push any buttons while developing firmware. 
  2. Since there is only one ADC on the ESP8266, I also added an analog multiplexor IC which lets me switch between two inputs.
  3. Through selectively soldering only certain resistors and jumpers it is possible to have 2 separate inputs, one of which has an optional voltage divider for 3.3 V or 5 V range (or more). The second input is direct or has a burden resistor that is biased to 0.5 V for current measurement with a current transformer.
  4. There are two transistor driven outputs capable of 300 mA for driving relays. These outputs also have robust flyback diode protection with a zener and rectifier diode. See this app note for why the zener is a good idea.


Firmware

I have used both espurna and Tasmota on these boards and I currently have one installed and running well with Tasmota in my Man Cave. The board is really small (about 3.5 x 5 cm) and so I wrapped it up in insulation tape and squeezed it into a light switch which had neutral available. A little bit dodgy but it works! ;)

I am working on some mods to the above firmwares (I haven't decided which is best yet) to control my how water geyser for maximum energy efficiency and also something to control my jacuzzi, gate, etc. 

I'm using Home-Assistant and Node-Red, which seem great so far! I'll post some articles on the setup at some point.

https://github.com/ManCaveMade/ESP-Live

Home Assistant Hue Emulation

My Home Assistant setup uses nginx to proxy the web interface to HTTPS. I bought a Google Assistant for black friday and I want it to be abl...