Flooding is a significant natural disaster that can cause extensive damage to property, infrastructure, and human lives. Traditional methods of monitoring river levels often involve manual measurements or outdated technology, which can be slow and unreliable. Can you imagine a situation without timely information?
This project aims to develop a reliable, real-time early warning system for monitoring river water levels using cellular technology and affordable hardware solutions. The goal is to improve flood prediction and risk management, ensuring the safety of communities and infrastructure. The project will enable better decision-making related to evacuation plans, infrastructure maintenance, and land use management by providing real-time information from the river monitoring systems.
Why Cellular Networks?Cellular networks are particularly suitable for monitoring river water levels for several key reasons:
- Wide Coverage: Cellular networks are widely established, providing extensive coverage even in remote areas.
- Real-Time Data Transmission: They allow real-time data transmission, essential for timely flood warnings and responses.
- Cost-Effectiveness: By utilizing existing cellular infrastructure, the need for additional investments in communication hardware is minimized.
- Scalability: Cellular networks can easily support many monitoring devices, making them scalable for extensive river systems.
- Reliability: These networks offer dependable communication channels, ensuring a consistent flow of data.
These advantages make cellular networks an efficient and practical choice for systems that monitor river water levels.
Hardware selectionFor this project, our goal is to establish a network connectivity solution that is not only reliable but also energy-efficient and easy to set up. To accomplish this, we have chosen to incorporate the Blues Cellular Notecard in conjunction with the Notecarrier A. This combination will enable us to create a robust and efficient system. We will be utilizing JST connectors to seamlessly integrate a LiPo battery and a solar panel into the Notecarrier A, allowing us to deploy a fully standalone device that maximizes both performance and sustainability.
To effectively measure the water level of the river, we will be using a SeeedStudio Ultrasonic Level Sensor (IP67 waterproof). This advanced sensor operates using the RS485 protocol. It is capable of detecting water levels at distances of up to 750 cm with the bell-mouth mounted. The ultrasonic technology employed by the sensor emits sound waves and measures the time it takes for the waves to bounce back, ensuring accurate readings even in varying environmental conditions. This will enable us to closely monitor the river's water level and react promptly to any significant changes.
We will use an M5Stack AtomS3 (ESP32 S3) connected to an M5Stack Atomic RS485 Base to interface the sensor and control the cellular networks.
The ultrasonic sensor communicates with the host microcontroller using the RS485 protocol. The Notecard is connected to the host microcontroller via the Qwiic connector and communicates over the I2C protocol.
All the hardware components are securely housed within a weatherproof enclosure, designed to protect against moisture and dust intrusion. This enclosure is mounted on a desktop camera arm, which allows for enhanced orientation and stability. We have 3D-printed a mount for the ultrasonic level sensor and a holder for the enclosure, ensuring it is securely attached to the arm.
The final assembly, which includes an attached LiPo battery, is organized as follows:
We also attached a small 300mW solar cell to the cover of the enclosure.
We need to set up Notehub, which is a cloud service that receives data from the Notecard and allows us to manage the device, and route that data to our own or 3rd party cloud apps and services. We can create a free account at https://notehub.io/sign-up and after successful login, we can create a new project.
We should copy the ProductUID which is used by Notehub to associate the Notecard to the project created.
Notecard ConfigurationFirst, connect the Notecarrier A to a computer via a USB cable. We should see a red LED flash repeatedly while it's booting up. We will be using the in-browser REPL to configure the Notecard which can be accessed at https://dev.blues.io/terminal.
Click on the USB Notecard button and pair the device as shown in the images below.
We would be able to see the REPL after a successful pairing.
To associate the Notecard with the project in Notehub, we need to provide ProductUID for the project. Write the request (given below) in the text field above and click on the paper plane button.
{"req":"hub.set", "product":"com.xxx.xxxxx:river_water_level_monitoring"}
To synchronize the Notecard with the Notehub, send the request below.
{"req":"hub.sync"}
After the synchronization process is finished, the response to the subsequent request will provide the UNIX Epoch time of the latest sync and the duration in seconds since the last completed synchronization.
{"req":"hub.sync.status"}
{
"time": 1735970962,
"completed": 4
}
Route ConfigurationWe will be displaying the live sensors data using the Datacake, a data streaming and visualization tool, that's easy to setup and configure. We would need to create a Datacake account. We can create a route by clicking the Create Route link at the top right on the Notehub Route page. Please follow the instructions given in the comprehensive tutorials offered by Blues, for leveraging the General HTTP/HTTPS Request/Response route type to invoke the Datacake API.
To ensure that the correct Notecard outbound file data is sent to Datacake, we need to specify the desired filters in the Filters section. This guarantees that the data sent is always the intended data. In the application code, we would add notes to the data.qo file.
We need to provide a specific HTTP payload decoder in the Datacake device configuration to parse the incoming data from the Notehub.
function Decoder(request) {
var data = JSON.parse(request.body);
var device = data.device;
var file = data.file;
var decoded = {};
if (file == "data.qo") {
decoded.ultrasonic_distance = data.body.ultrasonic_distance;
decoded.card_temperature = data.body.temperature;
decoded.voltage = data.body.voltage;
decoded.time = data.when;
decoded.location = "(" + data.best_lat + "," + data.best_lon + ")";
}
var datacakeFields = []
for (var key in decoded) {
if (decoded.hasOwnProperty(key)) {
datacakeFields.push({field: key.toUpperCase(), value: decoded[key], device: device})
}
}
return datacakeFields;
}
To visualize the sensor readings, battery voltage, and the Notecard temperature value we need to add a dashboard with Value widgets.
We can add and format the widgets as shown below.
Please follow the instructions here to download and install Arduino IDE. After installation, open the Arduino IDE and install the board package for the ESP32 by going to Tools > Board > Boards Manager. Search the board package as shown below and install it.
After the board package installation is completed, choose the M5StackAtomS3 from Tools > Board > ESP32 Boards menu and select the serial port of the connected board from Tools > Port menu. We need to install the Blues Wireless Notecard library using the Library Manager (Tool > Manage Libraries...) as shown below.
Similarly, we can find and install the M5AtomS3 library.
FirmwareWe can utilize the following Arduino sketch to sample ultrasonic level sensor readings and transmit it to the Notehub. Create a new sketch with the following code and compile/upload the firmware to the M5Stack AtomS3. The sensor readings are collected every second and transmitted to the Notehub every 30 seconds.
#include <Notecard.h>
#include <M5AtomS3.h>
#define PRODUCT_UID "com.xxxxx.xxxxx:river_water_level_monitoring"
#define ATOMS3_RX_PIN 5
#define ATOMS3_TX_PIN 6
Notecard notecard;
unsigned char cmd_dist[] = {0x01, 0x03, 0x01, 0x01, 0x00, 0x01, 0xd4, 0x36};
unsigned int timeout_ms = 1000;
void setup()
{
notecard.begin();
J *req = notecard.newRequest("hub.set");
JAddStringToObject(req, "product", PRODUCT_UID);
JAddStringToObject(req, "mode", "continuous");
notecard.sendRequestWithRetry(req, 5);
auto cfg = M5.config();
AtomS3.begin(cfg);
AtomS3.Display.setTextDatum(middle_center);
AtomS3.Display.setTextSize(1);
Serial2.begin(9600, SERIAL_8N1, ATOMS3_RX_PIN, ATOMS3_TX_PIN);
}
uint16_t getDistance()
{
uint16_t distance_mm;
uint8_t buff[256];
Serial2.write(cmd_dist, 8);
delay(10);
int dataLen;
unsigned long start_ms = millis();
while ((dataLen = Serial2.available()) == 0) {
delay(20);
if (millis() - start_ms > timeout_ms) {
/** error value **/
return 999;
}
}
if (dataLen > 0) {
int recvSize = Serial2.readBytes(buff, dataLen);
distance_mm = buff[3] << 8 | buff[4];
}
return distance_mm;
}
void sendNote(uint16_t distance)
{
J *req = notecard.newRequest("note.add");
if (req != NULL) {
JAddBoolToObject(req, "sync", true);
J *body = JAddObjectToObject(req, "body");
if (body != NULL) {
JAddNumberToObject(body, "ultrasonic_distance", distance);
}
notecard.sendRequest(req);
}
}
unsigned long last_sampling_ms = millis();
unsigned long last_note_ms = millis();
void loop()
{
if (millis() - last_sampling_ms > 1000) {
uint16_t distance = getDistance();
Serial.printf("Distance = %d mm\n", distance);
AtomS3.Display.clear();
if (distance <= 250 || distance > 9999) {
AtomS3.Display.setTextColor(RED);
AtomS3.Display.drawString("ERROR", AtomS3.Display.width() / 2, AtomS3.Display.height() / 2, &fonts::FreeSansBold18pt7b);
} else {
AtomS3.Display.setTextColor(GREEN);
AtomS3.Display.drawNumber(distance, AtomS3.Display.width() / 2, AtomS3.Display.height() / 2, &fonts::FreeSansBold24pt7b);
if (millis() - last_note_ms > 30000) {
sendNote(distance);
last_note_ms = millis();
}
}
last_sampling_ms = millis();
}
}
Field DeploymentWe have securely mounted the device firmly using the desktop camera arm on a bridge that spans the river.
The ultrasonic sensor should be positioned as perpendicular as possible to the water level to effectively emit and receive sound waves for accurate distance measurements.
The M5Stack AtomS3 shows the ultrasonic sensor readings on the TFT display in millimeters. This compact display is very useful for checking sensor status in the field.
In the Datacake dashboard, we can view the latest sensor data values.
Additionally, we can see the device’s location on a map alongside the sensor value. A detailed map becomes an invaluable tool when managing a multitude of devices, allowing us to visualize their locations along with the corresponding sensor values. This comprehensive view not only enhances our understanding of each device’s status but also facilitates efficient monitoring and quick decision-making across the entire network.
In the demo video, the position of the device may appear slightly off; however, this discrepancy is due to using the cellular tower location rather than the actual location of the device itself. This should not pose any real concern, as there will only be one device installed at the designated deployment site. The approximate location of the device will still allow for reliable monitoring and tracking. However, should we require a more precise location in the future, we have the option to implement additional code that would allow the device to periodically transmit its GPS coordinates.
The M5Stack AtomS3's TFT display shows the ultrasonic sensor value in millimeters and also it shows the text ERROR whenever the MCU fails to read data from the sensor over RS485 connection (that happens once in a while) or the sensor value is below 250 mm (sensor's limitation).
ConclusionThis project has successfully developed a real-time river level monitoring system that leverages modern cellular technology combined with cost-effective hardware. By replacing slow and unreliable traditional methods with this innovative approach, we have significantly improved the speed and accuracy of flood predictions. This advancement not only aids in the timely dissemination of critical information but also plays a pivotal role in safeguarding lives, property, and infrastructure. The implications of this system extend beyond mere data collection; it empowers communities to prepare for and respond to flood events more effectively.
Comments