Sharp GP2Y1014AU PM2.5 detector

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/
// 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);
}