Use a different configuration depending on the amount of light in garduino

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 ");
}

Please edit your post and place the code text inside code tags.

1 Like

Why do you have 5 different DHT22s? Are there multiple zones in the grow room?

I assume depending on if it is day or night you want to use different max and min humidity and temp values. If so, you can create const structures corresponding to day and night values. When you transition from day to night and vice versa you can change a pointer.

1 Like

You seem to be suffering from a severe case of cut-n-paste-itis! This has caused your code to swell to 5 times its healthy size. The cure is arrays.

Do you need to plan for having a mix of different types of temp/humidity sensors? For example 3x DHT11 + 3x DHT22?

In this application I would bump that to "structs". There are associations of multiple data types here.

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 ");
}

I would really appreciate it if you could help me with arrays I really don't know much about the subject and your help would help me a lot

The first step is for you to read the forum guide. Then fix your posts #1 & #6 which are breaking forum rules because you did not use code tags. After that we will help you with your question.

I don't have the time to refactor your code entirely. But here is a start to setting your day and night thresholds and assigning them based on day or night. You can further improve the code by having arrays for your DHT devices as well. Also note that I used code tags.

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>

#define BLYNK_AUTH_TOKEN "xxx"

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

const int NUM_DHT = 5;

struct thresholds_t
{
  int maxHum;
  int minHum;
  int maxTemp;
};

const thresholds_t dayThresholds[NUM_DHT] = 
{
  {70,63,88},
  {70,63,88},
  {70,63,88},
  {70,63,88},
  {70,63,88}
};
  
const thresholds_t nightThresholds[NUM_DHT] = 
{
  {70,63,88},
  {70,63,88},
  {70,63,88},
  {70,63,88},
  {70,63,88}
};

thresholds_t* currentThresholds = dayThresholds;

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()
{
  // Debug console
  //Serial.begin(115200);

  //pinMode(SDCARD_CS, OUTPUT);
  //digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(auth);

  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);
  
  // TBD: determine whether it is day or night then assign the appropriate threshold array to the currentThresholds pointer
  // thresholds_t* currentThresholds = dayThresholds;

  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 > currentThresholds[0].maxHum) {
    digitalWrite(dehumidifier, HIGH);

  } else if (h < currentThresholds[0].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 > currentThresholds[1].maxHum) {
    digitalWrite(dehumidifier2, HIGH);

  } else if (h2 < currentThresholds[1].minHum) {
    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 > currentThresholds[2].maxHum) {
    digitalWrite(dehumidifier3, HIGH);

  } else if (h3 < currentThresholds[2].minHum) {
    digitalWrite(dehumidifier3, LOW);
  }

  float h4 = dht4.readHumidity();
  float t4 = dht4.readTemperature();

  if (isnan(h4) || isnan(t4)) {

    return;
  }
  if (h4 > currentThresholds[3].maxHum) {
    digitalWrite(dehumidifier4, HIGH);

  } else if (h4 < currentThresholds[3].minHum) {
    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 > currentThresholds[4].maxHum) {
    digitalWrite(dehumidifier5, HIGH);

  } else if (h5 < currentThresholds[4].minHum) {
    digitalWrite(dehumidifier5, LOW);
  }

  // Serial.print("Humidity: ");
  // Serial.print(h);

  // Serial.print("Temperature: ");
  // Serial.print((int)round(1.8*t+32));
  // Serial.println(" *F ");
}
1 Like

Thank you very much indeed for the great help and yes I will continue to improve the code and again sorry for all the mistakes I am new here

How to post code

Hi I made some small modifications but I don't know how to declare what the program has to do I don't know if with high, and low it's well done

#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
//sensor ldr
int ldrPin = 0;
int ldrValue = 0;

const int NUM_DHT = 5;

struct thresholds_t
{
int maxHum;
int minHum;

};

const thresholds_t dayThresholds[NUM_DHT] =
{
{70,63},
{70,63},
{70,63},
{70,63},
{70,63}
};

const thresholds_t nightThresholds[NUM_DHT] =
{
{60,55},
{60,55},
{60,55},
{60,55},
{60,55}
};

thresholds_t* currentThresholds = dayThresholds;
thresholds_t* currentThresholdsN = nightThresholds;

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()
{
//Debug console
Serial.begin(9600);
// pinMode(ledPin,OUTPUT);
//pinMode(SDCARD_CS, OUTPUT);
//digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

Blynk.begin(auth);

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);

ldrValue = analogRead(ldrPin);
if (ldrValue >=1010){
digitalWrite(dayThresholds, HIGH);
}
else{
digitalWrite(nightThresholds, LOW);
}

float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
return;
}
if (h > currentThresholds[0].maxHum) {
digitalWrite(dehumidifier, HIGH);

} else if (h < currentThresholds[0].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 > currentThresholds[1].maxHum) {
digitalWrite(dehumidifier2, HIGH);

} else if (h2 < currentThresholds[1].minHum) {
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 > currentThresholds[2].maxHum) {
digitalWrite(dehumidifier3, HIGH);

} else if (h3 < currentThresholds[2].minHum) {
digitalWrite(dehumidifier3, LOW);
}

float h4 = dht4.readHumidity();
float t4 = dht4.readTemperature();

if (isnan(h4) || isnan(t4)) {

return;

}
if (h4 > currentThresholds[3].maxHum) {
digitalWrite(dehumidifier4, HIGH);

} else if (h4 < currentThresholds[3].minHum) {
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 > currentThresholds[4].maxHum) {
digitalWrite(dehumidifier5, HIGH);

} else if (h5 < currentThresholds[4].minHum) {
digitalWrite(dehumidifier5, LOW);
}

// Serial.print("Humidity: ");
// Serial.print(h);

// Serial.print("Temperature: ");
// Serial.print((int)round(1.8*t+32));
// Serial.println(" *F ");
}

@greenhouse420 USE CODE TAGS when posting code.

Disculpa soy nuevo aquí como se hace eso

Si eres nuevo, lee las instrucciones en el "How to get the best out of the forum" post.

??? I have no idea what your intent is here. Doesn't make sense.

Wouldn't this make more sense?

  if (ldrValue >= 1010) {
    currentThresholds = dayThresholds;
  }
  else {
    currentThresholds = nightThresholds;
  }

Please use code tags!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.