-
1Basic Setup using Raspberry Pi Pico
We begin by putting together the simplest possible configuration utilizing the MQ135 Sensor and the recently released Raspberry Pi PICO 2.
Here, we connected the MQ135 Sensor's VCC to the 3.3V Pin of PICO, GND to GND, and GPIO26 and GPIO21 for the analog and digital outputs, respectively.
This was the sketch we used for Test.
#include <Wire.h> // Define the pins const int analogPin = 26; // GP26 const int digitalPin = 21; // GP21 void setup() { Serial.begin(9600); pinMode(digitalPin, INPUT); } void loop() { int analogValue = analogRead(analogPin); int digitalValue = digitalRead(digitalPin); Serial.print("Analog Value: "); Serial.print(analogValue); Serial.print(", Digital Value: "); Serial.println(digitalValue); delay(1000); }
It takes about 20 to 30 seconds for the MQ135 Sensor to preheat before it provides precise readings. The sensor value in the Serial monitor can be observed by the user using the sketch above.
-
2Level 2- Design
We made a little enclosure in the Level 2 design that was just 80 x 55 x 30 mm in size. It was separated into two bodies: the Base and the Top Lid part. The OLED screen is mounted in place by the top lid, which also has four screw holes for attaching it to the base body with M2 screws.
The Firebeetle 2 Board, MQ135 Sensor, Power Switch, and Battery are all housed inside the Base Body.
We added handles to the left and right sides of the base body to make this enclosure comfortable and easy to hold.
To make it easier to wear or carry around, we have included a hook-like component that can be used to attach an ID card strap or a keychain to this device.
We created additional components that resemble the letters O and X and put them on the top lid part of the enclosure to increase its visual impact. To enhance the device's aesthetic impact, both of these parts will be printed in orange PLA, while the entire enclosure will be printed in grey PLA.
-
3Why Choose FireBeetle over Raspberry Pi Pico
For level 2 of this project, we swapped the main microcontroller used, which was the Raspberry Pi Pico 2, to the Firebeetle 2 ESP32-E Microcontroller board.
A minor space issue within the enclosure was the reason for this switch;
however, despite the fact that the two boards appear to be almost identical in size, the Pico is really smaller than the Firebeetle. We had to modify the enclosure's design and make it slightly larger because using Pico required the addition of a second board for charging the lithium cell.
We utilized the Firebeetle to address this issue since it has an onboard lithium-ion cell charging circuit that is driven by the TP4056, a full linear charger integrated circuit made specifically for single-cell lithium-ion batteries.
The TP4065 was incorporated into the Firebeetle development board, which resolved our space issue. It is perfect for usage in portable devices that need a dependable and effective lithium-ion battery charging solution.
-
4MAIN SKETCH
Let's have a look at the final Sketch which will be used in Firebeetle Setup.
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); const int analogPin = 35; // A3 const int digitalPin = 2; // D2 void setup() { Serial.begin(9600); pinMode(digitalPin, INPUT); // SSD1306 OLED display initialization if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for(;;); } display.display(); delay(2000); // Pause for 2 seconds display.clearDisplay(); } void loop() { int analogValueRaw = analogRead(analogPin); int analogValue = map(analogValueRaw, 0, 4095, 0, 1023); // Scale the value to match the Pico's range int digitalValue = digitalRead(digitalPin); String airQuality = getAirQuality(analogValue); Serial.print("Analog Value (Raw): "); Serial.print(analogValueRaw); Serial.print(", Scaled Value: "); Serial.print(analogValue); Serial.print(", Digital Value: "); Serial.println(digitalValue); // Display scaled analog value and air quality condition on OLED display.clearDisplay(); display.setTextSize(2); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0, 10); // Start at top-left corner display.print("Value: "); display.println(analogValue); display.setTextSize(1); display.setCursor(0, 40); display.print("Air Quality: "); display.println(airQuality); display.display(); delay(1000); } String getAirQuality(int analogValue) { if (analogValue <= 200) { return "Excellent"; } else if (analogValue <= 400) { return "Good"; } else if (analogValue <= 600) { return "Moderate"; } else if (analogValue <= 800) { return "Poor"; } else { return "Very Poor"; } }
The three main libraries in the sketch were added specifically to use I2C communication to drive the SSD1306 OLED.
Two outputs are provided by the MQ135 sensor: an analog output that is attached to the Firebeetle's A3 pin and a digital output that is connected to the Firebeetle's D2.
We must reduce the raw analog value, which is around 0-4095, to a range of 0-1023 in order to obtain the analog value, which is what we need to obtain the air quality measurements.
Using the Serial.println function, the values are displayed on the screen, but with a twist. The twist here is that we have added getAirQuality Function which takes the scaled analog value and returns a string representing the air quality condition:
- <= 200: "Excellent"
- <= 400: "Good"
- <= 600: "Moderate"
- <= 800: "Poor"
- > 800: "Very Poor"
-
5FireBeetle SSD1306 Display and MQ135 Wiring
If you are recreating this project, it will be easier for you because the wiring diagram for the entire procedure has been added.
- Connecting the Firebeetle's 3.3V and GND wire to the MQ135 Sensor's VCC and GND starts the procedure.
- Next, we used two wires to connect the Firebeetle's 5V and GND to the SSD1306 VCC and GND pins.
- Following that, we used connecting wires to link the MQ135 Sensor's analog and digital outputs to the Firebeetle's A3 and D2.
- Next, we linked the Firebeetle's SDA and SCL pins to the OLED screen's SDA and SCL pins in a similar manner.
-
6Power Source Wiring
We are using a compact formfactor 14500 3.7V 600mAh Lithium ion cell combined with a Protection Circuit Module (PCM), a tiny circuit that guards against overcharge, overdischarge, short circuit, and other issues, as the project's power supply.
We simply connected the lithium cell's positive terminal to the firebeetle's battery positive terminal for the wiring. The negative of the lithium cell was soldered to the rocker switch's on terminal, and the other terminal of the rocker switch was connected to the firebeetle's battery negative terminal. The rocker switch, which is positioned between the battery and the firebeetle, serves as the device's primary power switch.
-
7Body Assembly process
- We positioned the OLED screen inside the top lid to begin the body assembly process, and then we used hot glue to secure the display in place.
- Within the base body, the MQ135 sensor is then slide into place.
- The battery and power switch are next fastened in their proper positions, and the Firebeetle Board is placed in the center of the base body and fastened there using hot glue.
- After ensuring that everything was in its proper place, we placed the top lid over the base body and fastened them together with four M2 screws.
- We finish by applying super glue to the back of the letter O and X parts before positioning them onto the device.
The assembly process is now complete.
-
8Result and Conclusion
The Air Quality Meter, a portable air quality monitoring device that can measure hazardous gases in the environment, is the end result of this little building. This gadget makes it simple for users to keep an eye on the quality of the air in their surroundings and offers a useful indicator for enhancing both indoor and outdoor air safety.
We took readings in two different locations in my city to test our setup: on my rooftop and close to a green area. The low carbon concentration in the green area contrasts with the high carbon concentration in the city, which is why we got different readings.
The city's readings ranged from 550 to 620, depending on whether the area was close to a major road, an industrial region, or a green space with lots of trees and few cars.
If we take the tests in places where gases are less common, such mountains or hills, the values may drop much further.
Overall, this setup was finished, but I would like to make revisions to this project in the future to further reduce its size and make it extremely portable.
Thanks for reaching this far, and I will be back with a new project pretty soon.
Peace.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.