Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

Lesson 15: Raindrop Detection Module

In this lesson, you will learn how to use a raindrop detection sensor with an ESP32 Development Board. We’ll cover reading digital signals from the sensor when it detects rainwater and displaying this information on the serial monitor. This project provides an engaging way to grasp digital input and output in microcontroller programming, making it ideal for beginners in electronics and coding with the ESP32 platform.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Universal Maker Sensor Kit

94

Universal Maker Sensor Kit

You can also buy them separately from the links below.

Component Introduction

Purchase Link

ESP32 & Development Board (ESP32 Board)

BUY

Raindrop Detection Module

BUY

Breadboard

BUY

Wiring

../_images/Lesson_15_Raindrop_Detection_Module_esp32_bb.png

Code

Code Analysis

  1. Defining sensor pin

    Here, a constant integer named sensorPin is defined and assigned the value 25. This corresponds to the digital pin on the ESP32 Development Board where the raindrops detection sensor is connected.

    const int sensorPin = 25;
    
  2. Setting up the pin mode and initiating serial communication.

    In the setup() function, two essential steps are performed. Firstly, pinMode() is used to set the sensorPin as an input, enabling us to read digital values from the raindrops sensor. Secondly, serial communication is initialized with a baud rate of 9600.

    void setup() {
      pinMode(sensorPin, INPUT);
      Serial.begin(9600);
    }
    
  3. Reading the digital value and sending it to the serial monitor.

    The loop() function reads the digital value from the raindrops sensor using digitalRead(). This value (either HIGH or LOW) is printed to the Serial Monitor. When raindrops are detected, the serial monitor will display 0; when no raindrops are detected, it will display 1. The program then waits for 50 milliseconds before the next reading.

    void loop() {
      Serial.println(digitalRead(sensorPin));
      delay(50);
    }