Building a humidity sensor
HTU21 sensors can be aquired at ArduinoTech.dk
For this sensor we need the pigpiod functionality. So lets start by having that being enabled automatically on boot.
Then add this code to the file, save and execute these commands.
After a reboot pigpiod should be running.
Now lets attach the sensor using 4 wires.
- VIN goes to pin 1
- GND goes to pin 9
- SCL goes to pin 5
- SDA goes to pin 3
Next step is to read the sensor output using a script. Dalexgray provides an excellent library/driver on GitHUb. Place both HTU21DF.py and HTU21DF_test.py in your preferred folder. Run the script by executing:
The output should be somewhat similar to:
Congratulations. You are now reading humidity and temperature using your Raspberry Pi
Assuming you have set up your Pi as a LAMP server, you can use this script I have created for saving humidity and temperature every second to your database.
Following your success you might wanna make sure that data is automatically sent to your DB even if the Raspberry Pi has been rebooted
An easy way to do that is by creating a shell script that checks if the python script is running, and if not, just start it
Paste this to your new file and save it:
Add this line and save: