Build an air quality analyzer with SDS011 with Arduino Nano

Publisher:清新天空Latest update time:2023-03-20 Source: elecfansKeywords:Arduino Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  Air pollution is a major problem in many cities, with air quality indexes getting worse every day. According to the World Health Organization, more people die prematurely due to the impact of harmful particles present in the air than die in car accidents. According to the Environmental Protection Agency (EPA), indoor air can be 2 to 5 times more toxic than outdoor air. So here we built a device to monitor air quality by measuring PM2.5 and PM10 particles in the air.


  We previously used the MQ135 gas sensor for air quality monitoring and the Sharp GP2Y1014AU0F sensor to measure the dust density in the air. This time we are using SDS011 sensor with Arduino Nano to build an air quality analyzer. The SDS011 sensor can calculate the concentration of PM2.5 and PM10 particles in the air. Here, real-time PM2.5 and PM 10 values ​​will be displayed on the OLED display.


  Required components

  Arduino Nano

  Nova PM sensor SDS011

  0.96' SPI OLED display module

  jumper

  Nova PM sensor SDS011

poYBAGLwxYuAHtMWAASkZ43LViA861.png

  The SDS011 sensor is the latest air quality sensor developed by Nova Fitness. It works on the principle of laser scattering and can obtain the particle concentration of 0.3 to 10 μm in the air. The sensor consists of a small fan, air inlet valve, laser diode and photodiode. Air enters through the air inlet, a light source (laser) illuminates the particles, and the scattered light is converted into a signal by a photodetector. These signals are then amplified to obtain the particle concentrations of PM2.5 and PM10.

pYYBAGLwxYWAELDkAABj2XCKAe0367.png

  SDS011 sensor specifications:

  Output: PM2.5, PM10

  Measuring range: 0.0-999.9μg/m3

  Input voltage: 4.7V to 5.3V

  Maximum current: 100mA

  Sleep current: 2mA

  Response time: 1 second

  Serial data output frequency: 1 time/second

  Particle size resolution: ≤0.3μm

  Relative error: 10%

  Temperature range: -20~50°C

  0.96' OLED display module

  OLED (organic light-emitting diode) is a self-luminous technology built by placing a series of organic films between two conductors. When an electric current is applied to these films, bright light is produced. OLED uses the same technology as TVs, but has fewer pixels than most of our TVs.

poYBAGLwxYGAOKIKAAI1SgYl8_I417.png

  For this project, we are using a monochrome 7-pin SSD1306 0.96” OLED display. It can work on three different communication protocols: SPI 3-wire mode, SPI 4-wire mode and I2C mode. The following table explains the pins and their functions Explained:

poYBAGLwxXyAXNnLAABmqGhaxkw862.png

  Learn more about OLEDs and their interfaces with different microcontrollers via the links below.

  Air quality analyzer circuit diagram

  The circuit diagram for measuring PM2.5 and PM10 particles using Arduino is very simple and is shown below.

pYYBAGLwxXiAWinMAAF2AMgWTLg167.png

poYBAGLwxXSAAd4UAAcd-JX6pJI649.png

  Both the SDS011 sensor and the OLED display module are powered by +5V and GND. The transmitter and receiver pins of SDS011 are connected to the D3 and D4 pins of the Arduino Nano. Since the OLED Display module uses SPI communication, we established SPI communication between the OLED module and Arduino Nano. The connections are shown in the table below:

pYYBAGLwxXCAa11vAAA5Y9_Dp78442.png

  Build the circuit on the performance board

  I also soldered all the components on the performance board to give it a neat look. But you can also make them on a breadboard. The board I made is as follows. When soldering, make sure not to sort the wires. The performance board I welded is shown below:

poYBAGLwxWyAQAWsAARTT2OMUXI476.png

  Air quality monitor code description

  The complete code for this project is given at the end of the document. Here we will explain some important parts of the code.

  This code uses the SDS011, Adafruit_GFX and Adafruit_SSD1306 libraries. These libraries can be downloaded from the library manager in the Arduino IDE and can be installed from there. To do this, open the Arduino IDE and go to Sketch » Include Library » Manage Libraries. Now search for SDS011 and install R. Zschiegner's SDS Sensor library.

