#dustsensor
Explore tagged Tumblr posts
Text
Matlab Euro CAQI levels converter for Thingspeak service
I decided to move all calculations & aproximations from arduino code to Thingspeak service. Sensor will be only responsible of uploading raw data to Thingspeak service. This significantly reduces my efforts to upoad new software to sensor module.
Here are functions written in Matlab language that is used by Thingspeak to perform data processing and converting PM2.5 levels to CAQI Euro standard.
%// Euro AQI Standard %// AQI formula: https://en.wikipedia.org/wiki/Air_Quality_Index function output = toAQI(I_high, I_low, C_high, C_low, C) aqiResult = (I_high - I_low) * (C - C_low) / (C_high - C_low) + I_low end function output = calculateAQI25(density) d10 = density * 10; if d10 <= 150 output = toAQI(25, 0, 150, 0, d10); elseif d10 <= 300 output = toAQI(50, 26, 300, 151, d10); elseif d10 <= 500 output = toAQI(75, 51, 500, 301, d10); elseif d10 <= 1000 output = toAQI(100, 76, 1000, 501, d10); elseif d10 <= 3000 output = toAQI(300, 101, 3000, 1001, d10); else output = 1001; end end %// Polution levels function output = aqi25captions(density) if density <= 25 output = 'Perfect =)'; elseif density <= 50 output = 'Good :)'; elseif density <= 75 output = 'Moderate :|'; elseif density <= 100 output = 'Unhealthy :('; elseif density <= 200 output = 'Bad :O'; else output = 'Hazardous X('; end end
0 notes
Text
ホコリセンサーで花粉センサーとか作るらしい。すごい RaspberryPi DustSensor https://t.co/bcaxx3jVRb
ホコリセンサーで花粉センサーとか作るらしい。すごい RaspberryPi DustSensor https://t.co/bcaxx3jVRb
— Hiroshi Sano (@hrs_sano645) March 9, 2017
from Twitter https://twitter.com/hrs_sano645 March 09, 2017 at 03:45PM via IFTTT
0 notes
Text
Air Pollution Sensor - Midterm Project Prototype

