Project Overview:
This project is an experimental prototype of an ultrasonic radar rainfall monitoring system based on ESP32, capable of monitoring rainfall over short distances (within 10m).
In the field of microcontroller-based environmental monitoring devices (such as temperature, humidity, brightness, wind speed, air pressure, and lightning distance), no examples of non-contact rainfall monitoring have been observed.
Based on ultrasonic ranging, this project conducted experiments on the reflection of ultrasonic waves from raindrops and the basic noise of ultrasonic wave reception, analyzed the echo changes in various environments, and determined a scheme to add a bandpass amplifier to the received reflected wave. For experimental convenience, a 40kHz ultrasonic frequency is used in this scheme. According to the principle of sound wave reflection, for tiny raindrops, a higher frequency should yield a larger reflected wave, thus improving sensitivity. In principle, the rainfall can be calculated based on the characteristics of the reflected wave, but this has not yet been achieved.
This project utilizes the Wi-Fi function of the ESP32 and adopts the MQTT protocol to send rainfall, temperature, and humidity information to a server, which can be pushed to mobile devices. The server is built on a Raspberry Pi using NodeRed, with PeanutShell used for intranet penetration.
The hardware of this project uses an ESP32WROOM module, a 1.8" TFT color screen, a rotary encoder, a DHT temperature and humidity sensor, and an RCWL-9610 ultrasonic ranging chip and an operational amplifier. The power supply is TYPE-C5V.
Software development
is conducted using the ARDUINO IDE platform.
After power-on, the display, temperature and humidity sensor, encoder, and ultrasonic wave generator and receiver are initialized. A second interrupt is then enabled, and a start pulse is issued in its service routine, generating eight 40kHz ultrasonic pulses. These pulses are emitted by the ultrasonic head, and the reflected waves are received, amplified by multiple bandpass amplifiers, and detected. Then, an analog-to-digital converter is initiated to read the envelope value and display the echo signal on the screen. The sampling width is 12 bits, the rate is 3.4 ksps, the horizontal axis of the curve is 8M, and the vertical axis is the echo intensity (not calibrated).
The rainfall detection logic is as follows:
1. If the echo increases and persists for a period of time, such as 30 seconds, it is determined to be rainfall.
2. Rainfall intensity is used to determine whether it is heavy, moderate, or light.
The calibration of rainfall amount requires the relationship between ultrasonic echo and rainfall, which has not yet been implemented.
Regarding sensitivity, this solution is not sensitive enough for "drizzle." The following measures can be taken to improve it: a) Increase the frequency, such as 1MHz~10MHz, based on the characteristics of ultrasonic waves. b) Increase the transmission power. c) Add a conical "horn" to the ultrasonic head.
Software code
/Ultrasonic Rainfall Radar V.1.0 20240916 Zhang Yu 18566289792
Color definitions
BLACK 0x0000 ///
< 0, 0, 0 NAVY 0x000F ///< 0, 0, 123
DARKGREEN 0x03E0 ///< 0, 125, 0
DARKCYAN 0x03EF ///< 0, 125, 123
MAROON 0x7800 ///< 123, 0, 0
PURPLE 0x780F ///< 123, 0, 123
OLIVE 0x7BE0 ///< 123, 125, 0
LIGHTGREY 0xC618 ///< 198, 195, 198
DARKGREY 0x7BEF ///< 123, 125, 123
BLUE 0x001F ///< 0, 0, 255
GREEN 0x07E0 ///< 0, 255, 0
CYAN 0x07FF ///< 0, 255, 255
RED 0xF800 ///< 255, 0, 0
MAGENTA 0xF81F ///< 255, 0, 255
YELLOW 0xFFE0 ///< 255, 255, 0
WHITE 0xFFFF ///< 255, 255, 255
ORANGE 0xFD20 ///< 255, 165, 0
GREENYELLOW 0xAFE5 ///< 173, 255, 41
PINK 0xFC18 ///< 255, 130, 198
/
include
Ticker tk1;
include
include
define TFT_CS 5
define TFT_RST 13
define TFT_DC 15
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
//mosi-23,clk-18
const int tPin = 4;
const int ePin = 2;
float dis;
unsigned int dat[160];
double tt;
boolean rr=true;
const int adcPin=34;
include "DHT20.h"
DHT20 DHT;
float humiD20;
float tempD20;
//--------------------------------------------------------
void setup(void) {
// Serial.begin(115200);
pinMode(tPin,OUTPUT);
pinMode(ePin,INPUT);
tft.initR(INITR_BLACKTAB);
tft.setRotation(1);//Horizontal screen
tft.invertDisplay(false);
tft.setTextSize(1);
attachInterrupt(ePin,cbk,CHANGE);
tk1.attach_ms(1000, tk1s);
Wire.begin();
DHT.begin();//SDA,SCL
}
//--------------------------------------------------------
void loop()
{
while(DHT.read()!=0){}
humiD20 = DHT.getHumidity();
tempD20 = DHT.getTemperature();
}
//--------------------------------------------------------
void tk1s()
{
tft.fillScreen(ST77XX_BLACK);
digitalWrite(tPin,LOW);delayMicroseconds(2);
digitalWrite(tPin,HIGH);delayMicroseconds(10);digitalWrite(tPin,LOW);
delayMicroseconds(3500);//8 ultrasonic pulses are emitted 2ms after the start pulse is emitted, 2250
tt=micros();
for(int i=0;i<160;i++)
{dat[i]=analogRead(adcPin)+analogRead(adcPin);delayMicroseconds(115); }//Get to 47ms
// tft.setCursor(0,16);tft.print(micros()-tt);tft.println("uS");
// for(int i=0;i<159;i++){ tft.drawLine(i,127-dat[i]/32, i+1,127-dat[i+1]/32,ST77XX_WHITE);}
tft.setTextColor(ST77XX_YELLOW); tft.setCursor(0,3);tft.print(dis);tft.print("cm ");
tft.print(tempD20);tft.print("C ");tft.print(humiD20);tft.print("%");
//----------------------------------------------------------------
for(int i=0;i<159;i++){ tft.drawLine(i,127-dat[i]/32, i+1,127-dat[i+1]/32,ST77XX_WHITE);}
axis();
}
//----------------------------------------------------------------
void cbk()
{if (digitalRead(ePin)&&rr){tt=micros();rr=false;}
if (!digitalRead(ePin)&&!rr)
{rr=true;dis=(micros()-tt)/58.00;}
}
//----------------------------------------------------------------
void axis()
{ for (int y=13;y<=127;y+=19){tft.drawFastHLine(0,y,152,0x0202);}
for (int x=0;x<=152;x+=19){tft.drawFastVLine(x,13,121,0x0202);}
tft.setTextSize(1); tft.setTextColor(ST77XX_MAGENTA);
for (int i=0;i<=8;i++){tft.setCursor(i19, 121);tft.print(i);}//x-axis number
for (int i=0;i<=6;i++){tft.setCursor(152, i19-9);tft.print(7-i);}//y-axis number
}