Dashboard Trouble

Arduino NANO 33IoT for communication with a CO Sensor, CO2 Sensor, Lux Sensor and Dust Sensor
On Blynk Server my dashboard is always offline
I was using Blynk 1.2.0 but the dashboard for the project always appeared as offline
In arduino code is sucessfully uploaded but no results can be found on the blynk web dashboard

#define BLYNK_TEMPLATE_NAME "FYP Blynk"
#define BLYNK_AUTH_TOKEN "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF"
#include "Arduino.h"
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#define BLYNK_PRINT Serial
float readPercentageCO2(); //read percentage of the CO2
float readPercentageCO(); //read percentage of the CO
#include <DHT.h>
#include <Adafruit_VEML7700.h>
#define DHTPIN A2
#define DHTTYPE DHT22
DHT dht = DHT (DHTPIN, DHTTYPE);
char auth[] = "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF";
char ssid[] = "DGEM4321";
char pass[] = "dgem4321";
BlynkTimer timer;
const float CO2Pin = A0;
const float COPin = A2;
int pin = A3;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 2000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
const int LightPin = A4;
int lightValue = 0;
int hchoPin = A6;
float hchoValue;

float readPercentageCO2();
float readPercentageCO();

Adafruit_VEML7700 veml = Adafruit_VEML7700();

void sensor()
{ 
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(V5,t);
Blynk.virtualWrite(V4,h);


float readPercentageCO2 =analogRead (CO2Pin) ;
float readPercentageCO =analogRead (COPin) ;
delay(500);
Blynk.virtualWrite(V0, readPercentageCO);
Blynk.virtualWrite(V6, readPercentageCO2);
float lux = veml.readLux();
Blynk.virtualWrite(V2, lux);
hchoValue = analogRead(hchoPin) * 5.0 / 1024.0;
Blynk.virtualWrite(V3, hchoValue);
} 

void setup()
{ 
  Serial.begin(115200);
dht.begin();
timer.setInterval (1000L,sensor);
Blynk.begin(auth, ssid, pass);
} 
void loop()
{ 
  Blynk.run();

timer.run();
}

What does your serial monitor show? (copy the text and paste it with triple backticks at the beginning and end, the same way you did with your code).

Pete.

My serial monitor is blank this was a code i was supposed to upload to Blynk

You need to figure-out why that is. Do you have it set to the correct baud rate (115200)?
Is your USB cable faulty?

Pete.

It still produces nothing, am i supposed to show you what my expected results are?

You need to get your serial monitor working, so that it allows you to diagnose why your device is failing to connect to Blynk.

Have you tried a simpler (basic) Blynk sketch to see if that gets online and outputs to the serial monitor?

Pete.

Is there an example of a simple blynk sketch

I tried it with only the DHT22 sensor and even though it uploaded with no problem the Blynk dashboard still shows me nothing

#define BLYNK_TEMPLATE_NAME "FYP Blynk"
#define BLYNK_AUTH_TOKEN "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF"
#include "Arduino.h"
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#define BLYNK_PRINT Serial
#include <DHT.h>
#define DHTPIN A2
#define DHTTYPE DHT22
char auth[] = "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF";
char ssid[] = " DGEM1234";
char pass[] = "dgem4321";
DHT dht = DHT (DHTPIN, DHTTYPE);
BlynkTimer timer;
void sensor()
{ 
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(V5,t);
Blynk.virtualWrite(V4,h);
}
void setup()
{ 
  Serial.begin(115200);
dht.begin();
timer.setInterval (1000L,sensor);
Blynk.begin(auth, ssid, pass);
} 
void loop()
{ 
  Blynk.run();

timer.run();
}

Yes, in the SketchBuilder (link at the top of the page) and in the examples installed in the IDE when you installed the Blynk library.

Pete.

So i have managed to get it all working and it is now running however it seems to only run for 10-30 seconds before i stop receiving data, is there a known cause for this is it because i am in Blynk2.0
Here is the current code

#define BLYNK_TEMPLATE_NAME "FYP Blynk"
#define BLYNK_AUTH_TOKEN "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF"
#include <DHT.h>
#include <DHT_U.h>
#include <Arduino.h>
#include <Adafruit_VEML7700.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
BlynkTimer timer;

const float CO2Pin = A0;
const float COPin = A2;
int pin = A3;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 2000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
const int LightPin = A4;
int lightValue = 0;
int hchoPin = A6;
float hchoValue;
#define DHTPIN A1
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

char auth[] = "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF";
char ssid[] = "TheWhiteHouse";
char pass[] = "dontellyou";

void setup()
{
  Serial.begin(9600);
  dht.begin();
  pinMode(hchoPin, INPUT);
  pinMode(A3, INPUT);
  starttime = millis();
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, sendData); // Send data to Blynk every 1 second
}

