Difference between revisions of "Sensor-Dust"

From Microduino Wiki
Jump to: navigation, search
(Application)
(Application)
Line 36: Line 36:
 
<source lang="cpp">
 
<source lang="cpp">
  
#define FAN_PIN 10      //Fan control pin
+
#include <SoftwareSerial.h>
#define LED_PIN 12      //Sensor LED control pin
+
SoftwareSerial pmSerial(4, 5);  //PM2.5 sensor soft serail port
#define DUST_PIN A0    //Sensor detection
+
#define INTERVAL_pm25            200
#define TIME1 280     
+
unsigned long pm25_time = millis();
#define TIME2 40
 
#define TIME3 9680
 
  
int dustVal = 0;
+
void setup() {
float dustVoltage = 0;  
+
  Serial.begin(9600); // See the connection status in Serial Monitor
float dustDensity = 0;
+
  pmSerial.begin(2400);   //start the soft serial port at first
 +
}
  
void setup(){
+
void loop() {
   Serial.begin(9600);
+
   if (pm25_time > millis()) pm25_time = millis();
   pinMode(FAN_PIN, OUTPUT);
+
   if (millis() - pm25_time > INTERVAL_pm25) {
  pinMode(LED_PIN, OUTPUT);
+
    Serial.println(PM25()) ;
  digitalWrite(FAN_PIN, LOW);
+
    pm25_time = millis();   //更新计时器
 +
  }
 
}
 
}
  
void loop(){
+
float PM25() {
   digitalWrite(FAN_PIN, HIGH);    //Open the fan before detecting
+
   int data_s = 0;    //serial receives the data
   delay(3000);
+
   int num = -1;     //serial receives the data and counts
   digitalWrite(FAN_PIN, LOW);     //Close the fan after 3s delay
+
   int sum = 0;       //checksum
   digitalWrite(LED_PIN,LOW);     //Turn on LED inside the sensor  
+
   int cal[5];       //receive the data buffer
   delayMicroseconds(TIME1);       //Wait for 280us
+
  float dustDensity = 0; //PM2.5 intensity
  dustVal = analogRead(DUST_PIN); //Analog value sampling 
+
 
  delayMicroseconds(TIME2);      // Wait for 40us
+
   pmSerial.listen();
  digitalWrite(LED_PIN,HIGH);     //Turn off the LED
+
  while (1) {
  delayMicroseconds(TIME3);
+
    if (pmSerial.available() > 0) { //serail cache data
  dustVoltage = dustVal * (5.0/1024.0);   //Convert the analog value to voltage value.  
+
      data_s = pmSerial.read();   //read the serial cache data
  dustDensity = 0.17 * dustVoltage - 0.1; //Convert the voltage value to dust density (Output unit: mg / m³)
+
      if (data_s == 0xAA) {        //attain the starting position of the data frame
   Serial.println(dustDensity);
+
        num = 0;                 //start to count
   delay(1000);
+
       }
 +
      else if (num >= 0) {
 +
        cal[num++] = data_s; //read teh data and the number+1, and store the data into the buffer
 +
        if (num == 6) {        //read to the last bit of the data frame
 +
          sum = cal[0] + cal[1] + cal[2] + cal[3]; //calculate the checksum
 +
          if (sum == cal[4] && cal[5] == 0xFF) {    //checksum match, the last bit of the data frame is 0xFF, representing the data frame received is normal
 +
            dustDensity = (cal[0] * 256 + cal[1]) * (5.0 / 1024) * 550; //calculate the PM2.5 intensity, in ug/m3
 +
          }
 +
          else {    //the data received is abnormal
 +
            dustDensity = 0;   //clear the intensity
 +
          }
 +
          break;
 +
        }
 +
      }
 +
    }
 +
  }
 +
   pmSerial.stopListening();
 +
   return dustDensity ;
 
}
 
}
 
</source>
 
</source>

Revision as of 06:29, 26 August 2016

Language: English  • 中文
Microduino-Dust

Microduino-Dust is a PM2.5 sensor.

