Arduino Sketch (Example/Demo Source Code) - Sharp GP2Y1026AU0F Application Manual

Dust sensor, arduino uno/mega
Table of Contents

Advertisement

7
Application Guide for Sharp GP2Y1026AU0F Dust Sensor
In the source code to follow, you will see that the regular hardware serial port is used only
for printing output to the Arduino Serial Monitor at 9600 baud. The actual UART data from
the dust sensor's TxD terminal is received through a software serial port connected to
Arduino Pin 10 running at 2400 baud.
Instead of using a software serial port, you can use the regular hardware serial port
(Arduino RX0 pin instead of Pin 10) but make sure the sensor TxD terminal is disconnected
during uploading to Arduino or else the upload will fail. Another option is to use Serial1 on
Arduino Mega 2560 for communicating with the dust sensor.
The GP2Y1026AU0F dust sensor outputs 1 byte every 10ms through its TxD terminal.
According to the specification, it produces a 7-byte data frame as follows:
Thus it takes 70ms to output a data frame which is equivalent to 14 frames per second.
However, the dust sensor MCU applies averaging to the data readings in order to reduce
noise and so the output voltage values only change about once per second. This means
that you will see a lot of consecutive frames with an identical set of bytes (and voltage).

8. Arduino Sketch (example/demo source code)

Disclaimer: The following code is for demonstration/example purposes only. It is not
intended for production or commercial usage.
The example code shows how to read in a data frame, verify the checksum, and calculate
the output voltage. A linear calibration coefficient is then applied which converts the
output voltage into a dust density value.
The code is listed in two sections, Part A and Part B, which you must combine into the
same Arduino sketch file (
).
sharp_gp2y1026au0f_v2.ino
http://www.socle-tech.com

Advertisement

Table of Contents
loading

Table of Contents