Tech: Boat Alarm shore power and battery monitor




Back in November I wrote about "Boat Alarm", a free service I'd developed for monitoring your boat. The original Boat Alarm client ran on an Arduino Uno R3 microprocessor with a CC3000 WiFi shield. Unfortunately the CC3000 proved to be unreliable, and I no longer recommend that WiFi hardware. I've switched to using the Adafruit HUZZAH ESP8266 for the client hardware (shown above). This microprocessor is Arduino-compatible and also has built-in support for WiFi. It has the added benefit of being very inexpensive. You can learn more about the Adafruit HUZZAH ESP8266 here.

The downside of the ESP8266 is that it has only one analog port, however there are 10 digital pins available for general I/O. Since many alarms are inherently binary in nature, i.e., something is either on or off, the latest version of the client is now able to utilize digital ports as well as the analog port.

Note: Pay attention to input voltages. Except for RX/TX, the ESP8266 only works with 3.3V and pins are not 5V tolerant. If using a USB adapter for monitoring shore power, step down the 5V output with a 5:3 voltage divider. Alternatively just use a 3.3V DC power supply.

The new client monitors shore power on digital pin 2, but you can modify the source code to monitor something else, or use another pin if you prefer. Shore power is monitored by means of sensing the output of a USB adapter plugged into your vessel's mains power (stepped down to 3.3V or less). As before, an analog pin is required to measure the battery voltage. The range of ESP8266's analog to digital converter (ADC) is only 1.0V, so you need to step down the battery voltage with a voltage divider. I combined the battery power supply with the voltage divider as shown below. The red wire supplies VBat and the yellow wire supplies Vbat/16.


The client software is configured via the Alarm array. Alarm fields in order are:
  1. alarm name
  2. alarm pin
  3. report value (true to report value, false not to report)
  4. expected value (if digital, otherwise ignored)
  5. low threshold (if analog)
  6. high threshold (if analog)
  7. scale (if analog)
The default configuration is as follows:

Alarm alarms[] = {
  { "Power:ShorePowerLoss", "D2", false, HIGH },
  { "Power:BatteryVoltageLow", "A0", true, 12600, 12000, INT_MAX, 16.0 }
}; 

The first alarm senses shower power on digital port 2 (D2) where HIGH is expected.
The second alarm senses battery voltage on analog port 0 (A0) where the normal range is above 12V (i.e., 12000mV), using a 16:1 voltage divider to scale the input voltage.

As for testing, the new version has been running on Arriba for over a week and has already detected one power outage. There is also a test device, which logs its output here.

The web service is pretty much the same as before, except when registering you can now specify your country and timezone. There is also now a way to view recent alarms, accessible from the update page.

OVER.