0% found this document useful (0 votes)
16 views

arduino code for dust sensor

arduino code for dust sensor

Uploaded by

Wajdi BELLIL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

arduino code for dust sensor

arduino code for dust sensor

Uploaded by

Wajdi BELLIL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

GP2Y1014AU0F Dust Sensor Pinout

The GP2Y1014AU0F Dust Sensor module features 6 pins: V-LED, LED-


GND, LED, S-GND, VOUT, and VCC. The sensor provides an analog
output, which should be connected to the ADC of a microcontroller to
measure particulate matter (PM) in the air. The pinout of the
GP2Y1014AU0F Dust Sensor is detailed below:

V-LED: This is the power pin for the LED. Connect it to the 5V pin of the Arduino using a
150Ω current-limiting resistor.

LED-GND: This is the ground pin for the LED. Connect it to the Arduino's ground pin.

LED: This pin controls the LED and can be used to turn it on or off. Connect it to any digital
pin on the Arduino.

S-GND: This is the ground pin for the pulse dust sensor module and should be connected to
the ground pin of the Arduino.

VOUT: This is the output pin of the dust sensor module. Connect it to any of the Arduino's
analog pins.

VCC: This is the power pin of the dust sensor module. Connect it to either the 5V or 3.3V pin
of the Arduino.Arduino
GP2Y1014AU0F Dust Sensor
Circuit Connection Diagram
Now that we fully understand how the GP2Y1014AU0F Dust Sensor
operates, we can connect all the necessary wires to the Arduino and
write the code to retrieve data from the sensor module. The wiring
diagram for connecting the GP2Y1014AU0F Dust Sensor to the
Arduino is shown below.

Arduino Code for Interfacing GP2Y1014AU0F


Dust Sensor Module with Arduino
The Arduino code for processing data from the GP2Y1014AU0F
Sensor is straightforward and easy to follow. The analog voltage
output from the sensor is simply converted into digital data to obtain
the results.

We begin the code by defining the analog input pin for the sensor, as
well as a digital pin to control the LED. Then, we define three
variables to store the timing values needed to calculate the dust
concentration measured by the sensor. Additionally, we define three
float variables to hold the sensor's output results.

int measurePin = A0; //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;
Next is the setup function. In this function, we initialize the serial
communication for debugging purposes and set the LED pin as an
output.

void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
}
Next is the loop function, where we begin the measurement process
as recommended by the datasheet. The entire measurement process
takes about 10ms, with a sampling period of 0.28ms. First, we set
the LED pin to low, which turns the LED on, and use the
delayMicroseconds() function to create a 280µS (0.28ms) delay, as
suggested by the datasheet. Then, we take our sample and
introduce another 40µS delay to ensure the pulse width remains at
0.32ms (320µS). Finally, we wait for the remaining 9680µS before
the next cycle.

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

Next, we calculate the voltage from the ADC value. Ensure that your
Arduino is powered by a proper +5V supply and not through USB, as
using USB power could lead to inaccurate results.

calcVoltage = voMeasured * (5.0 / 1024.0);

Finally, we calculate the concentration of suspended dust particles


using the linear equation provided by Chris Nafis. The result is given
in micrograms per cubic meter (µg/m³) and is printed to the serial
monitor window.

dustDensity = 170 * calcVoltage - 0.1;


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

You might also like