This project is ideal if you already have a Raspberry Pi running 24/7, e.g., as web server, printer server, pi-hole etc. Then you can easily add extra functionality like air monitoring, which will be achieved by realizing this project. At the end, you will have a small status screen displaying temperature, humidity, TVOC and CO2 values.
RequirementsTo follow this guide, you need a Raspberry Pi. I used the Model 3, but any other model should work fine too. Install a Debian based Linux-Distribution like Raspberry Pi OS. Furthermore, you will need the remaining components as listed above. For the final build, I soldered everything together and installed it into a 3D printed case, but this isn't absolutely necessary.
HardwareWire the components together as seen on the following image:
Log into the Raspberry Pi and open the Terminal. If your Pi runs headless, then just connect over SSH.
First update the Raspberry Pi:
sudo apt update
sudo apt upgrade
Then reboot:
sudo reboot
Install the necessary libraries:
sudo apt install python3-dev python3-pip python3-pil
sudo pip3 install --upgrade setuptools
sudo pip3 install Adafruit_DHT adafruit-circuitpython-ccs811 adafruit-circuitpython-ssd1306
Then create a new file by typing:
nano program.py
Now copy the code from the code section into the terminal window and save and exit it, by typing CTRL+O and then CTRL+X
Right now, the program probably won't work, because the baud-rate isn't configured correctly. You can change it by typing:
sudo nano /boot/config.txt
And adding the line
dtparam=i2c_arm_baudrate=10000
Now save and exit again by typing CTRL+O and then CTRL+X
Make sure to reboot the system before proceeding.
You can test the program by typing
python3 /program.py
If it doesn't work, then check, if you missed one of the previous steps. If you did everything correct and the program still won't work, feel free to ask for help in the comments.
Autostartonboot
To run the program every time you boot the System up, follow these steps:
sudo crontab -e
Then enter
@reboot python3 /home/pi/program.py &
And save by typing CTRL+O and then CTRL+X
Now the program runs automatically, every time the Pi boots up.
Sources/Referenceshttps://pimylifeup.com/raspberry-pi-humidity-sensor-dht22/
https://github.com/adafruit/Adafruit_CircuitPython_CCS811
https://learn.adafruit.com/monochrome-oled-breakouts/python-setup
Comments