Achraf Oukheir
Published

Climate Control

A tool to control the climate in any room.

BeginnerShowcase (no instructions)3 hours5,996
Climate Control

Things used in this project

Story

Read more

Schematics

DHT11

Capture of temperature and humidity as input and relay as output.

Code

Untitled file

Arduino
//OUKHEIR Achraf

#include "DHT.h"
#define DHTPIN 7     // what pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);
float t1=29;
float t2=26;
float h1=35;
float h2=40;
float humidity ;
float temperature;

void setup() {
  Serial.begin(9600);
  Serial.println("DHT test");

  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
 humidity = dht.readHumidity();
 temperature = dht.readTemperature();
  
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(temperature) || isnan(humidity)) {
   Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" *C");
  if (hot()|| humide())
   vent(6,true);
  else
  vent (6,false);
  
    
  }

}


void vent(int port,boolean act){ 
   pinMode (port,OUTPUT);
    
 if (act == true)
  digitalWrite ( port, HIGH);
 else 
  digitalWrite ( port, LOW);
    }
    
void vap(int port,boolean act){ 
   pinMode (port,OUTPUT);
    
 if (act == true)
  digitalWrite ( port, HIGH);
 else 
  digitalWrite ( port, LOW);
    }  

 boolean hot(){
     if (temperature>t1)
     return true;
     if (temperature<t2)
     return false; 
      }
      
 boolean humide(){
     if (humidity>h1)
     return true;
     if (humidity<h2)
     return false; 
      }

 
  

Credits

Achraf Oukheir

Achraf Oukheir

8 projects • 14 followers

Comments