Introduction
Sensors can be found just about everywhere, in your household security alarms, smoke alarms, and in many more devices.
In this tutorial, you will learn how to use a waterproof temperature sensor, the ds18b20 with the Raspberry Pi Zero W to turn your regular fish tank into a smart aquarium. We will use the 1-Wire data protocol to take temperature readings and send an alert via SMS. This will keep your fish friends safe from harm.
Tools
-
-
-
-
sudo raspi-config
-
sudo modprobe w1-gpio sudo modprobe w1-therm cd /sys/bus/w1/devices/ ls
-
-
sudo apt-get install python-w1thermsensor
-
from w1thermsensor import W1ThermSensor sensor = W1ThermSensor() temperature_in_celsius = sensor.get_temperature() temperature_in_fahrenheit = sensor.get_temperature(W1ThermSensor.DEGREES_F) temperature_in_all_units = sensor.get_temperatures([ W1ThermSensor.DEGREES_C, W1ThermSensor.DEGREES_F, W1ThermSensor.KELVIN]) print(temperature_in_celsius)
-
-
from w1thermsensor import W1ThermSensor from time import sleep sensor = W1ThermSensor() upperThreshold = 27 lowerThreshold = 21 while True: temperature = sensor.get_temperature() print 'Current temperature: ' + str(temperature) if temperature > upperThreshold: print 'Too hot' elif temperature < lowerThreshold: print 'Too cold' else: print 'Just right' sleep(900)
-
sudo pip install twilio
-
-
# -*- coding: utf-8 -*- from twilio.rest import Client from w1thermsensor import W1ThermSensor from time import sleep # Your Account SID from twilio.com/console account_sid ='XXXXXXX' # Put your Twilio account SID here # Your Auth Token from twilio.com/console auth_token ='XXXXXXX' # Put your auth token here client = Client(account_sid, auth_token) sensor = W1ThermSensor() upperThreshold = 27 lowerThreshold = 21 while True: temperature = sensor.get_temperature() print 'Current temperature: ' + str(temperature) if temperature > upperThreshold: client.messages.create( to='+#####', # Put your mobile phone number here from_='+######', # Put your Twilio number here body="Uh oh, the temperature is getting too high." ) elif temperature < lowerThreshold: client.messages.create( to='+#####', # Put your mobile phone number here from_='+######', # Put your Twilio number here body="Uh oh, the temperature is getting too low." ) else: print 'Just right' sleep(900)
-