#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";
#define W5100_CS 10
#define SDCARD_CS 4
#define DHTPIN1 53 // What digital pin we're connected to
#define DHTPIN2 51 // What digital pin we're connected to
#define DHT1TYPE DHT22 // DHT 22, AM2302, AM2321
#define DHT2TYPE DHT22
DHT dht1(DHTPIN1, DHT1TYPE);
DHT dht2(DHTPIN2, DHT2TYPE);
BlynkTimer timer;
void sendSensor()
{
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
// float h2 = dht2.readHumidity();
// float t2 = dht2.readTemperature();
Blynk.virtualWrite(V5, h1);
Blynk.virtualWrite(V6, t1);
//Blynk.virtualWrite(V7, h2);
//Blynk.virtualWrite(V8, t2);
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
dht1.begin();
//dht2.begin();
Blynk.begin(auth);
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
While this code does not (two sensors)
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";
#define W5100_CS 10
#define SDCARD_CS 4
#define DHTPIN1 53 // What digital pin we're connected to
#define DHTPIN2 51 // What digital pin we're connected to
#define DHT1TYPE DHT22 // DHT 22, AM2302, AM2321
#define DHT2TYPE DHT22
DHT dht1(DHTPIN1, DHT1TYPE);
DHT dht2(DHTPIN2, DHT2TYPE);
BlynkTimer timer;
void sendSensor()
{
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
Blynk.virtualWrite(V5, h1);
Blynk.virtualWrite(V6, t1);
Blynk.virtualWrite(V7, h2);
Blynk.virtualWrite(V8, t2);
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
dht1.begin();
dht2.begin();
Blynk.begin(auth);
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
When adding the 2nd sensor, i get disconnected almost directly from blynk. no data is sent and device offline. works perfect with on sensor with code above. Can someone help me?
Paste your full formatted sketch. Search the site for backticks if you don’t know how to post a sketch.
I have edited your thread title to reflect the problem.
It has to be something in my code, find it strange that i can not find example code on google… i can not be the first one trying this (btw i need about 15 sensors for my project…) but i figure if i can make 2 work then i can get 15 to work. thanks for the help… perhaps some one else have an idea?
I have four “identical” gauges one per virtual pin 5,6,7,8 - all set to push
digital pin 9 is a button on/off
i am fairly sure that the problem is not in how the app is setup, they failure happens before, it is surly something in the code when i add additional sensor that makes delays/holds or interrupts…