Dust Sensor



  • I think my dust sensor is working fine with the second sketch i have attached in this post.
    I think some rows are missing in the MySensors sketch

    I can be wrong but my dust sensor didn't work with MySensors sketch, i had to modify it.

    Anyone that have this sensor and a working sketch?

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - epierre
     * Converted to 1.4 by Henrik Ekblad
     * 
     * DESCRIPTION
     * Arduino Dust Sensort
     *
     * connect the sensor as follows :
     * 
     *   VCC       >>> 5V
     *   A         >>> A0
     *   GND       >>> GND
     *
     * Based on: http://www.dfrobot.com/wiki/index.php/Sharp_GP2Y1010AU 
     * Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
     * 
     * http://www.mysensors.org/build/dust
     * 
     */
    
    #include <MySensor.h>  
    #include <SPI.h>
    
    #define CHILD_ID_DUST 0
    #define DUST_SENSOR_ANALOG_PIN 1
    
    unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
    //VARIABLES
    int val = 0;           // variable to store the value coming from the sensor
    float valDUST =0.0;
    float lastDUST =0.0;
    int samplingTime = 280;
    int deltaTime = 40;
    int sleepTime = 9680;
    float voMeasured = 0;
    float calcVoltage = 0;
    float dustDensity = 0;
    
    MySensor gw;
    MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL);
    
    void setup()  
    {
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Dust Sensor", "1.1");
    
      // Register all sensors to gateway (they will be created as child devices)
      gw.present(CHILD_ID_DUST, S_DUST);  
       
    }
    
    void loop()      
    {    
      uint16_t voMeasured = analogRead(DUST_SENSOR_ANALOG_PIN);// Get DUST value
    
      // 0 - 5V mapped to 0 - 1023 integer values
      // recover voltage
      calcVoltage = voMeasured * (5.0 / 1024.0);
    
      // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
      // Chris Nafis (c) 2012
      dustDensity = (0.17 * calcVoltage - 0.1)*1000;
     
      Serial.print("Raw Signal Value (0-1023): ");
      Serial.print(voMeasured);
      
      Serial.print(" - Voltage: ");
      Serial.print(calcVoltage);
      
      Serial.print(" - Dust Density: ");
      Serial.println(dustDensity); // unit: ug/m3
     
      if (ceil(dustDensity) != lastDUST) {
          gw.send(dustMsg.set((int)ceil(dustDensity)));
          lastDUST = ceil(dustDensity);
      }
     
      gw.sleep(SLEEP_TIME);
    }
    
    Int val = 0;
    

    this is not in use anywhere in the code and if you comment it out it will still compile
    can be deleted
    2.
    You need to connect 6 cables otherwise it will not work.
    In beginning it says

     *   VCC       >>> 5V
     *   A         >>> A0
     *   GND       >>> GND
    

    Here you can find how it must be connected
    https://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
    and here
    http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/

    Original sketch for Sharp GP2Y1010AU0F is like this

    /*
     Standalone Sketch to use with a Arduino Fio and a
     Sharp Optical Dust Sensor GP2Y1010AU0F
     
     Blog: http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
     Code: https://github.com/Trefex/arduino-airquality/
     
     For Pin connections, please check the Blog or the github project page
     Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
     Changelog:
       2012-Dec-01:  Cleaned up code
     
     This work is licensed under the
     Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
     To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
     or send a letter to Creative Commons, 444 Castro Street, Suite 900,
     Mountain View, California, 94041, USA.
    */
     
    int measurePin = 6;
    int ledPower = 12;
     
    int samplingTime = 280;
    int deltaTime = 40;
    int sleepTime = 9680;
     
    float voMeasured = 0;
    float calcVoltage = 0;
    float dustDensity = 0;
     
    void setup(){
      Serial.begin(9600);
      pinMode(ledPower,OUTPUT);
    }
     
    void loop(){
      digitalWrite(ledPower,LOW); // power on the LED
      delayMicroseconds(samplingTime);
     
      voMeasured = analogRead(measurePin); // read the dust value
     
      delayMicroseconds(deltaTime);
      digitalWrite(ledPower,HIGH); // turn the LED off
      delayMicroseconds(sleepTime);
     
      // 0 - 3.3V mapped to 0 - 1023 integer values
      // recover voltage
      calcVoltage = voMeasured * (3.3 / 1024);
     
      // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
      // Chris Nafis (c) 2012
      dustDensity = 0.17 * calcVoltage - 0.1;
     
      Serial.print("Raw Signal Value (0-1023): ");
      Serial.print(voMeasured);
     
      Serial.print(" - Voltage: ");
      Serial.print(calcVoltage);
     
      Serial.print(" - Dust Density: ");
      Serial.println(dustDensity);
     
      delay(1000);
    }
    
    1. MySensors sketch doesn't include any POWERLED, without this it cant work
    int ledPower = 12;
    

  • Hero Member

    hello,

    Thanks for reporting, I will check again here, for I never really successfully managed to have this one working.

    Beside this, the two others (cheaper but good anyway !) are working fine, see my repo here:
    https://github.com/empierre/arduino



  • @flopp
    same experience here,
    The sketch provided by Mysensors.org does not switch on/off the LED used to detect the dust particle (code below with corrections).
    I tested that sensor (Sharp_GP2Y1010AU) with smoke and because it does not have a fan (like the nova fitness SD011) or does not create a draft with a resistor (like the Shinyei PPD42NS) the fumes can go around completely undetected. When i tested the sharp and Shinyei in parallel the later seemed a lot more reliable.
    I also modified the code for the sharp sensor to get the arduino to loop thru multiple readings before sending a smoothed result back to the gateway.
    Code below with lots of debugging.

    /**
    * The MySensors Arduino library handles the wireless radio link and protocol
    * between your home built sensors/actuators and HA controller of choice.
    * The sensors forms a self healing radio network with optional repeaters. Each
    * repeater and gateway builds a routing tables in EEPROM which keeps track of the
    * network topology allowing messages to be routed to nodes.
    *
    * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
    * Copyright (C) 2013-2015 Sensnology AB
    * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    *
    * Documentation: http://www.mysensors.org
    * Support Forum: http://forum.mysensors.org
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * version 2 as published by the Free Software Foundation.
    *
    *******************************
    *
    * REVISION HISTORY
    * Version 1.0 - epierre
    * Converted to 1.4 by Henrik Ekblad
    * 
    * 
    * DESCRIPTION
    * Arduino Dust Sensort
    *
    * connect the sensor as follows :
    * 
    *   VCC       >>> 5V
    *   A         >>> A0
    *   GND       >>> GND
    *   LED       >>> 2
    *
    * Based on: http://www.dfrobot.com/wiki/index.php/Sharp_GP2Y1010AU 
    * Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
    * 
    * http://www.mysensors.org/build/dust
    * 
    */
    
    #include <MySensor.h>  
    #include <SPI.h>
    #define CHILD_ID_DUST 0
    #define DUST_SENSOR_ANALOG_PIN 0
    
    int ledPower = 2;
    const int numreadings = 60;
    
    unsigned long SLEEP_TIME = 10*1000; // Sleep time between reads (in milliseconds)
    //VARIABLES
    int val = 0;// variable to store the value coming from the sensor
    float valDUST = 0.0;
    float lastDUST =0.0;
    int samplingTime = 280;
    int deltaTime = 40;
    int sleepTime = 9680;
    float voMeasured = 0;
    float calcVoltage = 0;
    float dustDensity = 0;
    
    MySensor gw;
    MyMessage dustMsg(CHILD_ID_DUST, V_LEVEL);
    
    void setup(){
     gw.begin();
     pinMode(ledPower,OUTPUT);
     // Send the sketch version information to the gateway and Controller
     gw.sendSketchInfo("Dust Sensor", "1.1");
     // Register all sensors to gateway (they will be created as child devices)
     gw.present(CHILD_ID_DUST, S_DUST);  
    }
    
    void loop(){
    float cumsum = 0;
    float temp = 0;
    float temp1 = 0;
    float cum_density = 0;
         for (int sample = 0; sample < numreadings; sample ++){ // loop reading dust sensor
           digitalWrite(ledPower,LOW); // power on the LED
           delayMicroseconds(samplingTime);
           uint16_t voMeasured = analogRead(DUST_SENSOR_ANALOG_PIN);// Get DUST value
           delayMicroseconds(deltaTime);
            digitalWrite(ledPower,HIGH); // turn the LED off
           // 0 - 5V mapped to 0 - 1023 integer values
           // recover voltage
           temp = voMeasured * (5.0 / 1024.0);
           cumsum = cumsum + temp;// cumulative sum over 60 seconds
           delay(1000);
           Serial.print("reading sample: ");
           Serial.println(sample);
           Serial.print("Raw Signal Value (0-1023): ");
           Serial.println(voMeasured);    
           Serial.print(" - cumulative: ");
           Serial.println(cumsum);
    }
    // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
    // Chris Nafis (c) 2012
    dustDensity = (0.17 * cumsum - 0.1)* (1000/60);
           
    Serial.print(" - Dust Density: ");
    Serial.println(dustDensity); // unit: ug/m3
    Serial.println("#########################################");
    
    //  if (ceil(dustDensity) != lastDUST) {
    //      gw.send(dustMsg.set((int)ceil(dustDensity)));
    //      lastDUST = ceil(dustDensity);
    //  }
    gw.send(dustMsg.set((int)ceil(dustDensity)));
     gw.sleep(SLEEP_TIME);
    }```

Log in to reply
 

Suggested Topics

  • 33
  • 9
  • 8
  • 5
  • 2
  • 17

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts