# Sharp GP2Y1014AU PM2.5 detector

**URL:** <https://forums.pimoroni.com/t/sharp-gp2y1014au-pm2-5-detector/13399>\
**Category:** Arduino & AVR\
**Created:** [March 25, 2020, 11:47pm UTC](https://forums.pimoroni.com/t/sharp-gp2y1014au-pm2-5-detector/13399 "2020-03-25T23:47:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [March 25, 2020, 11:47pm UTC](https://forums.pimoroni.com/t/sharp-gp2y1014au-pm2-5-detector/13399/1 "2020-03-25T23:47:25Z")

</div>

As I while away my time under the current circumstances I thought I would put together a PM2.5 detector. PM2.5s can impair lung function so the Gov recently said that certain types of open fire / stove fuels would be banned e.g un-seasoned (wet) wood.

The hardware I used was (from top to bottom in the pic):  
Arduino Nano V3 (clone)  
A 16x2 HD44780 LCD with a FC-113 I2C display driver  
A Sharp GP2Y1014AU PM2.5 detector (from Keyestudio)  
I connected everything up using jumper jerky wires and mounted everything on an mdf door hanger.

I used the 5V pin on the ICSP connector to power the LCD rather than splice two wires together.

I had to finesse the sample code from the Keyestudio wiki (which is quite a useful resource) to get the data displayed on the 16x2 lcd as it was written for a 20x4 lcd.

My code (where SV = raw signal voltage, CV = calculated voltage and DD = dust density … I must put these in the sketch as comments):

#include \<Wire.h\>  
#include \<LiquidCrystal\_I2C.h\>

#define BACKLIGHT\_PIN 13

LiquidCrystal\_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

int measurePin = 0; //Connect dust sensor to Arduino A0 pin  
int ledPower = 2; //Connect 3 led driver pins of dust sensor to Arduino D2  
int samplingTime = 280;  
int deltaTime = 40;  
int sleepTime = 9680;  
float voMeasured = 0;  
float calcVoltage = 0;  
float dustDensity = 0;  
void setup(){

// Switch on the backlight  
pinMode ( BACKLIGHT\_PIN, OUTPUT );  
digitalWrite ( BACKLIGHT\_PIN, HIGH );

lcd.begin(16,2); // initialize the lcd

lcd.setCursor(0,0);  
lcd.print("SV ");  
lcd.setCursor(9,0);  
lcd.print(“CV”);  
lcd.setCursor(0,1);  
lcd.print(“DD”);  
pinMode(ledPower,OUTPUT);  
}  
void loop(){  
digitalWrite(ledPower,LOW); // power on the LED  
delayMicroseconds(samplingTime);  
voMeasured = analogRead(measurePin); // read the dust value  
delayMicroseconds(deltaTime);  
digitalWrite(ledPower,HIGH); // turn the LED off  
delayMicroseconds(sleepTime);  
// 0 - 5V mapped to 0 - 1023 integer values  
// recover voltage  
calcVoltage = voMeasured \* (5.0 / 1024.0);  
// linear eqaution taken from [http://www.howmuchsnow.com/arduino/airquality/](http://www.howmuchsnow.com/arduino/airquality/)  
// Chris Nafis © 2012  
dustDensity = 0.17 \* calcVoltage - 0.1;  
lcd.setCursor(3,0);  
lcd.print(voMeasured);  
lcd.setCursor(12,0);  
lcd.print(calcVoltage);  
lcd.setCursor(4,1);  
lcd.print(dustDensity);  
delay(1000);  
}

 ![DSCF0405](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/1/1656f9b32d6acba4590ee2479cdf0a1d510013f8.jpeg)
