Mirko Pavleski
Published © GPL3+

DIY Air Quality Monitor with Sharp GP2Y1010AU0F Sensor

Very simple air quality monitor with nice processing graphical interface oh PC monitor.

BeginnerFull instructions provided38,210
DIY Air Quality Monitor with Sharp GP2Y1010AU0F Sensor

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Capacitor, 220 µF
Capacitor, 220 µF
×1
Through Hole Resistor, 150 ohm
Through Hole Resistor, 150 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Processing
The Processing Foundation Processing

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Code

Arduino code

Arduino
/*
 Standalone Sketch to use with a Arduino UNO and a
 Sharp Optical Dust Sensor GP2Y1010AU0F
*/

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(){
  Serial.begin(9600);
  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 (c) 2012
  dustDensity = 170 * calcVoltage - 0.1;

  
  Serial.println(dustDensity); // unit: ug/m3

  delay(1000);
}

Processing code

C/C++
/* //<>//
 Meter as a partial circle.
 Change a few colors.
 Note that the circle starts at 90.0 degrees (6:00 OClock) and
 moves clockwise. The scale labels have to be in this order.

  Non-Hardware example.
 
 created April 19, 2017
 by Bill (Papa) Kujawa.
 
 This example code is in the public domain.
 */
import processing.serial.*;
import meter.*;

Serial port;
String[] list;

Meter m;

void setup() {
  size(1150, 910);
  background(255, 255, 200);
  
   port = new Serial(this, "COM4", 9600);

  // Display a full circle meter.
  m = new Meter(this, 125, 25, true); // Instantiate a full circle meter class.
  m.setMeterWidth(850);
  m.setFrameColor(color(100, 0, 0));
  m.setTitleFontColor(color(0, 200, 0));
  m.setPivotPointColor(color(255, 0, 0));
  m.setArcColor(color(0, 0, 200));
  m.setScaleFontColor(color(200, 100, 0));
  m.setTicMarkColor(color(217, 22, 247));
  // Define where the scale labele will appear
  m.setArcMinDegrees(90.0); // (start)
  m.setArcMaxDegrees(360.0); // ( end)
  m.setArcThickness(5);
  m.setNeedleThickness(4);
  // Set the meter value correspond to the scale labels.
  m.setMinScaleValue(0.0);
  m.setMaxScaleValue(800.0);
  m.setInputSignalOutOfRangeFontColor(color(0, 255, 0));
  m.setMinInputSignal(0);
  m.setMaxInputSignal(800);
 m.setHighSensorWarningActive(true);
  m.setHighSensorWarningValue((float)200.0);
  String[] scaleLabelsA = {"0", "100", "200", "300", "400", "500", "600", "700", "800"};
  m.setScaleLabels(scaleLabelsA);

  // Change the title from the default "Voltage" to a more meaningful label.
  m.setTitle("Airquality (ug/m3)");

  // Display the digital meter value.
  m.setDisplayDigitalMeterValue(true);
}

void draw() {

  if (port.available() > 0) {
    String val = port.readString();
    list = split(val, ',');
 
float air = float(list[0]);

println("Airquality: " + air + " mg/m3 " );
m.updateMeter(int(air));
  }
}

Credits

Mirko Pavleski

Mirko Pavleski

151 projects • 1288 followers

Comments