Smart Backyard Sprinkler System (Lane Tech PCL)
by taburgeson in Circuits > Electronics
393 Views, 7 Favorites, 0 Comments
Smart Backyard Sprinkler System (Lane Tech PCL)
This is an automated sprinkler system I made for my backyard that distributes one inch of water per week on a flexible schedule, modified by rainfall.
Supplies
You will need a wire cutter/stripper and a crimping tool.
Materials:
- Particle Argon (microcontroller) with usb power cable
- Breadboard (i used a half-size breadboard)
- mosfet that can withstand 12 volts (i used the FQP30N06L from sparkfun)
- flyback rectifier diode (i used the 1N4007, but anything that has a rating above 24v should work)
- 1kΩ resistor
- Breadboard jumper wire and some stranded wire for the solenoid
- 12 volt power supply and breadboard connector
- Solenoid hose valve (in my case this was for a 3/4 inch hose, but yours may differ)
- crimps that fit the terminals on your solenoid
- A sprinkler
- Garden hoses (2)
- Female to female (for connecting the valve to the spigot)
- Another hose with a female connector (other end is determined by your sprinkler input)
- Some kind of tupperware to put the electronics in so they don't get wet
- A battery power supply for the Argon, or a more permanent option
Optional: Cardboard for mounting
Assemble the Breadboard
Start with your Particle Argon on the breadboard, and orient the board so the Argon is on the right side.
First, we'll place the important components we will need. It'll be easier if you also reference the image of the breadboard.
- Place the power input connector on the top left of the board
- Place the left pin of the mosfet at E5, with the black side of the mosfet facing towards you.
- Place the left leg of the resistor at B1 and the right leg at B5
- Find the line on the diode and place the leg of the diode closest to the line side at G9, and place the opposite leg at E9.
You've now placed all the components! Now we just need to connect them all with wires.
- First we will run the wire that will toggle the mosfet. Run this from B19 on the breadboard so it connects with the Digital 4 pin on the Argon. Then connect the other end to A1.
- Now we'll run the ground wires.
- Connect the ground pin of the argon, or the breadboard coordinate J27, to the ground rail of the breadboard.
- Then connect the rightmost pin of the mosfet (for example, C6 on the breadboard) to the ground rail of the breadboard.
- Then connect the ground pin of the power input connector to the ground rail of the breadboard.
- Now run a wire from the positive pin of the power input connector to the leg of the diode closest to the line side of the diode.
- Run a wire from the middile pin of the mosfet to the leg of the diode without a line.
If any of this is confusing, please reference the images above.
Add the Solenoid
Attach the crimps to the terminals of the solenoid and insert the stranded wire. Then crimp the wire with a crimping tool. Make sure the connection is strong by tugging on the wire a bit.
Complete the Breadboard
Attach the solenoid to the breadboard by intersting the ends of the wires in-line with each end of the diode. The positive wire goes on the line side of the diode and vice versa.
Creating Webhooks
Now we need to make 2 webhooks, one for getting the rainfall predictions for the future and the other for getting the rainfall data from the past.
For each webhook, you'll need to go to https://console.particle.io/integrations and click "Add new integration" in the top right corner. Then click Webhook.
First Webhook
The first webhook will be for historical rainfall data.
- You can name it whatever you want, I named mine "ACIS Historical Rainfall Data"
- The event name should be set to getOldRainfall
- The API url should be https://data.rcc-acis.org/StnData
- Make sure it is a GET request
Then, click Advanced Settings and scroll down.
- Set Form Fields to Custom, and add 5 rows.
- The rows are:
- sid > KORD
- (this is the airport code for the nearest airport to me, O'Hare Airport. change this depending on where you live)
- sdate > {{PARTICLE_EVENT_VALUE}}
- edate > {{PARTICLE_EVENT_VALUE}}
- name > pcpn
- elems > 4
- Then scroll all the way down to Response Template.
- Add {{{data.0.1}}}
Then click Create Webhook.
Second Webhook
The second webhook will be for rainfall predictions. For this, we'll use weatherapi.com.
First, go to https://www.weatherapi.com and click Signup. Once you've done that, find your API key on the account dashboard.
The webhook URL will be https://api.weatherapi.com/v1/forecast.json?key=yourapikey&q=yourzipcode
Once you have that, we can make the rest of the webhook.
- You can name it whatever you want, I named mine "weatherapi.com Precipitation Forecast"
- The event name should be set to getNewRainfall
- The API url should be what is written above
- Make sure it is a GET request
Then, click Advanced Settings and scroll down.
- Set Form Fields to Custom
- We only need one row:
- days > 3
- Then scroll all the way down to Response Template.
- Add {{{forecast.forecastday.1.day.totalprecip_in}}},{{{forecast.forecastday.2.day.totalprecip_in}}},{{{forecast.forecastday.3.day.totalprecip_in}}}
Then click Create Webhook.
Programming
https://go.particle.io/shared_apps/6567e75c2ae6f2000ab9d962
Sign into your particle account and copy the code from this link into a new program. Make sure all the values are correct, like the pin number for the mosfet, and the links for webhooks.
I've put some comments in the code to make it more readable, but i'll also break the code down here:
- First, all the necessary variables are declared
- If it is 9 am and it has been a day or more since the last run, start the program
- check if there are stored values in memory (EEPROM) of previous sprinkler runs, and store them in a variable
- Get the rainfall values of the last 3 days from the API individually and store them in an array
- if the day the program is currently getting data for also has an EEPROM entry with saved watering data, add that to the rainfall amount for that day
- add them all together (rainPastTotal)
- Get the rainfall values for the current and next 2 days
- split these up into an array
- add them all together (rainFutureTotal)
- if the rainfall from the past 3 days and the current and next 2 days is less than 0.8 inches
- calculate how long the sprinkler should run for, assuming lawns need 1 inch of water per week and oscillating sprinklers put out 1 inch of water per hour
- run the sprinkler for that amount of time
- record the amount of water the sprinkler put out into EEPROM so it can be accounted for the next time the program runs
The 2 "response handlers" at the bottom are necessary for how the API sends information back to the Argon device.
The ymd function is for generating a date in the YYYY-MM-DD format so it can be used in API calls.
Once you're ready, you can flash the code to your Argon!
Testing
Make sure you put all your electronics besides the solenoid into your tupperware container.
First, connect your hoses to each end of the solenoid valve, and make sure they are as tight as possible. The valve will leak if this is not done.
- Note - in the picture, my solenoid is wrapped in cardboard. You don't have to do this; my original intent was to mount it onto the side of my house but I realized it wasn't necessary.
Then, connect your 12v power supply to the connector on your breadboard and plug it in to an outlet, and connect your Argon to your power source.
Make sure to close the tupperware container!!!
You now have a "smart" sprinkler!