2017年1月10日 星期二

Sharp Dust Sensor GP2Y1010AU

源自於
http://www.arduino.org/learning/tutorials/boards-tutorials/sharp-dust-sensor-gp2y1010au

Sharp Dust Sensor GP2Y1010AU


In this exercise with the use of our Arduino Yún, we learn to build our detector air quality. To do this we will use the capabilities of the GP2Y1010AU0F. It's a dust sensor by optical sensing system with an infrared emitting diode (IRED) and a phototransistor that are diagonally arranged into this device. It detects the reflected light of dust in air. Especially, it is effective to detect very fine particle like the cigarette smoke. The output of the sensor is an analog voltage proportional to the measured dust density, with a sensitivity of 0.5V/0.1mg/m3.

What do we need

  • an Arduino Yún board
  • a Sharp Optical Dust Sensor (GP2Y1010AU0F)
  • a breadboard
  • a 220 uF capacitor
  • a 150 Ohm resistor
  • a bunch of wires




The circuit

Image 

Be sure to follow the connections shown in the fritzing circuit  and in the next table :

Sharp pin 1 (V-LED)          => 5V (connected to 150ohm resistor,220 uF capacitor)
Sharp pin 2 (LED-GND)     => Arduino GND pin
Sharp pin 3 (LED)             => Arduino pin 2
Sharp pin 4 (S-GND)         => Arduino GND pin
Sharp pin 5 (Vo)               => Arduino A0 pin
Sharp pin 6 (Vcc)              => 5V

The code

/* Detector air quality with Arduino Yun and          **
** Optical Dust Sensor (GP2Y1010AU0F)              */

int dustPin = 0; // dust sensor - Arduino A0 pin
int ledP = 2;    

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
  
void setup(){
  Serial1.begin(230400);
  pinMode(ledP,OUTPUT);
}
  
void loop(){
  digitalWrite(ledP,LOW); // power on the LED
  delayMicroseconds(280);
  
  voMeasured = analogRead(dustPin); // read the dust value
  
  delayMicroseconds(40);
  digitalWrite(ledP,HIGH); // turn the LED off
  delayMicroseconds(9680);
  
  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);
  dustDensity = 0.17 * calcVoltage - 0.1;
  
  Serial1.print("Raw Signal Value(0-1023) : ");
  Serial1.print(voMeasured);
  
  Serial1.print(" - Voltage: ");
  Serial1.print(calcVoltage);
  
  Serial1.print(" - Dust Density: ");
  Serial1.println(dustDensity); // mg/m3
  
  delay(1000);
}
Write or paste code in Arduino IDE, then load the sketch on Yún board.

Python Serial Test

Read data from shell.
To do this we used the included library “pyserial”. You must create a python script to be launched from a terminal. Then connect to your board with ssh, create file serialTest.py with the following code and start it with the command  “python serialTest.py”. Read data now.

import serial
try:
     print "Trying..."
     arduino = serial.Serial('/dev/ttyATH0',230400)
except:
     print "Failed to connect on"
while True:
     x=arduino.readline()
     print x

Referral link: 

Sharp Dust Sensor GP2Y1010AU
Sharp Dust Sensor Sample Code

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...