DIY IoT Rain Gauge & Weather Station (Raspberry Pi Pico W)
by Qis in Circuits > Raspberry Pi
371 Views, 1 Favorites, 0 Comments
DIY IoT Rain Gauge & Weather Station (Raspberry Pi Pico W)
When Software Engineers Touch Grass
Hi everyone!
We are Synced4IoT, a team of Computer Science (Software Engineering) students from Universiti Malaysia Terengganu (UMT). Usually, you’ll find us indoors debugging code in air-conditioned labs.
But recently, our lecturer gave us a wild challenge: Turn our campus into a "Living Laboratory."
His order was simple: "Build a weather station from scratch, go outside, and survive the monsoon season!"
So, we swapped our keyboards for soldering irons and muddy boots. Our mission? To build a DIY Tipping Bucket Rain Gauge that tracks rainfall, temperature, and humidity, and pushes data to the cloud in real-time.
We faced bugs (the coding kind AND actual insects), fried some wires, and learned that nature is unpredictable. Here is the story of how we built it. Let’s get making!
Supplies
To build a station that survives tropical storms, you need the right gear. Here is our checklist:
The Electronics
- Raspberry Pi Pico W: The WiFi-enabled brain.
- Hall Effect Sensor: We used this instead of a Reed Switch for smoother operation.
- DHT11 Sensor: For temperature & humidity.
- Powerbank (20,000mAh): Keeps the station alive for up to 14 days!
- Breadboard, Jumper Wires & USB Cable: For connections.
The Hardware (MacGyver Style)
- 3D Printed Parts: Funnel, Bucket, and Base.
- IP56 Waterproof Box (20x25x10cm): The main housing.
- Plastic Container (28x18x11cm): Modified to be the rain gauge holder.
- Mesh: Essential to filter bugs/leaves.
- Neodymium Magnet: The trigger.
- Bolt & Nut: The axle for the bucket.
- Plastic Bottle: Upcycled as a shield for the DHT11 sensor.
- Cable Glands: To seal wire entries.
- Clay & Hot Glue: For waterproofing gaps.
- Conformal Coating: To protect the PCB from humidity.
Tools
The Tipping Mechanism (Heart of the Project)
The heart of this project is the DIY Rain Gauge. We used a Tipping Bucket mechanism.
How it works: A funnel directs rain into a seesaw-like rocker. When one side fills up, it tips over using gravity. A magnet attached to the rocker swings past a sensor (we used a Hall Effect Sensor), sending a digital signal to the Pico W.
3D Printing the Parts: We used 3D-printed parts for the mechanism. We have attached the STL files below so you can replicate this project easily. Here is the file breakdown:
- The Base (Base 2.stl): Holds the sensor and electronics foundation.
- The Tipping Bucket (Cucchiaio 2.stl): The rocker mechanism itself.
- The Funnel (Imbuto 2.stl): Directs the rain into the bucket.
Print Settings: We recommend using PLA or PETG filament. An infill of 15% or higher is suggested for durability against the weather.
ASSEMBLY INSTRUCTIONS:
1. The Axle: We used a Bolt & Nut to hold the tipping bucket in the center.
- Critical Tip: Do not tighten the nut too much! The bucket must swing freely. We used Hot Glue between the nut and bolt to lock it in place without clamping down on the bucket.
2. The Sensor Upgrade (Hall Effect vs. Reed Switch): Originally, we planned to use a Reed Switch. However, we found that the magnetic pull was too strong and caused the bucket to get stuck.
- The Fix: We upgraded to a Hall Effect Sensor. It detects the Neodymium Magnet glued to the bucket digitally.
- The Result: Zero friction and smooth tipping!
The "Tupperware" Hack (DIY Stand)
Instead of building a complicated metal stand to hold the rain gauge, we hacked a plastic storage container.
- The Holder: We cut the lid of the container to fit the 3D-printed rain gauge base perfectly. The rain gauge sits inside, protected but stable.
- Drainage: We drilled 4 holes at the corners and cut square openings at the bottom.
- Protection:
- Mesh Filter: We glued a Mesh over the funnel to stop insects or leaves from entering.
- Sealing: We used Clay and a Hot Glue around the edges where the rain gauge meets the container to prevent leaks.
Why drill holes? As you can see in the photos, the holes ensure rainwater flows out immediately. We want to measure the rain, not store it!
Electronics & Soldering
Time to connect the brains. We used a Raspberry Pi Pico W because it’s affordable, supports MicroPython, and has built-in WiFi.
1. Soldering We soldered header pins to the Pico W so it fits securely into the breadboard (or you can solder wires directly for a permanent fix).
2. The Wiring Guide Here is the detailed connection breakdown:
- DHT11 (Temperature & Humidity)
- Signal: Connect to GP15.
- VCC (+): Connect to 3V3 (Physical Pin 36).
- GND (-): Connect to any GND pin (Physical Pin 38).
- Rain Gauge (Hall Effect Sensor)
- Signal: Connect to GP16.
- Ground: Connect to any GND pin.
- Note: The code uses machine.Pin.PULL_UP. This means you do not need an external resistor. Simply connect one wire to GP16 and the other to Ground. When the bucket tips (magnet passes), it closes the circuit, triggering the count.
- LED Indicator
- No external wiring required. We utilize the Pico’s Onboard LED. The code flashes this to show the "heartbeat" and successful data uploads.
- Power Source
- Connect your Power Bank to the Micro-USB port.
- Tip: Our code includes a "Keep-Alive" function that pulses the power draw to prevent modern power banks from auto-shutting off.
3. Waterproofing (Crucial!) Once the wiring was tested, we applied Conformal Coating to all exposed connections on the sensor side. This is a vital step to prevent humidity from corroding the circuit when deployed outdoors.
Boxing It Up (Final Assembly)
We placed all the sensitive electronics into the IP56 Waterproof Box.
- Cable Management: We drilled holes in the box and used Cable Glands to route the wires from the rain gauge (outside) to the Pico (inside). This keeps the box watertight.
- Power: The 20,000mAh Powerbank fits inside perfectly. After 7 days of operation, it still had plenty of charge left.
- The "Bottle Shield": The DHT11 sensor needs to be outside to measure air temp, but it can't get wet.
- Solution: We cut a Plastic Bottle, glued it to the outside of the box, and hid the sensor inside it. It acts as a perfect umbrella!
Calibration (Crucial Step!)
A rain gauge is useless if it's not accurate. To calibrate ours, we utilized a beaker to measure the water volume.
The Process:
- We filled a beaker with a known volume of water (100ml).
- We slowly poured the water through the 3D-printed funnel to simulate rain.
- We counted the total number of "tips" registered by the microcontroller.
- By dividing the Total Volume by the Number of Tips, and factoring in the surface area of our funnel, we calculated the specific rainfall depth per tip.
The Result: We found that one tip equals exactly 0.173 mm of rainfall.
The Code (MicroPython)
With the electronics ready, we flashed the code. We used MicroPython on the Raspberry Pi Pico W. The code handles three main tasks:
- Connects to WiFi.
- Counts Tips: Uses an Interrupt (IRQ) to detect when the bucket tips.
- Uploads Data: Sends the rainfall (mm), temperature, and humidity to ThingSpeak every 30 minutes.
Critical Configuration: In the code, you will see the variable MM_PER_TIP = 0.173. This value is not random but it is the specific result we obtained from the Water Calibration (Step 5) we did. You must update this variable with your own calibration result to ensure the rain data is accurate!
Code Snippet: Here are the critical parts you need to configure in main.py:
Note: The snippet above highlights the key logic. Please download the full main.py file attached below for the complete code including error handling and the 'Power Bank Keeper' feature.
Downloads
Data & Dashboard
Sending data to the cloud is what makes this a true "Living Laboratory." We used ThingSpeak as our analytics platform because it is free, easy to use, and integrates perfectly with MicroPython.
How it connects:
- Data Acquisition: The Pico W collects readings from the sensors.
- Transmission: Every 30 minutes, the Pico connects to WiFi and sends a data packet via HTTP to the ThingSpeak API.
- Visualization: ThingSpeak instantly plots this data onto live graphs.
Why use a Dashboard?
- Real-Time Monitoring: We can check the weather from anywhere without walking to the field.
- Data History: It allows us to track trends like "It rained heavily between 2:00 PM and 4:00 PM".
- Accessibility: The data can be shared publicly, turning our device into a community resource.
Setting Up ThingSpeak (Required)
Before running the code, you need to generate an API Key. Follow these steps:
- Create an Account: Go to ThingSpeak.com and sign up for a free account.
- New Channel: Click "New Channel".
- Configure Fields: Name your channel for example "Smart Rain Gauge" and enable the first 3 boxes:
- Field 1: Temperature
- Field 2: Humidity
- Field 3: Rainfall
- Save Channel: Scroll down and click "Save Channel".
- Get the API Key:
- Click on the "API Keys" tab.
- Copy the "Write API Key".
- Go back to your MicroPython code (main.py) and paste this key into the THINGSPEAK_API_KEY variable.
Now, when you run the Pico, you will see the charts populate automatically!
Deployment
Date: January 2nd, 2026 Location: UMT Campus Open Field
Choosing the right spot was critical for data accuracy. We adhered to WMO (World Meteorological Organization) guidelines for site selection:
- The "2x Height" Rule: We placed the station in a wide open area, far away from tall trees and buildings/walls.
- Why? Obstacles like walls block the wind-blown rain, causing a "rain shadow" which leads to inaccurate low readings. Trees can also drip extra water into the funnel.
- Stability: We used heavy bricks to weigh down the stand legs.
- Labeling: We attached a project tag (Synced4IoT) to the stand. This ensures that campus security or groundskeepers identify it as an active student project and not abandoned trash.
- Leveling: We ensured the rain gauge was perfectly horizontal so the tipping bucket works consistently.
The Result: The system ran continuously for 7 days, surviving strong winds and heavy rain without tipping over!
Final Results & Conclusion
So, Did We Survive?
We are incredibly happy to report that... IT WORKED!
Not only did we survive the outdoors, but our station did too. For 7 full days, our DIY setup braved the wind and rain, pinging us with fresh data every 30 minutes without a single hiccup.
This journey was a huge eye-opener for us. As Computer Science students, we learned that IoT isn't just about writing code in a comfortable lab. It's about sturdy hardware, muddy boots, and creative problem-solving. Who knew a Tupperware container and a plastic bottle could be so scientific?
We hope you enjoyed reading about our adventure. Thank You!
Made by Synced4IoT CSM3313 IoT Computing, Universiti Malaysia Terengganu.