You’ve been left at home in charge of the laundry. It’s already washed and hanging out to dry on the line. But you were warned – on pain of death – to bring it in if it starts to rain. The trouble is, you’re totally into whatever it is you’re coding right now and you won’t even notice if it rains. You’ll be toast if it rains and the laundry gets wet. So which is it to be? Code or laundry? That was your choice – until now!
Let’s Make a Rain Alert System
We’re going to use a simple raindrop sensor, a buzzer and a Pi to alert you when it rains. So you can get on with something useful instead of watching the weather. The components can all be found in a little kit on the RasPiO online shop.
To get an alert when it starts to rain, we’re going to rig this sensor up to a Raspberry Pi and trigger a buzzer. You could also have it blink LEDs, send you an SMS or tweet a photo of the washing line and the sky. But we’re going with a buzzer for now.
Here’s the Circuit
Here’s the Python Code
# raindrop sensor DO connected to GPIO18 # HIGH = no rain, LOW = rain detected # Buzzer on GPIO13 from time import sleep from gpiozero import Buzzer, InputDevice buzz = Buzzer(13) no_rain = InputDevice(18) def buzz_now(iterations): for x in range(iterations): buzz.on() sleep(0.1) buzz.off() sleep(0.1) while True: if not no_rain.is_active: print("It's raining - get the washing in!") buzz_now(5) # insert your other code or functions here # e.g. tweet, SMS, email, take a photo etc. sleep(1)
When no raindrops are on the sensor, the sensor controller’s DO (digital out) pin is HIGH (3.3V in our case). When raindrops are detected this changes to LOW (0V). By connecting DO to a GPIO port on the Pi (GPIO18) we can read the status and set off the buzzer (on GPIO13) when rain is detected.
When rain is detected, the buzzer is sounded 5 times in quick succession, followed by a 1s pause. This will repeat until the raindrops are no longer detected. A message will also be printed out on the screen each second while raindrops are detected…
You want the sensor to trigger when you have a couple of drops of water on it. It’s up to you exactly how many. I prefer it when it’s 2-3 drops or one really large one. You can change the trigger sensitivity by twiddling the controller board potentiometer when you have drops on your sensor. With your chosen number of drops on the sensor (and the Python script running) twiddle the pot. until the buzzer stops beeping and then back off until it just starts again. Then you have your setting. Then tweak and play with it as much as you wish to makes sure it works as you want.
Then put the Pi and controller in some kind of box to protect it from the rain, but obviously leave the sensor itself exposed. Run the python script and wait for the beeps to tell you it’s raining.
Suggestions for Taking it Further
- add some LEDs and make them activate when it rains
- send an email warning when it starts to rain
- send an SMS when it starts to rain
- send a push notification to your phone when it rains
- tweet at you when it starts to rain
- tweet a photo of the washing line and the sky when it starts to rain
- tweak the code so that it won’t keep beeping for the whole time it rains (that will grow old quickly)
If You’d Like to Make One
I’ve put together a little kit containing the parts you need for this project. If you’d like one, you can buy them from the RasPiO online shop here.
- Raindrop sensing board
- Control board
- 5 jumper wires with F-F DuPont connectors
- 10 jumper wires with M-F DuPont connectors
- Buzzer (active piezo)
- Mini breadboard