夏普 GP2Y1010AU0F 灰尘传感器

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(电路)
(值判读)
 
(未显示1个用户的13个中间版本)
第2行: 第2行:
  
 
GP2Y1010 Datasheet: https://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
 
GP2Y1010 Datasheet: https://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
 +
 +
[http://wiki.jackslab.org/images/GP2Y1010AU_%E8%AE%BE%E8%AE%A1%E5%8F%82%E8%80%83%E6%8C%87%E5%8D%97%E5%8F%8A%E5%8E%9F%E7%90%86.pdf 夏普 GP2Y1010AU 设计参考]
  
 
<br><br>
 
<br><br>
第39行: 第41行:
 
  Sharp pin 1 (V-LED)  => 5V (connected to 150ohm resister)
 
  Sharp pin 1 (V-LED)  => 5V (connected to 150ohm resister)
 
  Sharp pin 2 (LED-GND) => Arduino GND pin
 
  Sharp pin 2 (LED-GND) => Arduino GND pin
  Sharp pin 3 (LED)    => Arduino pin 2
+
  Sharp pin 3 (LED)    => Arduino pin 4
 
  Sharp pin 4 (S-GND)  => Arduino GND pin
 
  Sharp pin 4 (S-GND)  => Arduino GND pin
  Sharp pin 5 (Vo)      => Arduino A0 pin
+
  Sharp pin 5 (Vo)      => Arduino A4 pin
 
  Sharp pin 6 (Vcc)    => 5V
 
  Sharp pin 6 (Vcc)    => 5V
 
  */
 
  */
#include <SPI.h>
 
#include <Ethernet.h>
 
 
#include <stdlib.h>
 
#include <stdlib.h>
  
byte mac[] = {
+
long lastConnectionTime = 0;       // last time you update to the server, in milliseconds
  0x90, 0xA2, 0xDA, 0x0D, 0x27, 0x55};
+
const int postingInterval = 10000; // delay between two updates
IPAddress ip(192,168,1,90);
+
IPAddress gateway(192,168,1,1);
+
IPAddress subnet(255, 255, 255, 0);
+
  
// initialize the library instance:
+
int dustPin = 4;
EthernetClient client;
+
int ledPower = 4;
 +
int delayTime = 280;
 +
int delayTime2 = 40;
 +
float offTime = 9680;
  
long lastConnectionTime = 0;        // last time you connected to the server, in milliseconds
+
int dustVal = 0;
boolean lastConnected = false;      // state of the connection last time through the main loop
+
int i = 0;
const int postingInterval = 10000;  //delay between updates to Pachube.com
+
float ppm = 0;
 
+
int dustPin=0;
+
int ledPower=2;
+
int delayTime=280;
+
int delayTime2=40;
+
float offTime=9680;
+
 
+
int dustVal=0;
+
int i=0;
+
float ppm=0;
+
 
char s[32];
 
char s[32];
 
float voltage = 0;
 
float voltage = 0;
第79行: 第69行:
 
   pinMode(ledPower,OUTPUT);
 
   pinMode(ledPower,OUTPUT);
  
  // give the ethernet module time to boot up:
 
 
   delay(1000);
 
   delay(1000);
  // start the Ethernet connection:
+
   i = 0;
  if (Ethernet.begin(mac) == 0) {
+
    Serial.println("Failed to configure Ethernet using DHCP");
+
    // Configure manually:
+
    Ethernet.begin(mac, ip);
+
  }
+
   i=0;
+
 
   ppm =0;
 
   ppm =0;
 
}
 
}
  
 
void loop(){
 
void loop(){
   i=i+1;
+
   i = i + 1;
 
   digitalWrite(ledPower,LOW); // power on the LED
 
   digitalWrite(ledPower,LOW); // power on the LED
 
   delayMicroseconds(delayTime);
 
   delayMicroseconds(delayTime);
   dustVal=analogRead(dustPin); // read the dust value
+
   dustVal = analogRead(dustPin); // read the dust value
   ppm = ppm+dustVal;
+
   ppm = ppm + dustVal;
 
   delayMicroseconds(delayTime2);
 
   delayMicroseconds(delayTime2);
 
   digitalWrite(ledPower,HIGH); // turn the LED off
 
   digitalWrite(ledPower,HIGH); // turn the LED off
 
   delayMicroseconds(offTime);
 
   delayMicroseconds(offTime);
  
 
+
   if((millis() - lastConnectionTime > postingInterval)) {
   // if there's incoming data from the net connection.
+
  // send it out the serial port.  This is for debugging
+
  // purposes only:
+
  if (client.available()) {
+
    char c = client.read();
+
    //Serial.print(c);
+
  }
+
 
+
  // if there's no net connection, but there was one last time
+
  // through the loop, then stop the client:
+
  if (!client.connected() && lastConnected) {
+
    Serial.println();
+
    Serial.println("disconnecting.");
+
    client.stop();
+
  }
+
 
+
  // if you're not connected, and ten seconds have passed since
+
  // your last connection, then connect again and send data:
+
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+
 
     voltage = ppm/i*0.0049;
 
     voltage = ppm/i*0.0049;
 
     dustdensity = 0.17*voltage-0.1;
 
     dustdensity = 0.17*voltage-0.1;
第136行: 第100行:
 
     dataString += ",";
 
     dataString += ",";
 
     dataString += dtostrf(ppmpercf, 8, 0, s);
 
     dataString += dtostrf(ppmpercf, 8, 0, s);
 +
 
     i=0;
 
     i=0;
 
     ppm=0;
 
     ppm=0;
 +
 
     Serial.println(dataString);
 
     Serial.println(dataString);
     sendData(dataString);
+
     lastConnectionTime = millis();
    Serial.println(dataString);
+
    delay(1000);
+
 
   }
 
   }
  // store the state of the connection for next time through
+
 
  // the loop:
+
   delay(3000);
   lastConnected = client.connected();
+
 
}
 
}
  
