How To Build an Air Quality Alert Light with Raspberry Pi Pico
This project uses a Raspberry Pi Pico W, a low-cost microcontroller, to create an air quality alert system using NeoPixel RGB LEDs. The purpose is to determine air quality conditions before going outdoors by fetching air quality data from the OpenWeather API. The process involves setting up a button as an input trigger, connecting NeoPixel LEDs as an output display, and utilizing Python for coding.
- The circuit consists of a push button connected to GPIO14 and a strip of NeoPixel RGB LEDs connected to GPIO16. The button’s state change is detected when pressed, and the LEDs are used to visualize air quality conditions.
- The code involves various modules, including those for network connectivity, time control, HTTP requests, pin control, and NeoPixel control. The Pico connects to Wi-Fi using the network module and Wi-Fi credentials.
- The code then checks if the Wi-Fi connection is successful. If connected, the NeoPixel LEDs flash green 10 times to indicate a successful connection. If not connected, the NeoPixel LEDs flash red 10 times.
- In an infinite loop, the code waits for the push button to be pressed. Once pressed, it fetches air quality data from the OpenWeather API. The air quality index (AQI) is extracted from the API response.
- Depending on the AQI value, the NeoPixel LEDs flash different colors for different air quality conditions. For example, green for “Good,” blue for “Fair,” purple for “Moderate,” orange for “Poor,” and red for “Very Poor.” The LEDs flash each color 10 times with a half-second delay between flashes.
- If the button is not pressed, the loop continues to wait for user input.
- The main.py file containing this code is executed each time the Pico boots.
- The code includes placeholders for the Wi-Fi SSID, password, and OpenWeather API key, which need to be replaced with your actual values.
By following this guide and combining the hardware setup with the provided code, you can create an air quality alert light using a Raspberry Pi Pico W and NeoPixel LEDs to indicate air quality conditions before heading outside.
What you’ll need for this project:
- Raspberry Pi Pico W (pre-soldered headers) Maker kit 4 with breadboard parts
- 12×12 Tactile Push Button Switch with Blue Caps(pack of 5)
- Solderless 400 Point Breadboard
- Jumper cables Male to Male Pack of 65
Find the code here: How To Build an Air Quality Alert Light with Raspberry Pi Pico | Tom’s Hardware