Sharp GP2Y1010AU0F Dust Sensor Library

https://github.com/mickey9801/GP2Y1010AU0F

 

This is a wrapper library for Sharp GP2Y1010AU0F Optical Dust Sensor. The library is built base on this post.

Installation

  1. Download ZIP file of this repository;
  2. In the Arduino IDE, choose Sketch/Include Library/Add Zip Library;
  3. Navigate to the ZIP file, and click Open, the library will be placed in [Arduino directory]/libraries/GP2Y1010AU0F/;
  4. you should find the “GP2Y1010AU0F” in Sketch/Include Library from menu.

APIs

GP2Y1010AU0F

The constructor. Return a GP2Y1010AU0F object.

GP2Y1010AU0F::GP2Y1010AU0F(uint8_t ledPin, uint8_t measurePin)
 
ParametersTypeDescription
ledPinunsigned intSensor infrared LED pin number
measurePinunsigned intSensor analog measure pin number

begin

Setup sensor object. Return true when done.

bool GP2Y1010AU0F::begin()
 

read

Simply read the current dust density. Unit: ug/m3

float GP2Y1010AU0F::read()
 

Usage Example

/**
 * Example for using GP2Y1010AU0F Dust Sensor library
 * Created by Mickey Chan
 */

#include <GP2Y1010AU0F.h>

int measurePin = A0;   // Connect dust sensor analog measure pin to Arduino A0 pin
int ledPin     = 2;    // Connect dust sensor LED pin to Arduino pin 2

GP2Y1010AU0F dustSensor(ledPin, measurePin); // Construct dust sensor global object
float dustDensity = 0;

void setup() {
  Serial.begin(115200);
  Serial.println(F("GP2Y1010AU0F Dust Sensor Library Example"));

  dustSensor.begin();
}

void loop() {
  dustDensity = dustSensor.read();
  
  Serial.print("Dust Density = ");
  Serial.print(dustDensity);
  Serial.println(" ug/m3");

  delay(5000);
}
 

Reference

Sharp GP2Y1010AU0F data sheet
Air Quality Monitoring

 

You may also like...

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *