Air pollution is a major issue in many cities and the air quality index is getting worse every day. According to the World Health Organization report, more people are killed prematurely by the effects of hazardous particles presented in the air than from 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 build a project to monitor air quality by measuring dust particles density in the air.
So in continuation of our previous projects like LPG detector, Smoke detector, and Air Quality Monitor, here we are going to interface the Sharp GP2Y1014AU0F Sensor with Arduino Nano to measure the Dust Density in Air. Apart from the Dust sensor and Arduino Nano, an OLED display is also used to display the measured values. Sharp’s GP2Y1014AU0F Dust Sensor is very effective in detecting very fine particles like cigarette smoke. It is designed for use in Air purifiers and Air conditioners.
Components Required for Arduino Air Quality Sensor
- Arduino Nano
- Sharp GP2Y1014AU0F Sensor
- 0.96’ SPI OLED Display Module
- Jumper Wires
- 220 µf Capacitor
- 150 Ω Resistor
Sharp GP2Y1014AU0F Sensor
Sharp's GP2Y1014AU0F is a tiny six-pin analog output optical air quality/optical dust sensor that is designed to sense dust particles in the air. It works on the principle of laser scattering. Inside the sensor module, an infrared emitting diode and a photosensor are diagonally arranged near the air inlet hole as shown in the below image:
When air containing dust particles enters into the sensor chamber, the dust particles scatter the IR LED light towards the photo-detector. The intensity of the scattered light depends on the dust particles. The more dust particles in the air, the greater the intensity of light. Output voltage at the VOUT pin of the sensor changes according to the intensity of scattered light.
GP2Y1014AU0F Sensor Pinout:
As mentioned earlier, the GP2Y1014AU0F sensor comes with a 6-pin connector. The below figure and table shows the pin assignments for GP2Y1014AU0F:
S. NO. |
Pin Name |
Pin Description |
1 |
V-LED |
LED Vcc Pin. Connect to 5V through 150Ω Resistor |
2 |
LED-GND |
LED Ground Pin. Connect to GND |
3 |
LED |
Used to Toggle LED On/Off. Connect to any digital pin of Arduino |
4 |
S-GND |
Sensor Ground Pin. Connect to GND of Arduino |
5 |
VOUT |
Sensor Analog Output Pin. Connect to any Analog Pin |
6 |
VCC |
Positive Supply Pin. Connect to 5V of Arduino |
GP2Y1014AU0F Sensor Specifications:
- Low Current Consumption: 20mA max
- Typical Operating Voltage: 4.5V to 5.5V
- Minimum Detectable Dust Size: 0.5µm
- Dust Density Sensing Range: Up to 580 ug/m3
- Sensing Time: Less than 1 Second
- Dimensions: 1.81 x 1.18 x 0.69'' (46.0 x 30.0 x 17.6mm)
OLED Display Module
OLED (Organic Light-Emitting Diodes) is a self light-emitting technology, constructed by placing a series of organic thin films between two conductors. A bright light is produced when an electric current is applied to these films. OLEDs are using the same technology as televisions, but have fewer pixels than in most of our TVs.
For this project, we are using a Monochrome 7-pin SSD1306 0.96” OLED display. It can work on three different communications Protocols: SPI 3 Wire mode, SPI four-wire mode, and I2C mode. The pins and its functions are explained in the table below:
We have already covered OLED and its types in details in the previous article.
Pin Name |
Other Names |
Description |
Gnd |
Ground |
Ground pin of the module |
Vdd |
Vcc, 5V |
Power pin (3-5V tolerable) |
SCK |
D0,SCL,CLK |
Acts as the clock pin. Used for both I2C and SPI |
SDA |
D1,MOSI |
Data pin of the module. Used for both IIC and SPI |
RES |
RST, RESET |
Resets the module (useful during SPI) |
DC |
A0 |
Data Command pin. Used for SPI protocol |
CS |
Chip Select |
Useful when more than one module is used under SPI protocol |
OLED Specifications:
- OLED Driver IC: SSD1306
- Resolution: 128 x 64
- Visual Angle: >160°
- Input Voltage: 3.3V ~ 6V
- Pixel Colour: Blue
- Working temperature: -30°C ~ 70°C
Learn more about OLED and its interfacing with different microcontrollers by following the link.
Circuit Diagram
Circuit Diagram for Interfacing Sharp GP2Y1014AU0F Sensor with Arduino is given below:
The circuit is very simple as we are only connecting GP2Y10 Sensor and OLED Display module with Arduino Nano. GP2Y10 Sensor and OLED Display module both are powered with +5V and GND. The V0 pin is connected with the A5 pin of Arduino Nano. The LED pin of the sensor is connected to the Arduino’s digital pin12. Since the OLED Display module uses SPI communication, we have established an SPI communication between the OLED module and Arduino Nano. The connections are shown in the below table:
S.No |
OLED Module Pin |
Arduino Pin |
1 |
GND |
Ground |
2 |
VCC |
5V |
3 |
D0 |
10 |
4 |
D1 |
9 |
5 |
RES |
13 |
6 |
DC |
11 |
7 |
CS |
12 |
S.No |
Sensor Pin |
Arduino Pin |
1 |
Vcc |
5V |
2 |
VO |
A5 |
3 |
S-GND |
GND |
4 |
LED |
7 |
5 |
LED-GND |
GND |
6 |
V-LED |
5V Through 150Ω Resistor |
Building the Circuit on Perf Board
After soldering all the components on the perf board, it will look something like below. But it can be also built on a breadboard. I have soldered the GP2Y1014 sensor on the same board that I used to interface the SDS011 sensor. While soldering, make sure your solder wires should be at enough distance from each other.
Code Explanation for Air Quality Analyzer
The complete Arduino code for this project is given at the end of the document. Here we are explaining some important parts of the code.
The code uses the Adafruit_GFX, and Adafruit_SSD1306 libraries. These libraries can be downloaded from the Library Manager in the Arduino IDE and install it from there. For that, open the Arduino IDE and go to Sketch < Include Library < Manage Libraries. Now search for Adafruit GFX and install the Adafruit GFX library by Adafruit.
Similarly, install the Adafruit SSD1306 libraries by Adafruit.
After installing the libraries to Arduino IDE, start the code by including the needed libraries files. Dust sensor doesn’t require any library as we are reading the voltage values directly from the analog pin of Arduino.
#include <SPI.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h>
Then, define the OLED width and height. In this project, we’re 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 where OLED Display is connected.
#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 with the width and height defined earlier with the SPI communication protocol.
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
After that, define the Dust sensors sense and led pins. Sense pin is the output pin of the Dust sensor that is used to read the voltage values while the led pin is used to turn on/off the IR Led.
int sensePin = A5; int ledPin = 7;
Now inside the setup() function, initialize the Serial Monitor at a baud rate of 9600 for debugging purposes. Also, Initialize the OLED display with the begin() function.
Serial.begin(9600); display.begin(SSD1306_SWITCHCAPVCC);
Inside the loop() function, read the voltage Values from analog pin 5 of Arduino Nano. First, turn on the IR LED and then wait for 0.28ms before taking a reading of the output voltage. After that, read the voltage values from the analog pin. This operation takes around 40 to 50 microseconds, so introduce a 40-microsecond delay before turning the dust sensor led off. According to the specifications, LED should be pulsed on once every 10ms, so wait for the remainder of the 10ms cycle = 10000 - 280 - 40 = 9680 microseconds.
digitalWrite(ledPin,LOW); delayMicroseconds(280); outVo = analogRead(sensePin); delayMicroseconds(40); digitalWrite(ledPin,HIGH); delayMicroseconds(9680);
Then in the next lines, calculate the Dust density using the output voltage and signal value.
sigVolt = outVo*(5/1024); dustLevel = 0.17 * sigVolt - 0.1;
After that, set the text size and text colour using the setTextSize() and setTextColor().
display.setTextSize(1); display.setTextColor(WHITE);
Then in next line, define the position where the text starts using the setCursor(x,y) method. And print the Dust Density Values on OLED Display using display.println() function.
display.println("Dust"); display.println("Density"); display.setTextSize(3); display.println(dustLevel);
And in the last, call the display() method to display the text on OLED Display.
display.display(); display.clearDisplay();
Testing Arduino Air Quality Sensor
Once the hardware and code are ready, it is time to test the sensor. For that, connect the Arduino to the laptop, select the Board and Port, and hit the upload button. As you can see in the below image, it will display Dust Density on OLED Display.
The complete working video and code for Arduino Air Quality Sensor are given below. Hope you enjoyed the tutorial and learned something useful. If you have any questions, leave them in the comment section or use our forums for other technical queries.
#include <SPI.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for SSD1306 display connected using software SPI (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); int measurePin = A5; int ledPower = 7; float voMeasured = 0; float calcVoltage = 0; float dustDensity = 0; void setup(){ Serial.begin(9600); pinMode(ledPower,OUTPUT); display.begin(SSD1306_SWITCHCAPVCC); display.clearDisplay(); display.display(); } void loop(){ digitalWrite(ledPower,LOW); delayMicroseconds(280); voMeasured = analogRead(measurePin); delayMicroseconds(40); digitalWrite(ledPower,HIGH); delayMicroseconds(9680); calcVoltage = voMeasured*(5.0/1024); dustDensity = 0.17*calcVoltage-0.1; if ( dustDensity < 0) { dustDensity = 0.00; } Serial.println("Raw Signal Value (0-1023):"); Serial.println(voMeasured); Serial.println("Voltage:"); Serial.println(calcVoltage); Serial.println("Dust Density:"); Serial.println(dustDensity); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(85,22); display.println("Dust"); display.setCursor(85,38); display.println("Density"); display.setTextSize(3); display.setCursor(0,13); display.println(dustDensity); display.setCursor(6,43); display.setTextSize(2); display.println("ug/m3"); display.display(); display.clearDisplay(); delay(1000); }