Sensor Pin Introduction

Sensor backpin.png
  • Pins of the sensor:
    • PIN1: GND
    • PIN2: VCC
    • General signal pins:
      • PIN3(IO1): digital/analog signal
      • PIN4(IO2): NC(null)
    • Special signal pins:
      • If it is IIC: IO1/IO2 are respectively SDA/SCL.
      • If it is soft serial port: IO1/IO2 are respectively tx/rx.
  • Special to Sensor-Dust sensor pins
    • PIN1: GND
    • PIN2: VCC
    • PIN3(IO1): Soft serial port tx
    • PIN4(IO2): Soft serial port rx


Microduino sensor can communicate with core module through the connection with Microduino-Module Sensor Hub.

Features

  • Adopt SHARP GP2Y1010AUOF air quality sensor;
  • Serial port communication.

Specification

  • Working voltage: 4.5V~5.5V
  • Detection sensitivity: 0.5V/0.1mg/m3
  • 1.27mm-spacing 4Pin-to-6Pin interface;
  • Soft serial port (D4,D5) communication.

Document

Development

Microduino-Dust can be applied in outdoor air quality detection or indoor dust detection.

Application

#include <SoftwareSerial.h>
SoftwareSerial pmSerial(4, 5);  //PM2.5 sensor soft serail port 
#define INTERVAL_pm25             200
unsigned long pm25_time = millis();

void setup() {
  Serial.begin(9600); // See the connection status in Serial Monitor
  pmSerial.begin(2400);   //start the soft serial port at first 
}

void loop() {
  if (pm25_time > millis()) pm25_time = millis();
  if (millis() - pm25_time > INTERVAL_pm25) {
    Serial.println(PM25()) ;
    pm25_time = millis();    //更新计时器
  }
}

float PM25() {
  int data_s = 0;    //serial receives the data 
  int num = -1;      //serial receives the data and counts
  int sum = 0;       //checksum
  int cal[5];        //receive the data buffer
  float dustDensity = 0;  //PM2.5 intensity

  pmSerial.listen();
  while (1) {
    if (pmSerial.available() > 0) { //serail cache data
      data_s = pmSerial.read();   //read the serial cache data
      if (data_s == 0xAA) {        //attain the starting position of the data frame
        num = 0;                  //start to count 
      }
      else if (num >= 0) {
        cal[num++] = data_s; //read teh data and the number+1, and store the data into the buffer
        if (num == 6) {        //read to the last bit of the data frame 
          sum = cal[0] + cal[1] + cal[2] + cal[3];  //calculate the checksum 
          if (sum == cal[4] && cal[5] == 0xFF) {    //checksum match, the last bit of the data frame is 0xFF, representing the data frame received is normal
            dustDensity = (cal[0] * 256 + cal[1]) * (5.0 / 1024) * 550; //calculate the PM2.5 intensity, in ug/m3
          }
          else {     //the data received is abnormal
            dustDensity = 0;    //clear the intensity
          }
          break;
        }
      }
    }
  }
  pmSerial.stopListening();
  return dustDensity ;
}
  • Software:
  • Stack all modules together and then connect the Dust sensor's fan control interface with the D10 pin of the Sensorhub with a wire.
  • Connect Microduino-Dust sensor's control detection interface to the IO splitter's IN interface with a wire. And then connect the IO splitter's A-OUT interface to Sensorhub A0, the IO splitter's *B-OUT interface to Sensorhub D12.
  • Open Arduino IDE, copy the program to IDE and then choose the right board from Tools→Board and then compile.
  • Select the right port from Tools→Serial Port in Arduino IDE after compiling, then download program.
  • After the download, you can open the serial monitor. After the Dust sensor's fan works for three seconds, the serial console will display the current air dust density and the Dust sensor will have another detection after one second.

Purchase

History

Pictures

  • Front
File:Microduino-Dust-F.JPG
Microduino-Dust Front
  • Back
File:Microduino-Dust -b.JPG
Microduino-Dust Back