pYYBAGLwxWiATNadAAC4TWGRqd4224.png

  Likewise, install Adafruit's Adafruit GFX and Adafruit SSD1306 libraries.

After installing the libraries into the Arduino IDE, start the code by including the required library files.

#include 

#include 

#include 

#include 

 


In the next few lines, define two variables to store PM10 and PM2.5 values.


 


float p10,p25;

 


Then, define the width and height of the OLED. In this project, we are using a 128×64 SPI OLED display. You can change the SCREEN_WIDTH and SCREEN_HEIGHT variables according to your display.


 


#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 64

 


Then define the SPI communication pins connected to the OLED display.


 


#define OLED_MOSI 9

#define OLED_CLK 10

#define OLED_DC 11

#define OLED_CS 12

#define OLED_RESET 13

 


Then, create an Adafruit display instance using the width and height defined earlier using the SPI communication protocol.


 


Adafruit_SSD1306 display (SCREEN_WIDTH, SCREEN_HEIGHT, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

 


Now in the setup() function, initialize the serial monitor with a baud rate of 9600 for debugging. In addition, use the begin() function to initialize the OLED display and SDS011 sensor.


 


my_sds.begin(3,4);

SerialNumber.Start(9600);

display.begin(SSD1306_SWITCHCAPVCC);

 


In void loop(), read PM10 and PM2.5 values ​​from SDS011 sensor and print the readings on the serial monitor.


 


void loop(){

  Error = my_sds.read(&p25,&p10);

  if(!error){

    Serial.println("P2.5:"+String(p25));

    Serial.println("P10:"+String(p10));

 


After that, use setTextSize() and setTextColor() to set the text size and text color.


 


display.setTextSize(2);

display.setTextColor(white);

 


Then in the next line, use the setCursor(x,y) method to define the position of the starting text. Here we will display PM2.5 and PM10 values ​​on the OLED display, so the first row starts from (0,15) and the second row starts from (0, 40) coordinates.


 


display.setCursor(0,15);

display.println("PM2.5");

display.setCursor(67,15);

display.println(p25);

display.setCursor(0,40);

display.println("PM10");

display.setCursor(67,40);

display.println(p10);

 


Finally, call the display() method to display the text on the OLED Display.


 


display.display();

display.clearDisplay();

 


  Arduino air quality monitor test


  Once the hardware and code are ready, it's time to test the device. To do this, connect the Arduino to the laptop, select the board and port, and click the upload button. As shown in the picture below, it will display PM2.5 and PM10 values ​​on the OLED display.

pYYBAGLwxWGAUzXfAAVfqhG4SC0085.png

#include
#include
#include
#includefloating
p10,p25;
Internal error;
SDS011 my_sds;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Use Software SPI connected SSD1306 display declaration (default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display (screen width, screen height,
OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
Invalid settings () {
my_sds.begin(3,4);
Serial number. Begin (9600);
display.begin(SSD1306_SWITCHCAPVCC)
; display.clearDisplay()
; Display.Display();
}
Invalid loop () {
Error = my_sds.read(&p25,&p10);
if (! Error) {
Serial.println("P2.5:"+String(p25));
Serial.println("P10:"+String(p10));
display .setTextSize(2);
display.setTextColor (white);
display.setCursor(0,15);
display.println("PM2.5");
display.setCursor(67,15);
display.println(p25);
display .setCursor(0,40);
display.println("PM10");
display.setCursor(67,40);
display.println(p10)
; display.display();
display.clearDisplay();
}
Delay(100) ;
}

Keywords:Arduino Reference address:Build an air quality analyzer with SDS011 with Arduino Nano

Previous article:Analyze the differences in EMI test methods and results of receivers and spectrum analyzers
Next article:Built a pulse oximeter using MAX30100 and ESP32

Recommended ReadingLatest update time:2024-11-16 09:28

Use Arduino IDE to program ATMEGA8 and other microcontrollers
 Why do you want to use Arduino IDE to program ATMEGA8? Perhaps any of the following three reasons may impress you: Using a cheaper AVR microcontroller Require an AVR microcontroller with more or even less pins than ATmega328 You have all kinds of AVR except ATmega328
[Microcontroller]
Use Arduino IDE to program ATMEGA8 and other microcontrollers
Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号