void sendData()
{
  duration = pulseIn(pin, LOW);
  lowpulseoccupancy = lowpulseoccupancy + duration;
  if ((millis() - starttime) >= sampletime_ms)
  {
    ratio = lowpulseoccupancy / (sampletime_ms * 10.0);
    concentration = 1.1 * pow(ratio, 3) - 3.8 * pow(ratio, 2) + 520 * ratio + 0.62;
    Blynk.virtualWrite(V1, concentration); // Send concentration to Virtual Pin V1
    lowpulseoccupancy = 0;
    starttime = millis();
  }

  Adafruit_VEML7700 veml;

  Wire.begin();
  veml.begin();

  float lux = veml.readLux();
  Blynk.virtualWrite(V2, lux); // Send lux to Virtual Pin V2

  hchoValue = analogRead(hchoPin) / 8.0 / 1024.0;
  Blynk.virtualWrite(V3, hchoValue); // Send HCHO value to Virtual Pin V3

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Blynk.virtualWrite(V4, h); // Send humidity to Virtual Pin V4
  Blynk.virtualWrite(V5, t); // Send temperature to Virtual Pin V5

  float percentageCO2 = analogRead(CO2Pin);
  Blynk.virtualWrite(V6, percentageCO2); // Send CO2 percentage to Virtual Pin V6

  float readCO = analogRead(COPin)/4;
  Blynk.virtualWrite(V7, readCO); // Send CO value to Virtual Pin V7
}

void loop()
{
  Blynk.run();
  timer.run();
}

You appear to be missing:
#define BLYNK_TEMPLATE_ID "Your template ID"
From the top of your sketch.

You should delete this…

and change this:

to this…

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

These lines of code only need to be executed once, not every time sendData is executed.

What’s the logic behind this code…

Did you get your serial monitor working?

You should add this line of code near the top of your sketch…
#define BLYNK_PRINT Serial

and see what your serial monitor tells you when the device stops sending data. Adding-in some serial print statements will also allow you to diagnose what’s happening within your code.

Pete.

The top code i seemed to have forgotten to leave it in and i am not that sure behind the logic for the adafruit but it was the original arduino code for the Arduino
and the second code is calculations for the HCHO sensor apparently
also noted i will implement the changes now to test them out

My guess is that if you go and look at the original code it didn’t use a timer, but did a millis comparison to work-out when the function should be executed. As you’re using BlynkTimer now you should clean-up your code to remove the redundant code.

Pete.

This is the current work the serial monitoring is working however it randomly stops between every 2-20 iterations

#define BLYNK_TEMPLATE_NAME "FYP Blynk"
#define BLYNK_AUTH_TOKEN "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF"
#define BLYNK_PRINT Serial
#include <DHT.h>
#include <DHT_U.h>
#include <Arduino.h>
#include <Adafruit_VEML7700.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
BlynkTimer timer;

const float CO2Pin = A0;
const float COPin = A2;
int pin = A3;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 2000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
const int LightPin = A4;
int lightValue = 0;
int hchoPin = A6;
float hchoValue;
#define DHTPIN A1
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

char auth[] = "WMHxJs1HpOmEkOJvbGZGjMmVdBJYueLF";
char ssid[] = "TheWhiteHouse";
char pass[] = "dontellyou";

void setup()
{
  Serial.begin(9600);
  dht.begin();
  pinMode(hchoPin, INPUT);
  pinMode(A3, INPUT);
  starttime = millis();
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, sendData); // Send data to Blynk every 1 second
}

void sendData()
{

  Adafruit_VEML7700 veml;

  Wire.begin();
  veml.begin();

  float lux = veml.readLux();
  Blynk.virtualWrite(V2, lux); // Send lux to Virtual Pin V2
  Serial.print("Lux: ");
  Serial.println(lux);

  hchoValue = analogRead(hchoPin) / 8.0 / 1024.0;
  Blynk.virtualWrite(V3, hchoValue); // Send HCHO value to Virtual Pin V3
  Serial.print("HCHO Value: ");
  Serial.print(hchoValue);
  Serial.println(" ppm");

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Blynk.virtualWrite(V4, h); // Send humidity to Virtual Pin V4
  Blynk.virtualWrite(V5, t); // Send temperature to Virtual Pin V5
  Serial.print(" Humidity ");
  Serial.print(h);
  Serial.print("%");
  Serial.print(" Temperature ");
  Serial.print( t);
  Serial.print("% ");
 

  float percentageCO2 = analogRead(CO2Pin);
  Blynk.virtualWrite(V6, percentageCO2); // Send CO2 percentage to Virtual Pin V6
  Serial.print(" CO2: ");
  Serial.print(percentageCO2);
  Serial.println("PPM");

  float readCO = analogRead(COPin)/4;
  Blynk.virtualWrite(V7, readCO); // Send CO value to Virtual Pin V7
}

void loop()
{
  Blynk.run();
  timer.run();
}

You don’t seem to have taken onboard most of the code changes that I suggested.
Any reason for this?

Pete.

When i tried to use this Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
the code refused to launch for some reason after awhile i jus switched it back
i wasnt sure where to insert this part
Adafruit_VEML7700 veml;

Wire.begin();
veml.begin();

i did add the serial printing and the monitors amd removed the old timer
is there anything else i missed out?

What did your serial monitor show?

Before your void setup

You’ve not made it clear if the serial output relates to your device stopping responding, or whether some different messages are displayed when this occurs.

Pete.

I inserted a picture above of what my serial monitor shows Blynk data jus no longer transfers

No different messages are shows my code ‘runs normally’ everything is still active my serial print it still giving me results but it stops transferring to blynk

Okay, that part is now clear, but it’s the firts time you’ve verbalised this behaviour.
Does your device still sow as Online in the app and web console when this happens?

Pete.