Raspberry Pi Adjustable Air Quality Detector Running on GUI
I had been working on a project with which I could collate air quality information from an MQ-135 Air Quality Sensor to detect the occurrence of the deteriorating air quality in my workplace. However, the positioning of the MQ-135 Air Quality Sensor has gigantic importance while collecting pristine information from the sensor. Therefore, I decided to make a moveable sensor base via selected angles by developing a user-friendly interface. To achieve that goal and add a few corroborating features such as adjustable background light, I developed a GUI using the guizero module in Python for my Raspberry Pi, named Air Quality Module.
Via Air Quality Module, you can control two servo motors attached to the mini pan-tilt kit by choosing one of the given angles - 0, 30, 45, 90, 135, 180 - and adjust the background light in RGB format - 255, 255, 255. And, most importantly, you can monitor the current air quality range generated by the MQ-135 sensor: the GUI notifies you with a warning message if the air quality is deteriorating.
Preview: What You Will Learn
- How to control servo motors using angles with Raspberry Pi
- How to adjust the color of RGB LEDs with Raspberry Pi
- How to read analog sensors with MCP3008 and Raspberry Pi
- How to develop a GUI using the guizero module
- How to program a range function to arrange values like the map function in Arduino
Step 1: Read Analog Sensors with MCP3008
Unfortunately, Raspberry Pi does not have a built-in ADC (analog-to-digital converter) by which we can collect information from analog sensors easily as opposed to Arduino. Hence, we need to implement an external ADC in our circuit to collate data from analog sensors like the MQ-135 Air Quality Sensor. I used an MCP3008 8-channel ADC due to its efficiency and simple usage.
I used the Adafruit CircuitPython MCP3xxx library on Raspberry Pi to read analog sensors with MCP3008.
But, you will need to install the Adafruit_Blinka library that provides the CircuitPython support in Python to use the mentioned library.
sudo pip3 install adafruit-blinka
If it is needed, you have to enable the SPI on Raspberry Pi Configuration Settings before executing the command.
Once that's done, from your command line run the following command to install the Adafruit CircuitPython MCP3xxx library.
sudo pip3 install adafruit-circuitpython-mcp3xxx
Then, make the pin connections as follows. Even though the pin connections are well-explained on the project schematic and in the code,
I'll leave the following pin connection schematic for MCP3008 besides them.
- MCP3008 CLK to Pi SCLK
- MCP3008 DOUT to Pi MISO
- MCP3008 DIN to Pi MOSI
- MCP3008 CS to Pi D5
- MCP3008 VDD to Pi 3.3V
- MCP3008 VREF to Pi 3.3V
- MCP3008 AGND to Pi GND
- MCP3008 DGND to Pi GND
- MCP3008 CH0 to Analog Sensor's Signal Pin
CH0 refers to the first input pin on the MCP3008 - from 0 to 7.
Step 2: Developing a GUI (Air Quality Module) and Programming Raspberry Pi
To be able to create a GUI in Python, you need to install the guizero module on Raspberry Pi. Then, you can use all the provided widgets and events by the module.
From your command line run the following command to install the guizero module.
sudo pip3 install guizero
You can inspect all instructions and widget settings from here.
- Import the required libraries and modules.
- Do not forget to include all GUI widgets - App, Box, Text, TextBox, PushButton, ButtonGroup, MenuBar, info, yesno, warn.
- Create the SPI bus, the cs (chip select), and the mcp object.
- Create analog input channels connected to the input pins on the MCP3008 - I used only the channel 0.
- Define GPIO pin settings - GPIO.setmode(GPIO.BCM).
- Define RGB pins and set PWM frequencies - 100.
- Start RGB PWM pins at 100 - OFF.
- Define servo motor pins and set PWM frequencies - 50.
- Start servo base and arm pins at 0 - OFF.
- Define menu bar option commands (functions):
- In the Tutorial() function, open a yesno message to go to the project tutorial page if requested.
- In the Components() function, open an info message to display components.
- In the About() function, open an info message to display the elevator pitch.
- Define the widget commands and features:
- In the _range() function, replicate the Arduino map function to arrange values in a given range in Python.
- In the evaluateSensorValue() function, get the air quality value from the MQ-135 Air Quality in the tested range - from 0-60000 to 0-1023.
- Test your module, then define the value range in this case between 0 and 60000.
- If the threshold (300) is exceeded, notify with a warning message - Air Quality Deteriorating - and change the Status to DANGER.
- In the adjust_color() function, adjust the color of the RGB LED by changing PWM frequencies - between 0 and 100 - using ChangeDutyCycle(). Arrange the entered color values from 0-255 to 0-100.
- In base_tilt_move() and arm_tilt_move() functions, control the servo motors by the selected angles - 0, 30, 45, 90, 135, 180 - running ChangeDutyCycle(selected_angle). Cycle values between 2 and 12 are working precisely for the angles between 0 and 180.
- Do not forget to execute the following line after adjusting servo motor positions to turn off the servo PWM pins.
- ChangeDutyCycle(0)
- Create the GUI application named Air Quality Module.
- Define menu bar options - Tutorial, Components, About.
- Design the interface using the box widget:
RGB Color Interface
- Align parts using layout grid.
- Assign the related command (function) to the Adjust pushbutton - adjust_color.
Air Quality Interface
- Define the sensor and status text variables.
- Update the sensor value generated by the MQ-135 Air Quality Sensor every second by using the repeat() function.
Note: While loops are not working while executing the app.display() function.
Mini Pan-Tilt Base Interface
- Define the angles in the buttongroup widget - 0, 30, 45, 90, 135, 180.
- Assign the related command (function) - base_tilt_move.
Mini Pan-Tilt Arm Interface
- Define the angles in the buttongroup widget - 0, 30, 45, 90, 135, 180.
- Assign the related command (function) - arm_tilt_move.
- Start the loop- app.display().
Features
1) Change the background color of the apparatus (RGB).
2) Adjust the position of the servo motors on the mini pan-tilt kit by selecting different angles - 0, 30, 45, 90, 135, 180.
3) Get notified when the sensor (MQ-135) detects the occurrence of the air quality deterioration - Status: DANGER.
On Menu Bar:
M.1) Go to the tutorial page.
M.2) Inspect the components.
M.3) Display the elevator pitch.
Connections
Pin connections are well-explained in the code and on the project schematic below.
Connect Raspberry Pi to the screen.
Attach MCP3008 and RGB LED to the mini breadboards. I used a potentiometer to test the value range before connecting the MCP3008 to Raspberry Pi.
Assemble the mini pan-tilt kit and glue the MQ-135 Air Quality Sensor on the mini pan-tilt kit (arm).
Conclusion
After completing all the steps, I affix all parts on an old plastic box and position the apparatus on my desk to collect air quality data and adjust its background color using Air Quality Module (GUI) on my Raspberry Pi :)
Videos
Schematics
Code Files and Downloads
Raspberry Pi Adjustable Air Quality Detector Running on GUI
- Comments(0)
- Likes(2)
- (DIY) C64iSTANBUL May 12,2021
- Kutluhan Aktar May 11,2021
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Kutluhan Aktar
- Joker Remote Hazardous Gas Station and Monitor For a long time, I wanted to create a unique device to observe the presence of varying hazardous gas...
- Darth Vader IoT Cryptocurrency Tracker and Display w/ Raspberry Pi Pico Instead of using a mobile or web application, I decided to develop a brand-new device to track and d...
- Bluetooth Mobile Remote Lamp with Weather Station I have created an electronics project named Remote Lamp two years ago, as my new room lighting syste...
- Multi-Model AI-Based Mechanical Anomaly Detector w/ BLE Mechanical anomaly detection is critical in autonomous manufacturing processes so as to prevent equi...
- AI-assisted Pipeline Diagnostics and Inspection w/ mmWave StorySince the beginning of the industrial revolution, accurate pipeline system maintenance has been...
- IoT AI-driven Smart Grocery Cart w/ Edge Impulse Especially after the recent success of Amazon Go cashierless convenience stores, there is a surge in...
- BLE Mobile Star Wars Remote Lamp w/ Weather & Gas Station As you may have seen, I have created a similar remote Bluetooth-enabled lighting system for my room....
- IoT Bookmark and Reading (Book Ratings) Tracker w/ Qubitro While reading books or comics, I am fond of recording my ratings on a daily basis to track any surge...
- Iron Man Walkie-Talkie (Two-Way Radio) for Texting w/ LoRa For a long time, I have wanted to experiment with LoRa (short for long-range), which is a spread spe...
- Jigglypuff IoT Carbon Dioxide and Dust Monitor (Tracker) w/ Telegram The dust density and the carbon dioxide (CO2) density affect my sleep quality and health detrimental...
- IoT Heart Rate (BPM) Monitor and Tracker w/ Tuya Smart Heart rate, or pulse, is the number of times your heart beats each minute (BPM). While the heart cir...
- Raspberry Pi Adjustable Air Quality Detector Running on GUI I had been working on a project with which I could collate air quality information from an MQ-135 Ai...
- WhatsApp Coronavirus Notifier Bot Running on Raspberry Pi First of all, I hope that you and your loved ones are safe and healthy during these unprecedented ti...
- WhatsApp Surveillance Video Camera with IR Proximity Sensor As you can see in my previous electronics projects, I am fond of developing web applications showing...
- Marvel and DC Weekly New Comics Release List Tracker I am a huge comic book fan and collect issues of my favorite titles every week. Therefore, I check w...
- Arduino-Based (ATmega32U4) Mouse and Keyboard Controller For a long time, I needed a simple device allowing me to send varying mouse and keyboard commands to...
- Bluetooth-enabled Snowman Weather and Air Quality Gift Card Although it is struggling for me to create a brand-new design while paying homage to the classic Chr...
- WhatsApp Halloween-Themed RFID Talking Doorbell w/ RGB Eyes Despite the fact that making a hilarious yet not deceitful joke with a jack-o'-lantern on Halloween ...
-
-
-
-
-
-
3D printed Enclosure Backplate for Riden RD60xx power supplies
154 1 1 -
-