How to make temperature controlled fan (Switch).

Posted by moudud 10/05/2019 0 Comment(s)

 

 

How to make temperature controlled fan (Switch).

 


Circuit Diagram :


 

 

 Connections
 PinArduino pin
DHT11VCC5V
GNDGND
SignalD2
Relay ModuleVCC5V
GNDGND
InD13
OLED DisplayVCC5V
GNDGND
SDAA4
SCLA5

 

 

 

 

 


Code

 

 

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <SimpleDHT.h>

 

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);


// for DHT11, 
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT11 = 2;
const int output =  13;
SimpleDHT11 dht11(pinDHT11);

void setup() {
   Serial.begin(19200);
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
   display.clearDisplay();
   display.display();
  // initialize the LED pin as an output:
  pinMode(output, OUTPUT);
  // initialize the DHT11/DHT22 pin as an input:
  pinMode(pinDHT11, INPUT);

}

void loop() {
  // start working...
  Serial.println("____________________");
  Serial.println("Simple DHT11...");
  
  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    //Serial.print("Read DHT11 failed, err="); Serial.println(err);
    delay(1000);
    return;
  }
  
  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, "); 
  Serial.print((int)humidity); Serial.println(" H");
  
  
  delay(1500);       // DHT11 sampling rate is 1HZ.

 

  display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.setCursor(85, 5);
  display.println(temperature);
  temperature = temperature;

  // write the new one
  display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.setCursor(85, 5);
  display.println(temperature);

  display.display();


    display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.setCursor(85,20);
  display.println(humidity);
  humidity = humidity;

  // write the new one
  display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.setCursor(85, 20);
  display.println(humidity);

  display.display();

  display.setTextSize(1);
  display.setTextColor(WHITE, BLACK);
  display.setCursor(10, 20);
  display.println("Humidity");
  display.setCursor(10,5 );
  display.println("Temperature");
  display.setCursor(100,5 );
  display.println("C");
  display.setCursor(100,20 );
  display.println("%");


  if (temperature <=30 ) //Set the temperature here.
  {
    // turn LED on:
    digitalWrite(output, HIGH);
  } else {
    // turn LED off:
    digitalWrite(output, LOW);
  }
}

 


 

 


 

 


 

 

Write a Comment