Using the PMSA300I with Arduino is a simple matter of wiring up it to your Arduino-compatible microcontroller, installing the Adafruit PM25AQI library we've written, and running the provided example code.
I2C Wiring
Wiring the PMSA300I is made simple by using the I2C interface either via the STEMMA QT connector or a solderless breadboard.
- Connect PMSA300I VCC (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
- Connect PMSA300I GND (black wire) to Arduino GND
- Connect PMSA300I SCL (yellow wire) to Arduino SCL
- Connect PMSA300I SDA (blue wire) to Arduino SDA
Library Installation
You can install the Adafruit PM25AQI library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit PM25 AQI, and select the Adafruit PM25 AQI library:
Follow the same process for the Adafruit BusIO library.
Load Example
Open up File -> Examples -> Adafruit PM25 AQI Sensor -> PM25_test
After opening the demo file, upload to your Arduino wired up to the sensor. Once you upload the code, you will see the air quality data being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:
/* Test sketch for Adafruit PM2.5 sensor with UART or I2C */ #include "Adafruit_PM25AQI.h" // If your PM2.5 is UART only, for UNO and others (without hardware serial) // we must use software serial... // pin #2 is IN from sensor (TX pin on sensor), leave pin #3 disconnected // comment these two lines if using hardware serial //#include <SoftwareSerial.h> //SoftwareSerial pmSerial(2, 3); Adafruit_PM25AQI aqi = Adafruit_PM25AQI(); void setup() { // Wait for serial monitor to open Serial.begin(115200); while (!Serial) delay(10); Serial.println("Adafruit PMSA003I Air Quality Sensor"); // Wait one second for sensor to boot up! delay(1000); // If using serial, initialize it and set baudrate before starting! // Uncomment one of the following //Serial1.begin(9600); //pmSerial.begin(9600); // There are 3 options for connectivity! if (! aqi.begin_I2C()) { // connect to the sensor over I2C //if (! aqi.begin_UART(&Serial1)) { // connect to the sensor over hardware serial //if (! aqi.begin_UART(&pmSerial)) { // connect to the sensor over software serial Serial.println("Could not find PM 2.5 sensor!"); while (1) delay(10); } Serial.println("PM25 found!"); } void loop() { PM25_AQI_Data data; if (! aqi.read(&data)) { Serial.println("Could not read from AQI"); delay(500); // try again in a bit! return; } Serial.println("AQI reading success"); Serial.println(); Serial.println(F("---------------------------------------")); Serial.println(F("Concentration Units (standard)")); Serial.println(F("---------------------------------------")); Serial.print(F("PM 1.0: ")); Serial.print(data.pm10_standard); Serial.print(F("\t\tPM 2.5: ")); Serial.print(data.pm25_standard); Serial.print(F("\t\tPM 10: ")); Serial.println(data.pm100_standard); Serial.println(F("Concentration Units (environmental)")); Serial.println(F("---------------------------------------")); Serial.print(F("PM 1.0: ")); Serial.print(data.pm10_env); Serial.print(F("\t\tPM 2.5: ")); Serial.print(data.pm25_env); Serial.print(F("\t\tPM 10: ")); Serial.println(data.pm100_env); Serial.println(F("---------------------------------------")); Serial.print(F("Particles > 0.3um / 0.1L air:")); Serial.println(data.particles_03um); Serial.print(F("Particles > 0.5um / 0.1L air:")); Serial.println(data.particles_05um); Serial.print(F("Particles > 1.0um / 0.1L air:")); Serial.println(data.particles_10um); Serial.print(F("Particles > 2.5um / 0.1L air:")); Serial.println(data.particles_25um); Serial.print(F("Particles > 5.0um / 0.1L air:")); Serial.println(data.particles_50um); Serial.print(F("Particles > 10 um / 0.1L air:")); Serial.println(data.particles_100um); Serial.println(F("---------------------------------------")); delay(1000); }
Text editor powered by tinymce.