Hello all,
I’m trying to do something simple, or at least I thought it was…
I’m making a garage door opener, yes I know there are several out there, but I am adding a LDR to determine if I left the lights on, as well as a DHT11 to get the temperature with a four switch relay to open the doors. However, when I flash the Photon, nothing seems to work, or I get constantly the device is disconnected. Could someone kindly review my code and help point me in the right direction? I have commented out the code to tell me if the lights are on or off, and it seems to work, so I believe that is where I am failing at.
Thank you in advance!!!
#include <blynk.h>
#include <DHT.h>
char auth[] = "";
#define DHTPIN 6 // What digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
dht.begin();
pinMode(A0, INPUT);
pinMode(D0, OUTPUT);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
int ldrval=analogRead(A0);
if(ldrval>100)
{
Blynk.virtualWrite(7, "Lights On");
}
else
{
Blynk.virtualWrite(7, "Lights Off");
}
Blynk.run();
timer.run();
}