Seen above, Nga and I soldered the optical dust sensor to 6 wires since our matching connector needed crimp pins, which we did not have. But firstly, we had break into our optical dust sensor to expose the 6 pins in order to solder them to our wires. We hot glue gunned over the soldered pins and wires since it was so difficult to solder the pins without touching the adjacent pins to the left and right of each pin. Unfortunately, the gun did not keep the delicate soldering in place (the wires came loose from the pins) and we did not take a video of the working prototype at the time (beginner's mistake!).
Before the wires came loose from the soldering, we were able to get a range of values in the serial monitor of the arduino processing program, from about 150 (just sensing the air/particles in the VFL) to around the 700s when we blew smoke at the sensor.
The tutorial we found most helpful was this one from sensorapp. We wired accordingly and used the code, both worked seamlessly.
After we detected the range of air quality. We started to work on the output. We hooked up a speaker to digital 8 pin on the arduino and in our code we set a threshold for the pitch. So for values greater than or equal to 0 and less than or equal to 200 the speaker would beep a low pitch sound. And for values greater than or equal to 201 and less than or equal to 900, we multiplied the pitch by 2 to get a higher beep.
We started with the arduino tutorial for tone and reworked it using if and else statements.
This is our arduino code:
int dustPin=0; int dustVal=0; int ledPower=2; int delayTime=280; int delayTime2=40; float offTime=9680; #include "pitches.h" //int melody[] = { // NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 }; void setup() { Serial.begin(9600); pinMode(ledPower,OUTPUT); pinMode(4, OUTPUT); /* // iterate over the notes of the melody: for (int dustVal = 0; dustVal < 300; dustVal++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[dustVal]; tone(8, melody[dustVal],noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); } */ } void loop(){ // ledPower is any digital pin on the arduino connected to Pin 3 on the sensor digitalWrite(ledPower,LOW); // power on the LED delayMicroseconds(delayTime); dustVal=analogRead(dustPin); // read the dust value via pin 5 on the sensor if(dustVal >=0 && dustVal<=200){ tone(8, dustVal,100); }else if(dustVal >=201 && dustVal<=900){ tone(8, dustVal*2,500); } //int noteDuration = 1000/noteDurations[dustVal]; //tone(8, melody[dustVal],noteDuration); delayMicroseconds(delayTime2); digitalWrite(ledPower,HIGH); // turn the LED off delayMicroseconds(offTime); Serial.println(dustVal); delay(500); }
This is the arduino code for the class "pitches.h"
#define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
We also tried to connect an LED light to the arduino. We wanted to make the LED light fade in and out according to the range of non-smoke and smoke particles in the air. However, we weren't able to get that to work (that is why we moved on to a sound output). The LED light did fade in and out, but the serial monitor stopped spitting out values. We could not get the two to work at the same time. So we weren't sure what range the LED light was fading in and out too... Overall we are pleased by our initial test trial. Back to the drawing board in terms of resoldering and making sure it stays put. Perhaps crazy glue as an alternative? Also we would like to have two outputs, the LED light and the beeping of the speaker. Perhaps we will have to have a parallel circuit between the two outputs since we only have one GND pin available in our arduino leonardo (the other two are used by the optical dust sensor).
Ideally, for our final product, we would like to switch to the FLORA arduino (3.3V might be an issue), RGB LED light, and the speaker, and make a wearable device to be worn by babies, moms to be, or clipped onto the baby carriages or cribs.
Big THANK YOU to Tak (VFL)!
2 notes
·
View notes
Text
Arduino PM2.5 / PM10 Pollution Sensor based on Sharp Optical Dust Sensor GP2Y1010AU0F Part #2
In previous Part #1 I’ve described basics of Sharp Optical Dust Sensor. Now it is time to connect it to Arduino and run the code, to read sensor data and convert it to useful format.
I’ve bought cheap and small Arduino Nano board, breadboard and bunch of wires because I don’t like to spend time with soldering. I am going to build prototype, and later create smaller solution with LCD panel, some buttons to change modes and batteries pack.
I’ve got following solution, that could show some dust measurement results. I’ve spend a lot of time to proceed data, since that sensor produces analog signal of optical air measurement, and it should be converted to some useful units like milligrams per square meter.

As I mentioned in previous Part #1 my goal is to measure PM2.5 & PM10 pollution. So 25 µg/m3 of PM2.5 is considered as 100% pollution value. And I want to know when level is more than 300% which is considered as unhealthy conditions and it is better to stay at home and not open the windows.
Since PM2.5 is more dangerous, I would like to be able to measure PM2.5 & PM10 separately. But unfortunately GP2Y1010AU0F is unable to distinguish between different particles and shows general pollution level.
So, lets review how to connect Sharp Optical Dust Sensor to Arduino Nano board and show data on computer, connected to Arduino Nano via USB cable. If you have some LCD display then we also could use that to show data and have mobile solution.
Components:
Arduino Nano board
Sharp Optical Dust Sensor GP2Y1010AU0F
Waveshare Dust Sensor connection board
Breadboard
Jumper cables
16x2 LCD Display (optional)
Fig 1 - Arduino Nano board
Fig 2 - Waveshare Dust Sensor board with connected GP2Y1010AU0F
Fig 3 - Breadboard
Sensor connection
Waveshare Sensor Board has 4 pin connector and is very easy to connect it to Arduino.
Pin 1 VCC is connected to Arduino 5V pin.
Pin 2 GND is connected to any Arduino ground pin.
Pin 3 AOUT (Analog Output) is connected to Arduino A0 pin.
Pin4 ILED (Infrared LED) is connected to Arduino D7 pin
Whole system is powered by mini USB connector that is located on Arduino Nano board. Waveshare Dust Sensor board has red LED, that lights if power is connected to VCC.
In next Part #3 we will review Arduino program that is designed to read analog signals from Arduino A0 port.
Later we will convert analog data to pollution levels based on US and Europe standards.
Open this chart as large image in another post...
Go to next Part #3: Arduino PM2.5 Sensor based on Sharp Optical Dust Sensor GP2Y1010AU0F
Part #3
2 notes
·
View notes
Text
Arduino PM2.5 / PM10 Pollution Sensor based on Sharp Optical Dust Sensor GP2Y1010AU0F Part #6
I’ve performed some measurements of output signan to ILED and found that all Arduino programs that I’ve found on internet have incorrect sample timing.
Typical code is:
digitalWrite(PIN_LED, HIGH); // power on the LED
delayMicroseconds(280);
int analogData = analogRead(SENSOR_PIN);
delayMicroseconds(40);
digitalWrite(PIN_LED, LOW); // power off the LED
delayMicroseconds(9680);
280 + 40 + 9680 = 10000
Excelent according to sensor specification
But no one takes to consideration that analogRead is slow operation, that lasts for about 10 microseconds. Other operations also takes some time.
So, I’ve decided to check real pulse timings.
I’ve had Salae Logic usb digital osciloscope, that can measure impulse lenght, and I’ve performed several tests.
That code above gives following picture in analyzer program window:
Total period T = 10.28ms
ILED light time = 0.4391ms instead 0.32
As you see it is more than expected. If we calculate how much takes analogRead = 10280 - 10000 = 280 microseconds.
So I’ve decided to remove 40 microseconds delay befor switch-off
digitalWrite(PIN_LED, HIGH); // power on the LED
delayMicroseconds(280);
int analogData = analogRead(SENSOR_PIN);
delayMicroseconds(40);
digitalWrite(PIN_LED, LOW); // power off the LED
delayMicroseconds(9680);
New walues are slightly better
Total period T = 10.19ms
ILED light time = 0.398 ms instead 0.32
Finaly, to calculate how much time is needed to switch-on/off ILED I’ve calculated following code:
digitalWrite(PIN_LED, LOW); // power off the LED
digitalWrite(PIN_LED, HIGH); // power on the LED
digitalWrite(PIN_LED, LW); // power off the LED
So, each operation takes 0.05ms
After all I’ve decreased samples sleep delay time to 9500 to have period time close to 10ms.
https://github.com/vlytsus/arduinosensor
0 notes
Text
Arduino PM2.5 / PM10 Pollution Sensor based on Sharp Optical Dust Sensor GP2Y1010AU0F Part #5
I’ve decided to add LCD dispaly to the project to show calculated value. In this case dust sensor will be autonomous. I've used 16x2 LCD display HD44780. To handle display printing I've used LiquidCrystal library. By default enabled only serial printing: #define SERIAL_PRINT true. If you would like to enable LCD printing please set #define LCD_PRINT true.
Since I've got a lot of noise during measurements, I decided to filter it out from final results. It is performed by calculating median over 5 samples, and from that value is removed maximum & minimum results (avgDust - maxDust - minDust) / (SAMPLES_PER_COMP - 2). But this is not the end. To display data more smoothly I've added one more filter - stack[100] to store already filtered data and calculate median once more, over 100 samples.
I still was not happy with result's that I've achieved. My sensor was able to show hazardous concentrations of dust, but calculated dust veight values ug/m3 was far from data that I've got from official sensors, published in internet. I've found very usefull article about similar project, performed by Matthias Budde, Mathias Busse, and Michael Beigl from Karlsruhe Institute of Technology http://www.teco.edu/~budde/publications/MUM2013_budde.pdf
I was on the right direction. Now I need to perform additional calibration and include ambient temperature to calculations.
I've fixed several bugs and improved dust calculation formulas. All code sources and last chnages please check at: https://github.com/vlytsus/arduinosensor
/* *************************************************************** * ************* GP2Y1010AU0F Scharp Dust Sensor ***************** * *************************************************************** * Dust sensor calculates dust density based on reflected * infrared light from IR diode. Light brightness coresponds * to amount of dust in the air. Following program is responsible * to light-up IR diode, perform dust sampling and swith-off diode, * according to GP2Y1010AU0F specification. * Arduino program performs sequence of several measurements, * filters input data by mid point calulation based on several * measurements, to avoid voltage spikes. Then it performs dust * values transformation to ug/m2. Finaly calculated data could * be printed to Arduino serial output or to LCD display. * *************************************************************** * AQI Index could be calculated as * -------------------------------- * PM2.5 ug | AQI | Pollution * =========|=========|============ * 0-35 | 0-50 | Excelent * ---------|---------|------------ * 35-75 | 51-100 | Average * ---------|---------|------------ * 75-115 | 101-150 | Light * ---------|---------|------------ * 115-150 | 151-200 | Modrate * ---------|---------|------------ * 150-250 | 201-300 | Heavy * ---------|---------|------------ * 250-500 | > 300 | Serious * ---------|---------|------------ */ #include <LiquidCrystal.h> #include <stdlib.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define ADC_BASE_V 1100.0 //5000 //mv 4500 - real USB voltage #define MICROGR_2_MLVOLT_RATIO 0.2 //ug/m3 / mv #define ADC_RESOLUTION 1023.0 #define PIN_LED 7 #define PIN_ANALOG_OUT 0 #define POWER_ON_LED_DELAY 280 //#define POWER_ON_LED_SLEEP 40 // not used, digital read takes about 100 microseconds #define POWER_OFF_LED_DELAY 9500 #define SENSOR_PIN 0 #define DISPLAY_REFRESH_INTERVAL 30 #define SAMPLES_PER_COMP 5 #define STACK_SIZE 100 #define MAX_UNSIGNED_INT 65535 #define LCD_PRINT true #define SERIAL_PRINT true #define RAW_OUTPUT_MODE false // if true then raw analog data 0-1023 will be printed // Additional correction after calibration // to calculate dust as ug/m3 // by minimum & maximum values. // According to specification: min=600mv; max=3600mv // using linear function: y = a*x + b; // here x is voltage = ADC_val * V_adc_base / ADC_resolution #define A_CORRECTION 2.36 #define B_CORRECTION -76 float a_correction = A_CORRECTION * (ADC_BASE_V / ADC_RESOLUTION); unsigned int stack[STACK_SIZE+1];// stack is used to calculate middle value for display output unsigned int stackIter; // current stack iteration unsigned int refresh; // current display counter, used to not print data too frequently char str_temp[6]; void setup() { if(LCD_PRINT){ // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("-=Dust+Sensor=-"); } if(ADC_BASE_V < 4000) analogReference(INTERNAL); pinMode(PIN_LED, OUTPUT); pinMode(PIN_ANALOG_OUT, INPUT); digitalWrite(PIN_LED, LOW); stackIter = 0; refresh = 0; for(int i = 0; i < STACK_SIZE ; i++){ stack[i] = 0; } if(SERIAL_PRINT) Serial.begin(9600); } void loop(void){ if(stackIter >= STACK_SIZE) stackIter = 0; stack[stackIter] = computeSensorSequence(); if(refresh < DISPLAY_REFRESH_INTERVAL){ refresh++; }else{ refresh = 0; //calculate midpoint value and print int yResult = a_correction * calculateStackMidVal() + B_CORRECTION; if(yResult > 0){ print(yResult); } } stackIter++; } unsigned int computeSensorSequence(){ //perform several measurements and store to stack //for later midpoint calculations unsigned int maxDust = 0; unsigned int minDust = MAX_UNSIGNED_INT; unsigned long avgDust = 0; unsigned int dustVal = 0; //perform several sensor reads and calculate midpoint for(int i = 0; i< SAMPLES_PER_COMP; i++){ dustVal = readRawSensorData(); if (dustVal > 0){ //find max dust per sample if(dustVal > maxDust) maxDust = dustVal; //find min dust per sample if(dustVal < minDust) minDust = dustVal; avgDust += dustVal; } } //filter input data //don't take to consideration max & min values per sample //and save average to stack return (avgDust - maxDust - minDust) / (SAMPLES_PER_COMP - 2); } unsigned int calculateStackMidVal(){ int midVal = 0; for(int i = 0; i < STACK_SIZE ; i++){ midVal += stack[i]; } return midVal / STACK_SIZE; } unsigned int readRawSensorData(){ unsigned int analogData; //ADC value 0-1023 digitalWrite(PIN_LED, HIGH); // power on the LED delayMicroseconds(POWER_ON_LED_DELAY); analogData = analogRead(SENSOR_PIN); //delayMicroseconds(POWER_ON_LED_SLEEP);//not used, digital read takes about 100 microseconds digitalWrite(PIN_LED, LOW); // power off the LED delayMicroseconds(POWER_OFF_LED_DELAY);//9500 return analogData; } void print(int val){ print(String(val)); } void print(String msg){ if(SERIAL_PRINT) Serial.println(msg); if(LCD_PRINT){ lcd.setCursor(0, 1); lcd.print(msg); } }
0 notes
Text
Arduino PM2.5 / PM10 Pollution Sensor based on Sharp Optical Dust Sensor GP2Y1010AU0F Part #4
It’s time to get payload from data that we’ve received from dust sensor. There are a lot of controversial ideas about how to calculate dust particles weight per volume, based on air transparency and measured light from infrared diode. We should take to consideration several factors that could lead to incorrect results during measurements and try to eliminate them or add corrections to formula, that will be used to calculate dust density.
Voltage
Arduino will perform calculations based on measured voltage that comes to analog input. According to specification Arduino board & dust sensor are powered by 5V, but we are living in not ideal world. The USB 1.x and 2.0 specifications provide a 5 V supply on a single wire to power connected USB devices. The specification provides for no more than 5.25 V and no less than 4.75 V (5 V ± 5%) between the positive and negative bus power lines. That could lead to significant errors in calculations.
The sensor lower voltage output if there is no dust is specified from 0V to 1.5V. The 0V is more of a problem, as the ADC’s often don’t operate close to ground values.
Humidity
Since sensor is based on photoelectric effect from dust particles, that appears in focus of photo-resistor & reflected infrared diode light, dust sensor could calculate water fog particles as pollution. Also fog could condensate on lenses, that also could lead to decrease quality of results.
Sun light
Some developers mentioned that direct sun light has impact on measurement results. Possible that caused by light that hit to lenses or dust particles thru the sensor hole.
Temperature
Despite dust sensor specification promises that it would work in different temperature conditions from −10 to +65 °C, but according to experiment results with open/closed sensor hole, it calculates different values depending on ambient temperature. Also I’ve observed significant pollution data right after dust sensor is moved from cold to warm area. It could be caused by water fog condensation on cold lenses. For example see what will happen with your lenses if camera will be long time on cold.
Particles size
During my experiments I saw significant spikes in results. I’ve tried to perform some basic math results filtering to eliminate spikes data if there is significant difference from calculated medium value. But I am not sure that I was right, when decided to eliminate such spikes from final calculations. Possible that huge dust particles that appears in infrared beam focus could cause such spikes. If that is true - we shouldn’t remove them from results and consider as pollution. But from other side, huge particles are less hazardous, so, I have no final decision here. I am going to perform more measurements producing big particles from rug dust and fine particles from cigarette smoke to compare amount of spices in per each pollution type. Maybe in final solution I will add some kind of lightweight HEPA filter, to measure only PM2.5 particles and ignore huge dust particles.
Sampling rate
According to GP2Y1010AU0F datasheet we should follow 10ms sample rate to get correct measurement results. Possible it dictated by sensor self RC parameters, that could cause significant impact on infrared diode light brightness or photo-resistor currents. I’ve saw the same Arduino code samples in many internet articles, that performs reading from analog input and does 40 microseconds delay after that, to meet sensor specification.
delayMicroseconds(280); DUST = analogRead(SENSOR_PIN); // read data delayMicroseconds(40);
But probably performing all those developers haven’t taken to consideration one fact, that Arduino takes about 100 microseconds to read an analog input.
https://www.arduino.cc/en/Reference/AnalogRead
So probably this peace of code is incorrect: delayMicroseconds(40);
So we’ve reviewed several aspects that we need take to consideration during analog input interpretation.
More about real working code will be in next Part #5.
0 notes