finale2

mail@pastecode.io avatar
unknown
c_cpp
a year ago
5.7 kB
2
Indexable
Never
#include "DHT.h"
#define Relay1 5    //For Vane_1 & Dht_1
#define Relay2 18   //For Vane_2 & Dht_2
#define Relay3 19   //For Vane_3 & Dht_3
#define Relay4 21   //For Pompe water
#define DHT1 4      // Digital pin connected to the DHT1 sensor
#define DHT2 22     // Digital pin connected to the DHT2 sensor
#define DHT3 23     // Digital pin connected to the DHT3 sensor
#define DHTTYPE DHT11   // DHT 11
bool Relay_1 = false , Relay_2 = false, Relay_3 = false ;
bool control = false;
DHT dht1(DHT1, DHTTYPE);
DHT dht2(DHT2, DHTTYPE);
DHT dht3(DHT3, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));
  dht1.begin();
  dht2.begin();
  dht3.begin();
  pinMode(Relay1,OUTPUT);
  pinMode(Relay2,OUTPUT);
  pinMode(Relay3,OUTPUT);
  pinMode(Relay4,OUTPUT);

  digitalWrite(Relay1,LOW) ;
  digitalWrite(Relay2,LOW) ;
  digitalWrite(Relay3,LOW) ;
  digitalWrite(Relay4,LOW) ;
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);
  
    //*****for dht 1*****
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h1 = dht1.readHumidity();
  // Read temperature as Celsius (the default)
  float t1 = dht1.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f1 = dht1.readTemperature(true);
  
    //*****for dht 2*****
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h2 = dht2.readHumidity();
  // Read temperature as Celsius (the default)
  float t2 = dht2.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f2 = dht2.readTemperature(true);

      //*****for dht 3*****
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h3 = dht3.readHumidity();
  // Read temperature as Celsius (the default)
  float t3 = dht3.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f3 = dht3.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
 // if (isnan(h1) || isnan(t1) || isnan(f1)||
  //    isnan(h2) || isnan(t2) || isnan(f2)||
   //   isnan(h3) || isnan(t3) || isnan(f3)) {
  //  Serial.println(F("Failed to read from DHT sensor!"));
  //  return;
 // }

  // Compute heat index in Fahrenheit (the default)
  float hif1 = dht1.computeHeatIndex(f1, h1);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic1 = dht1.computeHeatIndex(t1, h1, false);

    // Compute heat index in Fahrenheit (the default)
  float hif2 = dht2.computeHeatIndex(f2, h2);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic2 = dht2.computeHeatIndex(t2, h2, false);

    // Compute heat index in Fahrenheit (the default)
  float hif3 = dht3.computeHeatIndex(f3, h3);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic3 = dht3.computeHeatIndex(t3, h3, false);

  Serial.print(F("Humidity1: "));
  Serial.print(h1);
  Serial.print(F("%  Temperature1: "));
  Serial.print(t1);
  Serial.print(F("°C "));
  Serial.print(f1);
  Serial.print(F("°F  Heat index1: "));
  Serial.print(hic1);
  Serial.print(F("°C "));
  Serial.print(hif1);
  Serial.println(F("°F"));

  Serial.print(F("Humidity2: "));
  Serial.print(h2);
  Serial.print(F("%  Temperature2: "));
  Serial.print(t2);
  Serial.print(F("°C "));
  Serial.print(f2);
  Serial.print(F("°F  Heat index2: "));
  Serial.print(hic2);
  Serial.print(F("°C "));
  Serial.print(hif2);
  Serial.println(F("°F"));

  Serial.print(F("Humidity3: "));
  Serial.print(h3);
  Serial.print(F("%  Temperature3: "));
  Serial.print(t3);
  Serial.print(F("°C "));
  Serial.print(f3);
  Serial.print(F("°F  Heat index3: "));
  Serial.print(hic3);
  Serial.print(F("°C "));
  Serial.print(hif3);
  Serial.println(F("°F"));
  

/////////////////////////////////////////////
if (control){
  ///*****Manual*****/////*****************************
  char x = Serial.read();
  switch(x)
  {
    case '1': 
      digitalWrite(Relay1,HIGH);
      break;
    case '2': 
      digitalWrite(Relay1,LOW);
      break;
    case '3': 
      digitalWrite(Relay2,HIGH);
      break;
    case '4': 
      digitalWrite(Relay2,LOW);
      break;
    case '5':
      digitalWrite(Relay3,HIGH);
      break;
    case '6':
      digitalWrite(Relay3,LOW);
      break;
    case '7':
      digitalWrite(Relay4,HIGH);
      break;
    case '8':
      digitalWrite(Relay4,LOW);
      break;
    default : 
      Serial.println("Invalid");
      break;
  }
}
else {
  ////******Auto*****/////////
  if (h1 > 40 && h1 <90){
    digitalWrite(Relay1,HIGH);
    Relay_1 = true;
  }
  else { 
    digitalWrite(Relay1,LOW);
    Relay_1 = false;
  }
  if (h2 > 40 && h2 <90){
    digitalWrite(Relay2,HIGH);
    Relay_2 = true;
  }
  else { 
    digitalWrite(Relay2,LOW);
    Relay_2 = false;
  }  
  if (h3 > 40 && h3 <90){
    digitalWrite(Relay3,HIGH);
    Relay_3 = true;
  }
  else { 
    digitalWrite(Relay3,LOW);
    Relay_3 = false;
  }
  if (Relay_1  || Relay_2   || Relay_3 ){
    digitalWrite(Relay4,HIGH);
  }
  else { 
    digitalWrite(Relay4,LOW);
  }
}

//////////////////////////////////////
bool c = Serial.read();
if(  c== true) 
    {
      control = true;
      } 
if(  c== false) 
    {
      control = false;
      } 
}