Good morning, in my project, I use an Arduino uno board, I have a photoresistor connected to analog input 2.
We have a room in which there are 12 hours of light and 12 hours of darkness and an external system turns those lights on and off.
I would like to generate an alarm in the Blynk automation section related to the Light reading according to the time.
Something like;
From 8:00 a.m. until 8:00 p.m. should read A2 >150 lux, otherwise it sends an alarm
From 8:00 p.m. until 8:00 there must be darkness A2<20 lux, otherwise it sends an alarm.
Thank you in advance for your help.
sorry for my english
my code
//device info
#define BLYNK_TEMPLATE_ID
#define BLYNK_TEMPLATE_NAME
#define BLYNK_AUTH_TOKEN
#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define W5100_CS 10
#include <DHT.h>
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// definir sensores
int SENSOR = 5;
int LDR = analogRead (2);
int s = (sensors.getTempCByIndex(0));
DHT dht (SENSOR, DHT22);
BlynkTimer timer;
void sendSensor()
{
sensors.requestTemperatures();
int h = dht.readHumidity();
int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
int LDR = analogRead (2);
int s = (sensors.getTempCByIndex(0));
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V1, h);
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V2, LDR);
Blynk.virtualWrite(V7, s);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN);
dht.begin();
sensors.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}