// this method makes a HTTP connection to the server:
+
</source>
void sendData(String thisData) {
+
  // if there's a successful connection:
+
  if (client.connect("www.pachube.com", 80)) {
+
    Serial.println("connecting...");
+
    // send the HTTP PUT request.
+
    // fill in your feed address here:
+
    client.print("PUT /api/YOUR_FEED_HERE.csv HTTP/1.1\n");
+
    client.print("Host: www.pachube.com\n");
+
    // fill in your Pachube API key here:
+
    client.print("X-PachubeApiKey: YOUR_KEY_HERE\n");
+
    client.print("Content-Length: ");
+
    client.println(thisData.length(), DEC);
+
  
    // last pieces of the HTTP PUT request:
+
<br><br>
    client.print("Content-Type: text/csv\n");
+
    client.println("Connection: close\n");
+
  
    // here's the actual content of the PUT request:
+
== 简化版程序 ==
    client.println(thisData);
+
  
    // note the time that the connection was made:
+
<source lang=cpp>
    lastConnectionTime = millis();
+
int dustPin=4;
 
+
int dustVal=0;
  }
+
  else {
+
int ledPower=4;
    // if you couldn't make a connection:
+
int delayTime=280;
    Serial.println("connection failed");
+
int delayTime2=40;
  }
+
float offTime=9680;
 +
void setup(){
 +
Serial.begin(9600);
 +
pinMode(ledPower,OUTPUT);
 +
}
 +
 +
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
 +
delayMicroseconds(delayTime2);
 +
digitalWrite(ledPower,HIGH); // turn the LED off
 +
delayMicroseconds(offTime);
 +
 +
delay(3000);
 +
Serial.println(dustVal);
 
}
 
}
 
</source>
 
</source>
 +
 +
<br><br>
 +
 +
== 值判读 ==
 +
 +
> https://www.airnow.gov/index.cfm?action=airnow.calculator
 +
 +
