Monitoring Water Levels with the Ai-M61-32S

Project Solution

By reading the analog values from the IO interface and performing voltage conversion, the detected voltage values can be obtained. Further voltage - water level calibration enables serial printing and plotting of water level height, achieving real - time water level monitoring.

Voltage Conversion

Based on Ohm's Law, V = I / R, voltage is proportional to resistance. By obtaining the analog values corresponding to 3.3V and GND (measured as 3199 and 21), the actual voltage conversion formula is derived as Valtage = val * (3.3 / (3199-21)).

 

Code    

#include <stdio.h> void setup() {    

pinMode(19, INPUT);    

Serial.begin(115200);

}

void loop() {    

int val = analogRead(19); // analog value reading

float vlt = val * (3.3 / (3199-21)); // real voltage conversion    Serial.println(vlt);    

delay(200);

}

Hold down the IO2 button and short - press the EN button to enter download mode. After configuring the port, upload the project and reset to run the program.

 

Water Level Sensor

The water level sensor can detect water height (detection range: 0 - 40 mm) and can also be used as a raindrop sensor for weather monitoring, detecting rainfall and intensity. It is widely applied in automotive windshield wiper systems, intelligent lighting systems, washing machines, and smart sunroof systems.

Module Introduction

When powered on, the power indicator LED lights up. Operating voltage: DC 3.3V - 5V. Output type: analog signal.

 

The sensor features 10 exposed copper lines, with 5 power copper lines and 5 sensing copper lines arranged in an interlaced parallel pattern, with each power copper line having a sensing copper line in between.

Module Schematic

 

Pin Definition

  • S (Signal) is the analog output;
  • + (VCC) is the sensor power supply;
  • - (GND) is the ground.

 

Working Principle

When there is water between parallel copper lines, different immersion heights result in varying currents. The resistance between copper lines changes with water level variations.

Resistance is inversely proportional to water height (the deeper the sensor is immersed, the better the conductivity, the lower the resistance, and the higher the current). Thus, the water level can be determined by measuring the sensor's output voltage via ADC.

 

Hardware Connection

S -> IO19, + -> 3V3, - -> GND.

After completing the hardware connection, open the serial port. At this point, the output voltage should be 0.

Water Level Calibration

Due to differences in water quality and conductivity, calibration is required. Dry the parallel copper lines on the PCB surface before each calibration. Place the sensor in water when the voltage reads 0 and record the water level and voltage. Collect multiple sets of data for averaging.

Calibration Data Collection

At a water level of 10 mm, the corresponding serial output voltage is 1.25 V.

 

Increase the water level and collect multiple voltage - water level data pairs. Assuming a linear relationship between voltage (V) and water level height (mm), fit the data using Excel to obtain the equation y = 41.774 x - 38.686.

 

Project Code

Add water level height definitions in the code:    

#include <stdio.h>void setup() {    pinMode(19, INPUT);    

Serial.begin(115200); }void loop() {    int val = analogRead(19); // analog sensor value     

float vlt = val * (3.3 / (3199-21)); // real voltage conversion    float wl = 41.774 * vlt - 38.686; // water level (mm)      Serial.print(val);      Serial.print(",");    Serial.print(vlt);    Serial.print(",");    Serial.println(wl);...
Read more »