EdgeLink: DIY Digital Rain Gauge & Weather Station With Raspberry Pi Pico
by _amirazl13 in Circuits > Raspberry Pi
175 Views, 1 Favorites, 0 Comments
EdgeLink: DIY Digital Rain Gauge & Weather Station With Raspberry Pi Pico
In this project, we are building a precise Tipping Bucket Rain Gauge and Weather Station using a Raspberry Pi Pico. We will use a Hall Effect sensor to detect the tipping motion of the bucket (to count rainfall) and a BME280 sensor to monitor temperature, humidity, and atmospheric pressure.
A Note on Credit: The mechanical design for the tipping bucket and funnel in this project is based on the excellent "DIY Arduino Rain Gauge" by vandenbrande. We have adapted the electronics to run on the more powerful Raspberry Pi Pico W with IoT capabilities, but the genius mechanical mechanism remains the same. You can check out the original inspiration here: DIY Arduino Rain Gauge.
Supplies
To build this station, you will need a mix of electronics and hardware for the enclosure.
Electronics:
- Microcontroller: Raspberry Pi Pico (W version is optional but great for future cloud upgrades).
- Sensors:
- BME280 (Temperature, Humidity, Pressure). Get it on Shopee
- A3144 Hall Effect Sensor (We will use this in Analog mode for higher sensitivity). Get it on Shopee
- Components:
- Neodymium Magnet (Small but strong). Get it on Shopee
- Jumper Wires for Breadboard
- Breadboard or Prototype PCB.
Hardware & Enclosure:
- M4 Stainless Steel threaded rod (< 8.8mm of diameter).
- M4 Self-locking nuts and washers.
- PVC Enclosure (Waterproof box for the electronics). Get it on Shopee
- Plastic container (housing for the rain gauge mechanism).
- Metal Mesh (To cover the gauge intake to keep out bugs and leaves).
Tools:
- 3D Printer (For the tipping bucket mechanism).
- Hot Glue Gun.
- Soldering Iron & Solder.
- Drill.
- Wrenches/Pliers.
- Software: Thonny IDE (for programming the Pico).
The Concept (How It Works)
- The Tipping Bucket: Rain falls into a funnel and fills one side of a small 3D-printed "see-saw" bucket. When it gets heavy enough, it tips over, dumping the water and lifting the other side.
- The Magnet: We attach a small magnet to the bucket.
- The Sensor: As the bucket tips, the magnet passes a Hall Effect Sensor.
- The Code: The Pico detects this magnetic change, counts it as "1 tip," and calculates the rainfall (in our case, 0.173mm per tip).
Wiring the Electronics
We are using a "Split" configuration, powering both sensors from the Pico's 3.3V rail.
Common Power Connections:
- Pico 3V3 (Pin 36): Red (+) Rail.
- Pico GND (Pin 38): Blue (-) Rail.
1.Connecting the BME280 (I2C)
Note: The BME280 communicates via I2C. We are using the default I2C0 pins.
2.Connecting the Hall Effect Sensor (Analog Setup)
Note: While many use Hall sensors as digital switches, we are connecting this to an Analog Pin (ADC). This allows us to tune the sensitivity in software and avoid false triggers.
Assembly and Housing
This is the most critical part of the build. If the bucket sticks, you lose rain data. If the sensor is misaligned, the Pico won't detect the tips.
1. Get the 3D Printed Parts
The mechanical design for the tipping bucket and funnel is based on the proven "DIY Arduino Rain Gauge" by vandenbrande.
- Download the Files: You can get the .STL files for the Bucket and Funnel directly from the original project here: DIY Arduino Rain Gauge.
2. The "Pivot Sandwich" (Crucial Step)
We need the bucket to swing with almost zero friction. Assemble the M4 threaded rod in this exact order:
- Frame Wall
- Nut
- Washer
- [TIPPING BUCKET]
- Washer
- Nut
- Frame Wall
- Tuning: Tighten the inner nuts against the bucket only until they touch, then back them off slightly. The bucket should fall freely from one side to the other with a gentle tap. If it feels "sticky," loosen the nuts.
3. Magnet & Sensor Alignment
We are using the Hall Effect sensor in Analog Mode, so the distance is very important.
- The Magnet: Hot glue the Neodymium magnet into the slot on the side of the bucket. Important: Ensure the magnet is flush (flat) with the plastic surface. If it sticks out, it might hit the frame.
- The Sensor: Mount the Hall Effect sensor on the stationary frame directly opposite the magnet.
- The Gap: Ideally, when the magnet passes the sensor, the gap should be between 2mm and 4mm.
- Too close: The magnet might hit the sensor.
- Too far: The signal will be too weak for the Pico to detect.
4. Weatherproofing the Enclosure
- Mounting: Secure the Pico W and BME280 inside your waterproof PVC box.
- Cable Entry: Drill a hole for the wires running from the rain gauge to the box.
- Sealing: Once the wires are through, you must seal the hole completely with Silicone Sealant or a generous amount of Hot Glue. Moisture is the enemy of the BME280 sensor!
- Mesh: Glue the metal mesh over the top of the funnel to prevent leaves and bugs from clogging the drain hole.
The Code - Calibration & Logic
We are using MicroPython. Make sure you have the bme280.py library saved to your Pico before running this.
Why this code is special:
Instead of just looking for "Magnet" or "No Magnet," this code includes a calibration sequence. When you power it on, it measures the "resting" magnetic field. It then looks for a deviation from that baseline to detect a tip. This makes it much more reliable!
Testing
- Plug in your Pico via USB.
- Run the script in Thonny.
- Wait 2 seconds for the calibration (keep the magnet steady!).
- Manually tip your rain bucket. You should see the LED on the Pico flash, and the shell should print: *** TIP DETECTED! ***.
- Check the BME280 output to ensure you are getting Temperature and Pressure data.
If your rain gauge is counting too many tips, try increasing the HALL_THRESHOLD variable in the code (e.g., from 2000 to 3000).
Setting Up the Cloud Dashboard (ThingSpeak)
To see our weather data from anywhere in the world, we will send it to ThingSpeak. This platform allows us to store data and visualize it with charts and gauges.
Create a Channel
- Go to ThingSpeak.com and sign up for a free account.
- Click "New Channel".
- Name your channel (e.g., My Pico Weather Station
Configure the Fields
We need to tell ThingSpeak what data to expect. Enable the first 4 boxes and label them exactly like this to match our future code:
- Field 1: Temperature
- Field 2: Humidity
- Field 3: Pressure
- Field 4: Rainfall
Scroll down and click "Save Channel".
Visualizing the Data (Customizing the Look)
By default, ThingSpeak creates simple line charts. To create the "Weather Station Command Center" look shown in the project photos (with gauges and digital readouts), follow these steps:
1. Add "Numeric Displays" (For Current Values) Line charts show history, but numeric displays show the now.
- On your Channel view, click the "Add Widget" button.
- Select Numeric Display and click Next.
- Configure for Temperature:
- Name: Temperature
- Field: Select Field 1 (or whichever field you assigned to Temp).
- Units: Type °C in the box.
- Data Type: Select "Decimal" (this ensures you see 26.8 instead of just 26).
- Click Create.
- Repeat this process for Humidity (%) and Rainfall (mm).
2. Add the "Gauge" (For Pressure) The speedometer-style gauge is perfect for visualizing Atmospheric Pressure.
- Click "Add Widget" and select Gauge.
- Configure for Pressure:
- Name: Air Pressure
- Field: Select Field 3.
- Min/Max: Set Min to 900 and Max to 1100 (this covers the standard range of weather pressure in hPa).
- Units: hPa.
- Click Create.
3. Arrange Your Dashboard
- Click the Pencil Icon (Edit View) at the top of the page.
- Drag and drop the boxes to organize them.
- Recommendation: Place the Numeric Displays in a column on the right and the History Charts on the left for a clean, professional layout.
The Final Firmware
Now that we have tested the sensors and set up the cloud, it is time for the Final Firmware. This version is much smarter than our test scripts.
Features of this code:
- WiFi Fallback: It tries to connect 10 times. If it fails (e.g., router is down), it doesn't crash—it switches to "Offline Mode."
- Offline Data Queuing: If WiFi is down, it saves your weather data in memory. When WiFi returns, it automatically uploads all the missed data!
- Safety Boot: The system waits for a button press to start (preventing boot loops if code is bad).
- Remote Control: It checks ThingSpeak for commands (like turning the LED on/off remotely).
The Code
Copy the code below into main.py on your Pico W.
Configuration & User Manual
1. Configuration Guide
Before you save the code, look at the top section under 1. CONFIGURATION and fill in your details:
- WIFI_SSID: Your WiFi Network Name (Note: Pico W only supports 2.4GHz WiFi).
- WIFI_PASSWORD: Your WiFi Password.
- TS_WRITE_API_KEY: The "Write API Key" you copied from ThingSpeak.
- TS_READ_API_KEY: The "Read API Key" from ThingSpeak (for remote control).
- MM_PER_PULSE: Default is 0.173. Change this only if you calibrate your bucket and find it differs.
2. User Manual (How to Operate)
This firmware has built-in safety features and light signals so you know what it is doing.
A. Turning It On (Safety Boot)
To prevent the Pico from getting stuck in a crash loop on battery power, it has a Safety Boot:
- Plug in the power.
- The Shell will say: >>> HOLD BOOTSEL BUTTON TO START <<<.
- Press and Hold the white BOOTSEL button on the Pico.
- The LED will turn ON. Release the button.
- The system will now start normally.
- (Note: If the system restarts itself due to an error, it will skip this check and start automatically.)
B. LED Status Signals
The onboard LED tells you what is happening without needing a screen:
C. Offline Mode
If your WiFi goes down, the weather station will not stop.
- It will try to connect 10 times.
- If it fails, it saves the data to a "Queue" in memory.
- It goes to sleep and tries again in 3 minutes.
- Once WiFi returns, it will rapidly upload all the saved data to ThingSpeak automatically!
D. Manual Reset
If the system is acting strange, you don't need to unplug it.
- Press and hold the BOOTSEL button.
- Wait for 3 seconds.
- The Pico will reboot.
Installation & Power
1. Positioning Place the gauge in an open area, away from trees or buildings that might block the rain. Use a bubble level to ensure the rim is perfectly flat.
2. Powering the Station Since the Pico W uses WiFi, it consumes too much power for a small coin battery. You have two options:
- Option A (Easiest): Use a high-quality, long Micro-USB cable (3-5 meters) connected to a USB wall adapter indoors. Ensure the cable entry into the box is sealed tight.
- Option B (Portable): Use a USB Power Bank (like those for phones). A 10,000mAh power bank can run this station for about 2-3 days. For long-term use, you would need a solar charging system (which is a great upgrade for Version 2.0!).
Once you plug the power in, watch the LED on the Pico. If you see 5 Fast Blinks, congratulations! Your station has successfully connected to WiFi and is now uploading live weather data to the cloud. You are officially running your own micro-weather observatory!