### 5.4 Rain Detection System #### 5.4.1 Steam Sensor ![cou41](../media/cou41.png) Steam sensor detects the presence of water, so it is usually used in rain detection. If the rain hits the conductive pads on the sensor, it will send a signal to the Arduino board. ![couy41](../media/couy41.png) **Parameters**: - Voltage: 3~5V - Current: 1.5mA - Power: 7.5mW Open the **5.4.1Alarm-System** code with Arduino IDE. ```c #define SteamPin 35 //Define the steam sensor pin to 35 void setup() { Serial.begin(9600); pinMode(SteamPin,INPUT); } void loop() { //Read the value of steam sensor int ReadValue = analogRead(SteamPin); Serial.print("Steam Value: "); Serial.println(ReadValue); delay(500); } ``` Choose the **ESP32 Dev Module** board and **COM** port, and upload the code. ![5458448](../media/5458448.png) **Test Result:** Touch the detection area with your finger. The larger the area you touched is, the larger the valuewill be. You can open the serial monitorto observe the currently detected value (range: 0~4095). ![image-20250417131110395](../media/image-20250417131110395.png) #### 5.4.2 Rainwater Detection System Open the **5.4.2Rainwater-Detection-System** code with Arduino IDE ```c #define SteamPin 35 //Define pins #define BuzzerPin 16 void setup() { Serial.begin(9600); pinMode(SteamPin,INPUT); pinMode(BuzzerPin,OUTPUT); } void loop() { //Read the value of steam sensor int ReadValue = analogRead(SteamPin); Serial.print("Steam Value: "); Serial.println(ReadValue); //Determine whether the detected value is within 800~2000 if(ReadValue >= 800 && 2000 > ReadValue){ //Execute for 3 times for (int i = 0; i < 3; i++) { tone(BuzzerPin,200); delay(100); noTone(BuzzerPin); delay(100); } } //Determine whether the detected value is within 2000~4000 else if (ReadValue >= 2000 && 4000 >= ReadValue) { for (int i = 0; i < 3; i++) { tone(BuzzerPin,400); delay(100); noTone(BuzzerPin); delay(100); } } //Determine whether the detected value is greater than 4000 else if (ReadValue > 4000) { for (int i = 0; i < 3; i++) { tone(BuzzerPin,600); delay(100); noTone(BuzzerPin); delay(100); } } noTone(BuzzerPin); delay(500); } ``` Choose the **ESP32 Dev Module** board and **COM** port, and upload the code. ![5458448](../media/5458448.png) **Test Result:** The greater the detected value of the steam sensor is, the loader the sound emitted by the buzzer will be. ![flo4](../media/flo4.png)