×

Home Návody Recepty Download Reflexia O mne

Zoznam článkov:

Meranie PM prachových častíc senzorom SDS011:

11.10.2020

MeracKvalityOvzdusia

Prachové častice v ovzduší sú tak malé, že ich nemôžeme vidieť, ale môžeme ich zmerať a zobraziť na mape.

Existuje na to už hotová a výborná web stránka https://www.meria.me/ podľa ktorej som postupoval aj ja. Samotné zostavenie a naprogramovanie je veľmi jednoduché a rýchle.

Skladá sa z týchto častí:

  • SDS011 – Laser senzor pre meranie PM2.5 a PM10 častíc
  • BME280 – Senzor merania teploty, atmosférického tlaku a vlhkosti
  • ESP8266 – Wifi microchip NodeMcu v3
ZapojenieSenzora

Moje výsledky:

Zdrojový kód pre NodeMCU ESP8266:

    
    
    /******************************************************
   * PROJECT: Air quality measurement 
   * + send data on web
   *  
   * Made by Ing. Michal Kulina
   * 22.11.2020
   *******************************************************/
  
  #include <Arduino.h>
  #include <SdsDustSensor.h>
  #include <ESP8266WiFi.h>        // Include the Wi-Fi library
  #include <ESP8266HTTPClient.h>
  #include <Wire.h>
  #include <Adafruit_Sensor.h>
  #include <Adafruit_BME280.h>
  
  
  const char* ssid     = "YOUR_WIFI_SSID";         // The SSID (name) of the Wi-Fi network you want to connect to
  const char* password = "YOUR_WIFI_PASSWORD";     // The password of the Wi-Fi network
  
  /* SDS011 Dust Sensor */
  const int SDS_RX_PIN = D7; //D3; // D3 -> SDS011 TX pin
  const int SDS_TX_PIN = D8; //D4; // D4 -> SDS011 TX pin
  SoftwareSerial softwareSerial(SDS_RX_PIN, SDS_TX_PIN);
  SdsDustSensor sds(softwareSerial); //  additional parameters: retryDelayMs and maxRetriesNotAvailable
  const int MINUTE = 60000;
  const int WAKEUP_WORKING_TIME = 30000; // 30 seconds.
  const int MEASUREMENT_INTERVAL = 5*MINUTE; //default is 5 * MINUTE
  
  
  float Pressure_c = 0;
  Adafruit_BME280 bme; // I2C
  unsigned long delayTime;
  
  
  ///*** START ONLY ONE: ***///
  void setup() {
    WiFi.begin(ssid, password);             // Connect to the network
    Serial.begin(115200);
    Serial.println("...");
    Serial.print("Connecting to ");
    Serial.print(ssid); 
    
  
    int i = 0;
    while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
      delay(1000);
      Serial.print(++i); Serial.print(' ');
    }
  
    Serial.println('\n');
    Serial.println("Connection established!");  
    Serial.print("IP address:\t");
    Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
  
    //BME280 Sensor read:
      bool status;
      // default settings
      // (you can also pass in a Wire library object like &Wire2)
      status = bme.begin(0x76);  //I2C address can be 0x77 or 0x76 (by default 0x77 set in library)
      if (!status) {
          Serial.println("Could not find a valid BME280 sensor, check wiring!");
          while (1);
      }
      else {Serial.println(F("BME280 sensor read OK."));}
      
  
  
  
  //SDS010 Sensor
  Serial.println("SDS011 dust sensor read:");
  delay(500);
  /* SDS011 Dust Sensor */
  sds.begin();
  // Prints SDS011 firmware version:
  Serial.println(sds.queryFirmwareVersion().toString());
  // Ensures SDS011 is in 'query' reporting mode:
  Serial.println(sds.setQueryReportingMode().toString());
  
  
  } //END VOID SETUP
  
  
  
  ///*** CYCLIC HEAD PROCES: ***///
  void loop() {
  
  //1.Get data from BME280 sensor
  Serial.print("Temperature = ");
      Serial.print(bme.readTemperature());
      Serial.println(" *C");
  
      Serial.print("Pressure = ");
      Serial.print(bme.readPressure() / 100.0F);
      Serial.println(" hPa");
  
  
      Serial.print("Humidity = ");
      Serial.print(bme.readHumidity());
      Serial.println(" %");
  
      Serial.println();
  delay(delayTime);
  
  //2. Wake up SDS011
  sds.wakeup();
  delay(WAKEUP_WORKING_TIME);
  
  
  //3. Get data from SDS011 sensor
  PmResult pm = sds.queryPm();
  if (pm.isOk()) {
  Serial.print("PM2.5 = ");
  Serial.print(pm.pm25); // float, μg/m3
  Serial.print(", PM10 = ");
  Serial.println(pm.pm10);
  } else {
  Serial.print("Could not read values from PM2.5 and PM10 sensor, reason: ");
  Serial.println(pm.statusToString());
  }
  
  
  //4.Send data on Web
  /******************************************************
   * This function sends measured data to a PHP script on
   * the webserver where it is stored with a timestamp 
   *
   * If you want know how "send GET data" doing, look on 
   * https://youtu.be/q02f4sPghSo
   * 
   * How to send via POST data on web, you look on
   * https://youtu.be/32VcKyI0dio
   *******************************************************/
  Pressure_c=(bme.readPressure() / 100.0F);
  
  
  HTTPClient http;
    //Build call string:
    String dataline = "https://YOURWEBSITE.com/FILE.php";
    dataline += "?temp=" + String(bme.readTemperature());
    dataline += "&press=" + String(Pressure_c, 1); //2 decimal places
    dataline += "&humid=" + String(bme.readHumidity(), 1);
    dataline += "&pm25=" + String(pm.pm25, 1);
    dataline += "&pm10=" + String(pm.pm10, 1);
  
    bool httpResult = http.begin(dataline);
    if(!httpResult)
    {
      Serial.println("Invalid HTTP request:");
      Serial.println(dataline);
    }
    else
    {
      int httpCode = http.GET();
      if (httpCode > 0)
      { // Request has been made
        Serial.printf("HTTP status: %d Message: ", httpCode);
        String payload = http.getString();
        Serial.println(payload);
      }
      else
      { // Request could not be made
        Serial.printf("HTTP request failed. Error: %s\r\n", http.errorToString(httpCode).c_str());
      }
    }
    http.end();
  
  
  //END. Put SDS011 back to sleep
  WorkingStateResult state = sds.sleep();
  if (state.isWorking()) {
  Serial.println("Problem with sleeping the SDS011 sensor.");
  } else {
  Serial.println("SDS011 sensor is sleeping");
  delay(MEASUREMENT_INTERVAL);
  }
  
  }  
      
    

Zdroj: Microsoft

↖ VRÁTIŤ SA SPÄŤ HORE
Akékoľvek použitie obsahu, vrátane prevzatia článkov, obrázkov (okrem referencií) alebo ich častí, je povolené. Šírte informácie z tejto stránky, ako len chcete.