DIY IoT Rain Gauge & Weather Monitoring System Using Raspberry Pi Pico W
by Hemasangari in Circuits > Raspberry Pi
129 Views, 0 Favorites, 0 Comments
DIY IoT Rain Gauge & Weather Monitoring System Using Raspberry Pi Pico W
This project presents a DIY IoT-based environmental monitoring system designed for outdoor campus deployment. The system measures rainfall, air temperature, humidity, and water temperature using a combination of off-the-shelf sensors and a custom-built tipping bucket rain gauge.
Rainfall is detected using a mechanical tipping bucket mechanism combined with a Hall effect sensor and processed by a Raspberry Pi Pico W. All sensor data is transmitted wirelessly to the cloud and visualised on a custom ThingSpeak dashboard, allowing real-time and remote monitoring.
Sensor readings are recorded automatically at 30-minute intervals to ensure stable operation while conserving power. This project was developed as part of an IoT Computing group project and provides clear, step-by-step documentation so that other students can easily replicate, modify, and deploy the system for environmental monitoring applications.
Supplies
To build this DIY IoT rain gauge system, you will need a combination of electronic components, mechanical parts, and basic tools for assembly and deployment.
Electronics
- Raspberry Pi Pico W (used for sensor reading and wireless data transmission)
- DHT22 Temperature and Humidity Sensor
- DS18B20 Waterproof Temperature Sensor
- Hall Effect Sensor Module (used to detect tipping bucket movement)
- Neodymium Magnet (attached to the tipping bucket)
- Breadboard
- Jumper Wires (Male–Male / Male–Female)
- USB Cable (for programming the Pico W)
- Portable Power Bank (used as the power source)
Hardware & Enclosure
- Weatherproof PVC Enclosure (to house the electronics)
- Cut Plastic Bottle (used as a protective cover for the water temperature sensor connection)
- 3D-Printed Tipping Bucket Rain Gauge Housing
- Funnel (to collect rainwater)
- Electrical Tape (used for insulating and bundling wires, and for extending cable length)
- Plastic Container or Housing (for rain gauge body)
- PVC Pipe (to protect the water temperature sensor cable)
- Screws, Nuts, and Washers (for mounting the rain gauge)
- Glue (for cable sealing and waterproofing)
Tools
- Drill (for making mounting and cable entry holes)
- Screwdrivers
- Hot Glue Gun
The System Architecture (IoT Flow)
This system follows a complete end-to-end IoT architecture consisting of three main layers: sensing, communication, and application.
At the sensing layer, multiple sensors are used to measure rainfall, air temperature, humidity, and water temperature. The Raspberry Pi Pico W collects data from these sensors at fixed intervals.
At the communication layer, the Pico W sends sensor data wirelessly to the cloud using its built-in Wi-Fi capability.
At the application layer, ThingSpeak is used to store and visualise the data on a custom-designed dashboard that can be accessed remotely.
The figure below illustrates the complete working flow of the system, from rainfall collection and bucket tipping to sensor detection, data processing, and cloud visualisation.
Environmental Parameters Collected
The system collects four parameters:
- Water Temperature (DS18B20)
- Air Temperature & Humidity (DHT22)
- Rainfall (DIY tipping bucket + Hall effect sensor)
All data is recorded every 30 minutes and transmitted to the cloud.
Images above show the actual sensors used for air temperature, humidity, water temperature, and rainfall detection.
Circuit Wiring Using Raspberry Pi Pico W
All sensors share a common 3.3V (3V3) and GND to reduce wiring complexity and ensure stable voltage. Separate GPIOs are used for each signal to avoid interference and simplify debugging.
- DHT22 → GPIO 15 (air temp & humidity)
- DS18B20 → GPIO 2 (water temperature)
- Hall Effect Sensor → GPIO 0 (rainfall pulses)
Wiring photos show Pico placement, jumper routing, and connections. Use them together with the details below to reproduce the circuit accurately.
Wiring Details:
Rain Gauge (Hall Effect Sensor)
- Signal: GPIO 0 (Pin 1) – Yellow wire
- VCC: 3.3V (Pin 30) – Red wire
- GND: Pin 25 – Black wire
DHT22 (Air Temperature & Humidity)
- Data: GPIO 15 (Pin 20) – White/Yellow wire
- VCC: 3.3V (Pin 30) – Red wire
- GND: Pin 25 – Black wire
DS18B20 (Water Temperature)
- Data: GPIO 2 (Pin 4) – Yellow wire
- VCC: 3.3V (Pin 30) – Red wire
- GND: Pin 18 – Black wire
How the Tipping Bucket Rain Gauge Works
The rain gauge used in this project operates based on the tipping bucket principle. Rainwater is collected through the funnel (Part 1) and directed into a small dual-chamber tipping bucket mechanism (Part 2) located inside the rain gauge housing.
- As rainwater accumulates in one side of the tipping bucket (Part 2), its weight gradually increases.
- Once a fixed volume of water is reached, the bucket tips to the opposite side and empties the collected water.
- This tipping action resets the bucket and allows the next measurement cycle to begin.
Each bucket tip represents a known amount of rainfall.
- By counting the number of tipping events over time, the system is able to calculate total rainfall in millimetres.
- The calculated rainfall data is then transmitted and displayed on the dashboard.
As shown in the exploded diagram above, the rain gauge consists of the following main components:
- Funnel (Part 1) – Collects rainwater and directs it into the tipping bucket.
- Tipping bucket mechanism (Part 2) – Alternates between two chambers to measure rainfall volume.
- Protective grid (Part 3) – Prevents leaves, insects, and debris from entering the funnel.
- Housing (Part 4) – Encloses the internal mechanism and provides structural support.
- Sensor cable – Connects the internal Hall effect sensor to the microcontroller.
This numbered component layout allows the rain gauge to be easily assembled, understood, and replicated by others following this documentation.
Magnetic Detection Using a Hall Effect Sensor
Instead of using a mechanical reed switch, this project uses a Hall effect sensor to detect the movement of the tipping bucket. A small magnet is attached to the bucket, and the Hall effect sensor is mounted inside the rain gauge housing along the path of the magnet.
When the bucket tips, the magnet passes close to the Hall effect sensor and produces a digital output pulse. This pulse is detected by the Raspberry Pi Pico W and counted as a single rainfall event. Each detected pulse corresponds to one bucket tip.
Using a Hall effect sensor improves system durability by eliminating mechanical contact and reducing wear. This makes the rain gauge more reliable and suitable for long-term outdoor deployment. The image above shows the actual Hall effect sensor module used to detect the tipping motion of the rain gauge bucket.
Assembling the DIY Rain Gauge
The rain gauge assembly begins by positioning the tipping bucket mechanism securely inside the rain gauge housing.
- The bucket is checked to ensure it can move freely and tip smoothly without any obstruction, as accurate movement is essential for reliable rainfall measurement.
Next, the Hall effect sensor is fixed inside the housing at a position where the magnet attached to the tipping bucket passes closely during each tip.
- The distance between the magnet and the sensor is carefully adjusted to ensure consistent and reliable pulse detection without physical contact.
Once the internal components are secured, the rain gauge housing is placed on top of the weatherproof enclosure to determine the correct mounting position.
- Mounting points are marked, and mounting holes are drilled on the enclosure lid.
The rain gauge housing is then secured to the enclosure using screws.
- All screws are tightened firmly to ensure the housing remains stable and does not shift due to wind or heavy rainfall during outdoor deployment.
This mounting method provides both mechanical strength and long-term durability for outdoor use.
Weatherproof Enclosure Design
To ensure reliable outdoor operation, all electronic components are housed inside a weatherproof PVC enclosure. Cable entry points are carefully sealed using glue and to prevent water ingress and protect the internal electronics.
The rain gauge is mounted on top of the enclosure to allow direct and unobstructed rainfall collection. The water temperature sensor cable is routed through a PVC pipe, which provides additional protection against physical damage and environmental exposure.
A cut plastic bottle is used as a protective cover for the water temperature sensor connection. The bottle helps shield the sensor wiring and connector from direct exposure to water, dirt, and debris while still allowing the sensor probe to remain in contact with the water.
Using a recycled plastic bottle provides a lightweight, waterproof, and low-cost solution that is easy to modify and replace if needed. This approach also improves durability during outdoor deployment without adding significant cost to the system.
The image above shows the PVC electrical enclosure box used to house the Raspberry Pi Pico W and other electronic components. An IP-rated PVC enclosure was selected to provide protection against dust and water, ensuring long-term durability and safe outdoor operation of the system.
Temperature Sensor Calibration
Initial testing showed the DHT22 reading higher than local ambient values from a weather app. A constant −20 °C offset was applied in code to correct this systematic error.
This practical calibration is sufficient for relative environmental monitoring, which is the project’s objective, rather than laboratory-grade accuracy.
ThingSpeak Configuration
ThingSpeak was used as the cloud platform for data storage and visualisation. A custom dashboard was designed with a focus on clear UI/UX to make the data easy to understand.
This is step by step to connect with ThingSpeak :
- Log into the ThingSpeak account.
- Create new channel and name after the team's name. Add some description (if needed).
- Add the field of parameters to be measured. In this case, we are measuring:
Field 1: Temperature
Field 2: Humidity
Field 3: Water Temperature
Field 4: Rainfall
Field 5 : Master Switch (to turn off and on the switch, optional)
- Save the channel.
- Get the API keys for setting on Thonny coding and HTML dashboard coding.
The data will be represented in graph which x-line is time recorded and y-line is the data measurement numbers.
Programming the System Using Thonny
The Raspberry Pi Pico W was programmed using MicroPython through the Thonny IDE, chosen for its direct MicroPython support and ease of debugging and deployment.
Core Program Functions
The program performs the following functions:
- Reads data from all connected sensors
- Counts rainfall events from the tipping bucket rain gauge using an interrupt-based approach
- Applies a manual temperature calibration offset (−20.0 °C) to the air temperature readings
- Uploads sensor data to ThingSpeak using HTTP requests
- Sends data at 30-minute intervals to balance power consumption and data resolution
Wi-Fi Configuration and Connectivity
The Pico W connects to a local Wi-Fi network to enable cloud communication with ThingSpeak.
- Wi-Fi credentials are defined in the configuration section of the code
- A stable Wi-Fi connection is required to prevent data loss
- The on-board LED turns on when the Pico W is successfully connected to Wi-Fi
If Wi-Fi connectivity is lost during operation, the system attempts to reconnect automatically. If reconnection fails, the Pico W performs a full reset to restore network functionality.
Autonomous Operation and Reliability
This firmware turns the Pico W into a fully autonomous environmental monitoring system designed for long-term outdoor deployment.
- The script runs continuously in a main loop that manages:
- Wi-Fi connectivity
- Sensor acquisition
- Data upload to ThingSpeak
- On startup, the system:
- Waits briefly for stabilization
- Initializes all sensors
- Starts a Watchdog Timer (WDT)
Watchdog Timer (Fail-Safe Mechanism)
A Watchdog Timer with an 8-second timeout is used as a fail-safe mechanism.
- The watchdog must be regularly “fed” by the program
- If the program freezes, encounters a network error, or becomes unresponsive, the watchdog automatically resets the Pico W
- This prevents the system from remaining stuck during long unattended deployments
ThingSpeak Integration
ThingSpeak is used for cloud data storage and visualization.
The following credentials are required:
- Channel ID
- Read API Key
- Write API Key
- The Channel ID is located at the top of the ThingSpeak channel page
- The API keys are found in the API Keys section
- All sensor readings are uploaded and recorded on the ThingSpeak platform
Sensor Data Acquisition Method
Two different data acquisition methods are used, depending on sensor type.
Rain Gauge (Interrupt-Type Sensor)
- The rain gauge is connected to an interrupt pin
- Each bucket tip immediately triggers an interrupt
- Rainfall is counted in the background without blocking the main program
- This ensures no rainfall events are missed, even during data uploads
Temperature Sensors (Polled-Type Sensors)
- DHT22 is used for air temperature and humidity
- DS18B20 is used for water temperature
- These sensors are read sequentially during each measurement cycle
A manual calibration offset of −20.0 °C is applied to the air temperature readings to compensate for internal enclosure heating effects.
Remote Control (Master Switch)
A remote Master Switch is implemented using ThingSpeak.
- Before collecting sensor data, the Pico W checks a designated ThingSpeak field
- If the field value is:
- 1 → The system measures sensors and uploads data
- 0 → The system enters standby mode
This allows the system to be remotely enabled or disabled during maintenance periods or dry seasons without physical access.
Smart Sleep Routine (Power Conservation)
To conserve power without triggering the Watchdog Timer:
- The 30-minute sleep interval is divided into 5-second sleep cycles
- During each cycle, the system:
- Feeds the Watchdog Timer
- Briefly wakes up
- Blinks the status LED
- Returns to sleep
This approach allows stable, long-term operation while preventing watchdog resets during extended sleep periods.
Error Handling and System Recovery
If a critical error occurs inside the main loop:
- The system waits briefly
- A full system reset is triggered using machine.reset()
This ensures the Pico W can recover automatically from unexpected runtime failures.
Custom Dashboard
The dashboard displays system status, water temperature, ambient temperature, humidity, and rainfall rate. All values are updated automatically every 30 minutes and can be viewed remotely using a web browser or mobile device.
Full HTML code for dashboard :
Testing the Rain Gauge Using Water
Before outdoor deployment, the rain gauge was tested using water to verify correct operation. Water was slowly poured into the funnel to simulate rainfall under controlled conditions.
During testing, each tipping action of the bucket was visually observed and compared with the pulse count received by the Raspberry Pi Pico W. The Hall effect sensor successfully detected each bucket tip and generated a corresponding digital pulse.
The detected pulses were transmitted to the cloud and displayed correctly on the dashboard as rainfall data. This testing confirmed that the rain gauge assembly, magnetic detection, and data transmission were functioning properly before long-term outdoor deployment.
System Deployment and Testing
After successful bench testing, the complete system was deployed outdoors at a selected campus location near a water source. The weatherproof enclosure was placed on a stable surface, and the rain gauge was mounted on top to allow unobstructed rainfall collection.
The water temperature sensor was positioned securely in the water, while the air temperature and humidity sensor remained inside the enclosure with sufficient ventilation. All cable connections were checked to ensure they were firmly secured and protected from environmental exposure.
The system was powered using a portable power bank, allowing flexible deployment without the need for a fixed power source. During deployment, the system operated continuously and transmitted sensor data automatically at 30-minute intervals.
Field testing confirmed stable operation, reliable sensor readings, and consistent updates on the cloud dashboard under real outdoor environmental conditions.
Conclusion
This project delivers a complete DIY IoT rain gauge system with reliable sensing, cloud visualization, and outdoor durability. Using a Hall effect sensor improves longevity, while practical calibration and testing ensure meaningful data.
All materials, wiring, assembly steps, calibration methods, and configurations are documented so others can fully replicate the system using readily available components.