Hardware Reference
In-Depth Information
We also need a flow control valve similar to this one sold o
n
SparkFun
available at
https://www.spa
rkfun.com/products/10456
.
Engage thrusters
1. NOAA (
http://www.weather.gov/
) provides weather data generated from the
weather staions situated in diferent ciies. Each city's weather staion has a unique
four-leter code. For example, Chicago, Illinois' code is
KORD
. We will make use of
this four-leter code to retrieve the weather forecast for a city.
2.
The weather data is retrieved using the
pywapi
library as follows:
def main():
pp = pprint.PrettyPrinter(indent=4)
while True:
result = pywapi.get_weather_from_noaa('KORD')
pp.pprint(result['weather'])
sleep(10)
3. We will turn on the sprinkler only if the weather forecast (available under the
weather keyword) is anything other than
Rain
,
Light Rain
, or
Thunderstorm
:
if (result['weather'] != 'Light Rain' or
result['weather'] != 'Rain' or
result['weather'] != 'Thunderstorm'):
GPIO.output(25,GPIO.HIGH)
4. The sprinkler can be turned on using a transistor switching circuit and a relay.
(If you are not familiar with transistor switching circuit and relays,
Project 4
,
Christmas Light Sequencer
provides informaion about a transistor switching
circuit in extensive detail).
5.
It has not been demonstrated here but the
pywapi
module needs to be used in
conjuncion with the
datetime
module to turn on the sprinkler at selected imes
of day.
Objective complete - mini debriefing
If it is not possible to interface the solenoid valve directly to Raspberry Pi, as the solenoid
valve can only be interfaced to an Arduino and controlled using the
python-twisted
framework.
In states such as California where there are someimes severe droughts, it is common
pracice to save water from drain pipes using barrels. The
pywapi
module can be used to
replace the barrels if there is an upcoming rain forecast.