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
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.
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.
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?
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.
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?