Read PM 2.5 sensor data via Blynk virtual pins

Dear Blynkers, Greetings. I have an issue with one of my project. I am integrating three sensors to be read using a Blynk interface. DHT 11, MQ 135 and a PM 2.5 , optical dust sensor. I don’t have any issues with the first two sensors. The dust sensor/ PM 2.5 works fine, using the serial window. It records the dust density, like 0.0… 0.04… 0.09…0.05 (ug/m3) like this. I tried importing data to the blynk virtual pins, but it records data of only zero. Kindly provide your inputs in this regard. I have attached the sample code. ( Only for PM 2.5 sensor)

code
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>


// Uncomment whatever type you're using!

SimpleTimer timer;
// Use Virtual pin 5 for uptime display

// variables and declarations

int measurePin = A5;
int ledPower = 12;

unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "------------------------------------";

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

  void sensor_PM25()
  {
  digitalWrite(ledPower,LOW);
  delayMicroseconds(samplingTime);

  voMeasured = analogRead(measurePin);

  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH);
  delayMicroseconds(sleepTime);

  calcVoltage = voMeasured*(5.0/1024);
  dustDensity = 0.17*calcVoltage-0.1;

    if(dustDensity<0)
  {
    dustDensity = 0.00;
  }

  Blynk.virtualWrite(V8, dustDensity);
  }

 void setup()
{
  // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
 
  timer.setInterval(1000L, sensor_PM25);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

Please repost code, properly formatted as instructed, thanks. - Moderator

Blynk - FTFC

code looks good as far as I can see, I would suggest that you cram a couple of Serial.prinln(stuff) lines in between this section:

  voMeasured = analogRead(measurePin);

  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH);
  delayMicroseconds(sleepTime);

  calcVoltage = voMeasured*(5.0/1024);
  dustDensity = 0.17*calcVoltage-0.1;

  if(dustDensity<0) dustDensity = 0;

  Blynk.virtualWrite(V8, dustDensity);

and check whether the other variables e.g. voMeasured return an expected value. Its possible for example that calcVoltage is negative meaning that its set to 0 by the following if statement.

Hello do you already solve your problem? cause im doing same project like you.

This topic is 7 months old… Please create your own current topic and include all the details about what you have so far. Thanks