Air Quality Chart - Small Count Reading (0.5 micron)+
 +
 +
<pre>
 +
3000 +    = VERY POOR
 +
1050-3000  = POOR
 +
300-1050  = FAIR
 +
150-300    = GOOD
 +
75-150    = VERY GOOD
 +
0-75      = EXCELLENT
 +
</pre>
  
 
<br><br>
 
<br><br>
第187行: 第168行:
 
* http://sensorapp.net/sharp-dust-sensor-and-arduino/
 
* http://sensorapp.net/sharp-dust-sensor-and-arduino/
 
* https://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
 
* https://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
* http://blog.yeelink.net/?p=184
 
  
 
<br><br>
 
<br><br>

2018年11月19日 (一) 19:35的最后版本

目录

[编辑] 1 概述

GP2Y1010 Datasheet: https://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf

夏普 GP2Y1010AU 设计参考



[编辑] 2 PIN

Sharp.gy1010.pin.jpg

Sharp pin 1 (V-LED)   => 5V (connected to 150ohm resister)
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



[编辑] 3 电路

Sharp.gy1010.circuit.gif



[编辑] 4 程序

/*
 Interface to Sharp GP2Y1010AU0F Particle Sensor
 Program by Christopher Nafis 
 Written April 2012
 
 http://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
 http://sensorapp.net/?p=479
 
 Sharp pin 1 (V-LED)   => 5V (connected to 150ohm resister)
 Sharp pin 2 (LED-GND) => Arduino GND pin
 Sharp pin 3 (LED)     => Arduino pin 4
 Sharp pin 4 (S-GND)   => Arduino GND pin
 Sharp pin 5 (Vo)      => Arduino A4 pin
 Sharp pin 6 (Vcc)     => 5V
 */
#include <stdlib.h>

long lastConnectionTime = 0;        // last time you update to the server, in milliseconds
const int postingInterval = 10000;  // delay between two updates

int dustPin = 4;
int ledPower = 4;
int delayTime = 280;
int delayTime2 = 40;
float offTime = 9680;

int dustVal = 0;
int i = 0;
float ppm = 0;
char s[32];
float voltage = 0;
float dustdensity = 0;
float ppmpercf = 0;

void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);

  delay(1000);
  i = 0;
  ppm =0;
}

void loop(){
  i = i + 1;
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(delayTime);
  dustVal = analogRead(dustPin); // read the dust value
  ppm = ppm + dustVal;
  delayMicroseconds(delayTime2);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(offTime);

  if((millis() - lastConnectionTime > postingInterval)) {
    voltage = ppm/i*0.0049;
    dustdensity = 0.17*voltage-0.1;
    ppmpercf = (voltage-0.0256)*120000;
    if (ppmpercf < 0)
      ppmpercf = 0;
    if (dustdensity < 0 )
      dustdensity = 0;
    if (dustdensity > 0.5)
      dustdensity = 0.5;
    String dataString = "";
    dataString += dtostrf(voltage, 9, 4, s);
    dataString += ",";
    dataString += dtostrf(dustdensity, 5, 2, s);
    dataString += ",";
    dataString += dtostrf(ppmpercf, 8, 0, s);

    i=0;
    ppm=0;

    Serial.println(dataString);
    lastConnectionTime = millis();
  }

  delay(3000);
}



[编辑] 5 简化版程序

int dustPin=4;
int dustVal=0;
 
int ledPower=4;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
}
 
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
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(offTime);
 
delay(3000);
Serial.println(dustVal);
}



[编辑] 6 值判读

> https://www.airnow.gov/index.cfm?action=airnow.calculator

Air Quality Chart - Small Count Reading (0.5 micron)+

3000 +     = VERY POOR
1050-3000  = POOR
300-1050   = FAIR
150-300    = GOOD
75-150     = VERY GOOD
0-75       = EXCELLENT



[编辑] 7 参考

























个人工具
名字空间

变换
操作
导航
工具箱