How do you do that? It really would help me a lot with the program by helping me write it correctly. I'm new to the world of programming and I really appreciate your help.
I use the code of a control to control a led with the light sensor, but I just want to replace these words with the right ones for it to run the night configuration instead of turning on the led.
I would really appreciate it if you could help me with this topic of creating constant structures corresponding to the values of day and night
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
#define W5100_CS 10
//#define SDCARD_CS 4
#define DHTPIN 2
#define DHTPIN2 5
#define DHTPIN3 7
#define DHTPIN4 9
#define DHTPIN5 23
#define dehumidifier 3
#define dehumidifier2 6
#define dehumidifier3 8
#define dehumidifier4 4
#define dehumidifier5 22
#define DHTTYPE DHT22
#define DHTTYPE2 DHT22
#define DHTTYPE3 DHT22
#define DHTTYPE4 DHT22
#define DHTTYPE5 DHT22
//prog dia
int valorLDR = 0; // here I defined the normal value of the led, but what I want is to include the day program
int UmbralNumber = 630; //this is the threshold of the sensor when it is night
int maxHum = 70;
int minHum = 63;
int maxTemp = 88;
int maxHum2 = 70;
int minHum2 = 63;
int maxTemp2 = 88;
int maxHum3 = 70;
int minHum3 = 63;
int maxTemp3 = 88;
int maxHum4 = 70;
int minHum4 = 63;
int maxTemp4 = 88;
int maxHum5 = 70;
int minHum5 = 63;
int maxTemp5 = 88;
//do I need to add all the max and min values in int for the night?
DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE2);
DHT dht3(DHTPIN3, DHTTYPE3);
DHT dht4(DHTPIN4, DHTTYPE4);
DHT dht5(DHTPIN5, DHTTYPE5);
BlynkTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(true);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor 1");
return;
}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature(true);
if (isnan(h2) || isnan(t2)) {
Serial.println("Failed to read from DHT sensor 2");
return;
}
Blynk.virtualWrite(V0, h2);
Blynk.virtualWrite(V1, t2);
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature(true);
if (isnan(h3) || isnan(t3)) {
Serial.println("Failed to read from DHT sensor 3");
return;
}
Blynk.virtualWrite(V2, h3);
Blynk.virtualWrite(V3, t3);
float h4 = dht4.readHumidity();
float t4 = dht4.readTemperature(true);
if (isnan(h4) || isnan(t4)) {
Serial.println("Failed to read from DHT sensor 4");
return;
}
Blynk.virtualWrite(V4, h4);
Blynk.virtualWrite(V7, t4);
float h5 = dht5.readHumidity();
float t5 = dht5.readTemperature(true);
if (isnan(h5) || isnan(t5)) {
Serial.println("Failed to read from DHT sensor 5");
return;
}
Blynk.virtualWrite(V8, h5);
Blynk.virtualWrite(V9, t5);
}
void setup()
{
Blynk.begin(auth);
// I don't know if it is necessary to define the value change detected by the sensor here
pinMode(ledPin,OUTPUT): // In the code, assign it to be an output to the LED pin
// in my case I don't know how to define the program
pinMode(dehumidifier, OUTPUT);
Serial.begin(9600);
dht.begin();
pinMode(dehumidifier2, OUTPUT);
Serial.begin(9600);
dht2.begin();
pinMode(dehumidifier3, OUTPUT);
Serial.begin(9600);
dht3.begin();
pinMode(dehumidifier4, OUTPUT);
Serial.begin(9600);
dht4.begin();
pinMode(dehumidifier5, OUTPUT);
Serial.begin(9600);
dht5.begin();
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
delay(2000);
//imagine that here I add the code that covers all the sensors working during the day
valorLDR = analogRead(analogPin); // here I read the sensor on an analog pin
if (valorLDR >= UmbralNumber){ //compare the reading value with the minimum threshold limit
digitalWrite(ledPin,HIGH);// if it is successful, I would like the day program to be executed
}else{
digitalWrite(ledPin,LOW);
// but if it is not met here I want a nightly configuration to be executed
}
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
//Serial.println("Failed to read from DHT sensor 1");
return;
}
if(h > maxHum) {
digitalWrite(dehumidifier, HIGH);
}else if (h < minHum) {
digitalWrite(dehumidifier, LOW);
}
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
if (isnan(h2) || isnan(t2)) {
// Serial.println("Failed to read from DHT sensor 2");
return;
}
if(h2 > maxHum2) {
digitalWrite(dehumidifier2, HIGH);
}else if (h2 < minHum2) {
digitalWrite(dehumidifier2, LOW);
}
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature();
if (isnan(h3) || isnan(t3)) {
// Serial.println("Failed to read from DHT sensor 2");
return;
}
if(h3 > maxHum3) {
digitalWrite(dehumidifier3, HIGH);
}else if (h3 < minHum3) {
digitalWrite(dehumidifier3, LOW);
}
float h4 = dht4.readHumidity();
float t4 = dht4.readTemperature();
if (isnan(h4) || isnan(t4)) {
// Serial.println("Failed to read from DHT sensor 2");
return;
}
if(h4 > maxHum4) {
digitalWrite(dehumidifier4, HIGH);
}else if (h4 < minHum4) {
digitalWrite(dehumidifier4, LOW);
}
float h5 = dht5.readHumidity();
float t5 = dht5.readTemperature();
if (isnan(h5) || isnan(t5)) {
// Serial.println("Failed to read from DHT sensor 2");
return;
}
if(h5 > maxHum5) {
digitalWrite(dehumidifier5, HIGH);
}else if (h5 < minHum5) {
digitalWrite(dehumidifier5, LOW);
}
// Serial.print("Humidity: ");
// Serial.print(h);
//Serial.print(" %\t");
// Serial.print("Temperature: ");
// Serial.print((int)round(1.8*t+32));
// Serial.println(" *F ");
}