Well I’ve been sitting on this one for a while and finally have time to write it up. With my boat sitting on a mooring, I wanted a easy way to check it’s vital signs: such as position, battery voltage and bilge level. There are now dozens of internet connected microcontrollers available, and I happened to choose the MKR1000 from Arduino.
There are also now hundreds of cloud based IoT services for aggregating data from devices. I found that ThinkSpeak was easy to setup and free for low volumes of data. Click the following graph to see the live version currently in use on my boat:
Pretty cool huh? So let me show you how to create a basic boat monitor using the MKR1000 and ThingSpeak!
- An Arduino MKR1000.
- Mobile 3G or 4G Wifi Modem.
- A GPS Module.
- Float Switch to monitor the bilge.
- A few resistors to monitor battery level.
Firstly, check out ThingSpeak and create an account. Then create a channel, fill in the name, description and enable/label the first four fields like so:
Save your channel, and you should see some empty graphs. Next go to the API Keys tab and copy your “Write API Key”. We will need to put this in the Arduino code.
Wire up the MKR1000 as follows:
- You can use any sort of GPS module that spits out NMEA sentences. Just remember to change the baud rate in the code.
- You will need to power the MKR1000 via a USB cable. The VIN pin can only accept 5V, do not connect higher voltages or you will fry the board.
- The battery voltage measurement terminals use a resistor divider which lets them measure 0 to 18.8V.
First, follow this setup guide and make sure you can compile and upload sketches for the MKR1000.
Next, grab the starting source code. You will also need to install the TinyGPS++ library.
Edit the code, and enter your ThingSpeak “Write API Key”, your Wifi SSID and password.
Essentially the code will connect to ThingSpeak every 60 seconds and report 4 values:
- Battery voltage on pin A1.
- The number of seconds between updates that the bilge switch has been on.
- GPS Latitude.
- GPS Longitude.
Compile your changes, and upload to the MKR1000. You should get something like the following out of the serial terminal. Check ThingSpeak and you should see a new data point on the graphs!
SSID: BoatWifi IP Address: 192.168.1.35 signal strength (RSSI):-82 dBm Setup Complete Connecting to ThingSpeak... field1=12.72&field2=0&field3=0.000000&field4=0.000000 HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 1 Connection: close Status: 200 OK X-Frame-Options: ALLOWALL Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH Access-Control-Allow-Headers: origin, content-type, X-Requested-With Access-Control-Max-Age: 1800 ETag: "c4ca4238b0b923820ecc509a6575849b" Cache-Control: max-age=0, private, must-revalidate Set-Cookie: request_method=POST; path=/ X-Request-Id: f7a7d01c-7bda-44e9-a0b2-7072e5d7bd57 X-Runtime: 0.036820 X-Powered-By: Phusion Passenger 4.0.57 Date: Sat, 04 Feb 2017 00:06:13 GMT Server: nginx/1.9.3 + Phusion Passenger 4.0.57
If you successfully made it this far, you can no doubt see there are a huge range of sensors that could be added and monitored remotely. It’s also possible to remotely control relays to turn on devices, such as a refrigerator. Using the ThingSpeak interface, the board can also send Tweets alerting you to potential problems:
I should provide a warning: the circuit I described for this post is in the simplest form to get the job done. It offers your MRK1000 board no protection from voltage spikes, bad wiring or electrostatic discharge. I have been working on a circuit board that will provide protection to the MKR1000 and add a whole bunch of features:
- Temperature, Humidity and Pressure monitoring.
- Possibly monitoring cabin gas levels (CO2 and Propane). Although doing this accurately becomes expensive.
- Primary and secondary battery voltages.
- Internal buzzer for backup bilge alarm.
- Build in GPS receiver.
- Built in power supply from 12V battery with transient voltage protection.
- NMEA 0183 interfaces to accept wind speed & direction (eg. from my Wind Board), could also be programmed to use any other NMEA sentences available (eg. depth).
- Interface to Victron BMV-700 series battery monitor. This allows access to battery health data such as voltages, current, state of charge.
- Ability to Tweet alerts and status.
- Remote control of a relay using ThingSpeak’s talkback function.
However I have had to put this project on hold due to lack of time. I may post further updates when I get the time, so feel free to subscribe to my blog and this will keep you updated.
Please let me know of any updates.
This looks like a really interesting project. I’d thought about doing something similar myself (although you have a lot more Arduino experience, so you’ll do cleaner and better than I would). A few other features I’d thought about, and would be interested in if they’re practical in your solution:
–Daily and/or emergency reports by SMS – I wanted to be independent of Wifi, which can be flaky at the marinas I use, so I was thinking of a 3G modem and SIM instead. Here in the US, I think it would be cheaper to get SMS service than a full data plan, so I’d imagined a daily status update and immediate messages for emergency conditions (e.g. high water level, low battery, geofence violated).
–Monitoring of bilge pump runtime – I’d like the daily status to include the total runtime of the bilge pump(s) in the previous 24h. That would require some sort of interrupt and timer when the pump(s) start and stop, which might mean a little more power draw for the Arduino, but that’s probably not significant on a good-sized house bank, at least if you have a little solar to keep the batteries charged.
–Daily history from a solar charge controller (e.g. times for bulk charge, acceptance, and standby; whether the bank was topped off during the day). This one would be a long shot, since every charge controller would be different. My Rogue controller can be queried via an RS-485 interface, so it’s theoretically doable, but it’s a lower priority, as most of that can be inferred from battery voltage patterns.
If you get the boards built, I’d be happy to help with coding and testing.
Thanks for your comments Aaron! There are some good ideas there.
It looks a lot like the kbox (https://www.tindie.com/products/sarfata/kbox-open-source-boat-gateway/). Could be interesting to use the same foundation for both projects since the kbox is totally opensource.
Cool, was not aware of kbox. Thanks for the link! It would indeed be great to have one foundation, will look into it more!
I think being able to “roll your own” gives more flexibility.
Hi, just in case this helps anyone else setting this up, I had a lot of issues with the Arduino only going through two loops before not connecting to Thingspeak any more. Took me hours to figure out it was the current version of WiFi101 which has an issue. I rolled the included version of WiFi101 back to 0.13.0 in the Arduino IDE and now seem to be good to go (not re-tested in boat yet).
Hi Tom, did you ever get a chance to add some of those additional features you were planning?
I have a similar project using a MKR GSM1400, getting battery info from a Victron BMV-600, and posting to thinger.io. Similar to when you posted this, it’s in the phase of working, but not with all the features I have planned for it. I am documenting it here: https://create.arduino.cc/projecthub/damonlane/off-grid-remote-monitoring-batteries-leak-detection-etc-3a15c1?ref=user&ref_id=674536&offset=0
If people have seen Floathub, which is a quasi-commercial Arduino boat monitor, you may know that open source project is a good source of code: https://github.com/floathub/device/blob/master/mega/mega.ino I’m not sure how much happens on the board vs on the server and they do hold back some features for their paying customers. I’m not knocking them at all, I’d buy one and use their service if I didn’t want to get info from the battery monitor instead of simple voltage and to automatically turn on ventilation if the dew point is lower outside than inside, and to….
Hi Damon, I’m afraid I didn’t get around to doing much more work on the boat monitor. Other parts of life got in the way.
Nice work with your own solution, and interesting to see the Floathub project. Thanks for your comments.
Very useful, might actually get something working now.
Hello all. I converted this code for a standard esp8266. Has anyone got the lat, long to update a map on the Thingspeak site? I have never used it until today. I got the data getting to the site, but then what?