Overview
The device is mounted on an old dam foundation behind my house (actually on my next-door neighbor's property) and monitors the creek level just above the ledge of an old dam.
Basics of the sensor
The water level sensor is based on the ESP8266 micro-controller chip and a HC-S04 ultrasonic sensor. The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP
stack and MCU (Micro-Controller Unit). I used the NodeMCU development platform using the LUA programming language to write the firmware and flash it to the micro-controller.
The sensor itself is an ultra-sonic sensor connected to the ESP8266. The firmware on the ESP8266 sends a signal to the ultra-sonic sensor, which in turn, emits an ultra-sonic signal above the surface of the water and detects when the signal returns. The returned signal is timed and the distance calculated using the speed of sound. It should be noted that temperature effects the speed of sound. I have made no effort to adjust for temperature changes. This likely results in minor fluctuations in level reading at lower levels. The firmware executes a reading every ten minutes, which includes five individual readings at five second intervals. The multiple readings allow for more accurate readings and to weed out any aberrant readings.
Web Server
The sensor connects to my home WiFi network via a Ubiquiti Picostation high power access point (it's about 110' from the sensor to the house). All of the results of the readings (and the current battery voltage) are posted to a local webserver at my house (Raspberry Pi running LAMP (linux, Apache, MySQL, PHP). A PHP script on the Raspberry Pi analyzes the five readings and determines either a modal average or a mean average (depending on the disparity of the readings). The resultant average is the entered into a local database and also posted to my webserver on the Internet (also running LAMP).
The Internet webserver uses a combination of PHP, Javascript and the Google Charts API to generate the water level chart.
Power
The device is powered by a motorcycle battery. It seems that it will last a couple of weeks. I know that I can reduce the power consumption by having the MCU sleep between reporting times. In my initial desire to get this up and running, I was more concerned with just getting it working than power consumption.
Structure
The sensor, micro-contoller, and battery are all attached to a structure made from 1-1/2" angle steel with a 1/2" square tube steel arm welded on the top to support the ultrasonic sensor. It also has 20 gauge steel shields welded over the ultrasonic sensor and the nodeMCU to protect them from the weather. The battery is encased in a weather-proof box and locked to the structure.
Things I Would Do Different
In retrospect, there are a few things that I would do differently (and I may do at some point). As noted earlier, the nodeMCU does not sleep between reporting times. This leads to more rapid battery consumption.
Currently the nodeMCU does the calculation of time, speed of sound and distance and rounds off to the closest inch before sending the information to the server. Because of the rounding and the effects of temperature, the charted data can look jaggedity. Also, this allows me no latitude to make adjustments for temperature or utilize increments of less than one inch, unless I reprogram the micro-controller. Unfortunately, this requires that I unseal it from its enclosure and connect to it via a USB cable. This also means standing atop a moss covered concrete abuttment over the creek with my laptop in hand. I should have sent the raw data to the server and done the calculations on the server, where I can make adjustments while sipping a latte and lying in bed.
The ultrasonic sensor is not water-resistant. I have provided a shield to protect it from rain and I sealed the electronics in a plastic case. However the
sensor cones are open to the air and therefore may be subject to air moisture and condensation. Since installing this, I have purchased a waterproof
sensor and I fully expect to install it when the other one quits working.
Thoughts, comments, questions: