Saturday 17 November 2018

[Tutorial] Extracting sensor data from Dust Sensor with ESP32

1. Devices

  • ESP32
  • Dust sensor
  • some jumper wires or four pins cable

2. Upload the code below to your Arduino IDE project

  • source code
#include "Arduino.h"

int pin = 2;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;

void setup() 
{
    Serial.begin(9600);
    pinMode(pin,INPUT);
    starttime = millis();//get the current time;
}

void loop() 
{
    duration = pulseIn(pin, LOW);
    lowpulseoccupancy = lowpulseoccupancy+duration;

    if ((millis()-starttime) > sampletime_ms)//if the sampel time == 30s
    {
        ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
        concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
        Serial.print(lowpulseoccupancy);
        Serial.print(",");
        Serial.print(ratio);
        Serial.print(",");
        Serial.println(concentration);   //concentration
        lowpulseoccupancy = 0;
        starttime = millis();
    }
}
  • pins connection
 JST Pin 1 (Black Wire)  => ESP32 GND
 JST Pin 3 (Red wire)    => ESP32 5VDC
 JST Pin 4 (Yellow wire) => ESP32 Digital Pin 2

3. Output

3. Issues

if there is a problem like: A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header. Press boot/flash during uploading the codes.

No comments:

Post a Comment

[Research] Recurrent Neural Network (RNN)

1. Introduction As we all know, forward neural networks (FNN) have no connection between neurons in the same layer or in cross layers. Th...