Air Quality Monitoring with the Nova PM Sensor SDS011 and Arduino Uno

,

Welcome to TechLogics! In today’s tutorial, we’ll dive into the fascinating world of air quality monitoring. We will show you how to connect and read the sensor values of the Nova PM Sensor SDS011 using an Arduino Uno. This powerful sensor allows us to detect particulate matter in the air, providing insightful data about our environment. Whether you’re a hobbyist or looking to learn about environmental monitoring, this tutorial is perfect for you!

What You Will Need

  • Nova PM Sensor SDS011
  • Arduino Uno

Understanding the Nova PM Sensor SDS011

The Nova PM Sensor SDS011 is a high-precision laser PM2.5 air quality detection sensor designed to measure fine particulate matter, making it an excellent choice for monitoring air quality in various environments such as homes, offices, and industrial settings. It provides accurate measurements of PM2.5 and PM10, helping users understand air pollution levels and make informed decisions regarding air quality management.

The sensor package includes a USB serial adapter, which serves to provide power to the sensor and enable data communication between the sensor and the Arduino.

Connecting the Sensor to the Arduino

To connect the sensor to the Arduino, you have a couple of options:

  1. Use the cable provided with the USB serial adapter for initial testing.
  2. Or Purchase a 7-pin connector cable for a more permanent and streamlined connection directly to the Arduino.

In this demonstration, we used a separately purchased 7-pin connector cable for effective communication and accurate data readings.

Wiring Configuration

The wiring configuration for connecting the Nova PM Sensor SDS011 to the Arduino Uno is straightforward:

  • Connect the RX pin of the SDS011 to Digital Pin 2 on the Arduino.
  • Connect the TX pin of the SDS011 to Digital Pin 3 on the Arduino.

Make sure to refer to the accompanying wiring diagram for proper setup.

Power Supply Requirements

The Nova PM Sensor SDS011 requires a 5V power supply to operate, which can conveniently be provided by the Arduino Uno. Connect the sensor’s 5V wire to the 5V power pin on the Arduino and the GND wire to one of the GND pins on the Uno. Alternatively, you can connect the 5V power supply directly to the sensor.

Setting Up the Arduino IDE

This tutorial covers the basic connection and code required to retrieve air quality values from the Nova PM Sensor SDS011 and display them in the Arduino IDE Serial Monitor.

Uploading the Code

  1. Connect the USB cable to the Arduino Uno, then plug the other end into your PC or laptop where the Arduino IDE is installed.
  2. Open the Arduino IDE and load the code provided below.
#include <SDS011.h>

// Create an instance of the SDS011 sensor
SDS011 my_sds;

// Variables to hold PM10 and PM2.5 values
float p10, p25; 
int error;

// Timing variables
unsigned long previousMillis = 0; // Store the last time we read the sensor
const long interval = 10000;      // Interval in milliseconds (10 seconds)

void setup() {
    Serial.begin(9600);                // Start Serial Monitor at 9600 bps
    my_sds.begin(2, 3);                // Initialize SDS011 with RX on Digital Pin 2, TX on Digital Pin 3

    Serial.println("SDS011 Sensor Initialized.");
}

void loop() {
    unsigned long currentMillis = millis(); // Get the current time

    // Check if it's time to read the sensor
    if (currentMillis - previousMillis >= interval) {
        previousMillis = currentMillis; // Save the last read time

        // Attempt to read from SDS011
        error = my_sds.read(&p25, &p10); // Read PM2.5 and PM10 values
        
        if (error == 0) {                // Check for successful reading (0 means new values)
            Serial.print("P2.5: ");
            Serial.println(p25);
            Serial.print("P10:  ");
            Serial.println(p10);
        } else {
            Serial.print("Error reading from SDS011, error code: ");
            Serial.println(error); // Print the error code
        }
    }

    // Optional: A short delay can be added here if needed to reduce CPU usage
    delay(100); // Adjust this delay if necessary
}

Installing the SDS011 Library

To use the Nova PM Sensor SDS011 with your Arduino, you need to install the corresponding library that provides the necessary functions for communication with the sensor. The library is included in the code with the line:

#include <SDS011.h> // Include the SDS011 library

Follow these steps to install the SDS011 library in the Arduino IDE:

  1. Open Arduino IDE: Launch the Arduino Integrated Development Environment (IDE) on your computer.
  2. Access Library Manager:
    • Click on Sketch in the top menu.
    • Hover over Include Library, and then click on Manage Libraries.
  3. Search for the Library: In the Library Manager window, there will be a search bar. Type in “SDS011” and press Enter. This will display a list of available libraries related to the SDS011 sensor.
  4. Install the Library: Once you find the appropriate SDS011 library (make sure it matches the sensor you’re using), click on the Install button next to it. This will add the library to your Arduino IDE.

Major Points of the Code:

  1. Library Inclusion: The code begins with #include <SDS011.h>, which imports the library necessary for communicating with the sensor.
  2. Instance Creation: An instance of the sensor is created using SDS011 my_sds;.
  1. Variable Declaration: Variables p10 and p25 hold the PM10 and PM2.5 values, respectively, and error is used to store any error codes encountered during reading.
  2. Timing Configuration: The previousMillis variable keeps track of the last time the sensor was read, and interval sets the reading frequency to every 10 seconds (10,000 milliseconds).
  3. Setup Function:
    • The setup() function executes once when the program starts. It initializes the serial communication at a baud rate of 9600 bps for real-time monitoring output.
    • The sensor is initialized using my_sds.begin(2, 3);, which sets up Digital Pin 2 for RX and Digital Pin 3 for TX.
  4. Loop Function: The loop() function runs repeatedly:
    • It checks if the specified interval has passed since the last reading. If it has, it reads the PM2.5 and PM10 values from the sensor.
    • The code checks if the reading was successful by evaluating the errorvariable. If successful (error == 0), it prints the PM2.5 and PM10 values to the Serial Monitor. If there’s an error, the error code is printed instead.

Monitoring Air Quality Data

Once the code is uploaded, begin monitoring air quality data by following these steps:

  1. Open the Serial Monitor in the Arduino IDE.
  2. Set it to a baud rate of 9600 bps for real-time output.
  3. Readings for PM2.5 and PM10 will now be updated every 10 seconds, allowing you to track air quality effectively.

Conclusion

In this tutorial, you’ve learned how to set up the Nova PM Sensor SDS011 with an Arduino Uno to monitor air quality. This basic setup not only provides immediate visibility into particulate matter concentration in your environment but also serves as a solid foundation for further development and integration with additional components, such as LCD or LED displays, and more advanced functionalities.

Stay tuned for our upcoming tutorials where we will explore these advanced integration techniques, enhance usability features like date and time functionalities, and much more!

If you found this tutorial helpful, please support us by liking, sharing, and subscribing to TechLogics! Your engagement helps us create more valuable content, and we sincerely appreciate your support.

0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x