Arduino DHT11 room temperature control

Mr.ElectroUino
0

Arduino DHT11 Sensor tutorial




 Arduino DHT11 Sensor projects.

Hello viewers! This project is on controlling the room temperature by using DHT11 sensor and Arduino uno. 
The idea behind the project is the problem I'm getting.
Whenever the rainy season start, the temperature alway goes low or high. So I decided to build a prototype circuit which can control the room temperature by getting the reading from DHT11 sensor. 

Working of DHT11 sensor project.
The temperature is less than 25°C, the fan speed decreases, and the heater will turn on. If the temperature greaters than 25°C, the fan speed increase depends on the room temperature.

Feature of the projects:
To display the DHT11 sensor reading, I'm using a 16x2 I2C LCD to print the DHT11 data. The data will be temperature and humidity. 
The purpose of the buzzer is uses as an Emergency sound indicator like when the DHT11 sensor detects the Highest or lowest temperature reading, the buzzer startted buzzing. So we can understand the temperature is on highest or lowest point.

RGB led is used as a Temperature indicator. We can also use it as a temperature mood light. It could be awesome, when we add more RGB LEDs.

 Component requirements: 

1. Arduino Uno
2. DHT11 sensor.
3. 16x2 I2C LCD display.
4. TIP41C  x  2.
5. DIY mini heater.
6. 12v dc fan.
7. Buzzer.
8. RGB LEDs    x    1.
9. Resistor (220 ohm)   x   3
10. Resistor (1k ohm)   x   2
11. Breadboard.
12. Jumper Wires.

 Arduino DHT11 wiring diagram: 

arduino dht11 wiring diagram

Pin Connection:


1. Firstly, make a connection between the Arduino Uno and breadboard.

  • Connect Arduino GND pin to breadboard GND side.
  • Connect Arduino 5v pin to breadboard 5v side.

Next, connect the breadboard GND side to another GND side of breadboard.


2. Make a connection between the Arduino Uno and DHT11 sensor.

  • The DHT11 data pin should be connected to the Arduino pin 4.
  • The DHT11 GND pin should be connected to breadboard GND side.
  • The DHT11 VCC pin should be connected to the breadboard 5v side.

3.Buzzer connection to arduino.

  • Connect the buzzer positive pin to pin 5 of the Arduino.
  • Connnect negative pins of buzzer to breadboard GND side.

4. Now, Its time to add a 12v fan, but the problem is arduino can only supply 12 volts. SO the solution for the problem is to use TIP41C transistor, which can be use as load switch.

  • Connect TIP41C Emitter pin to breadboard GND side.
  • Connect a 1k resistor to the base pin of the TIP41C transistor. Now connect the end of the resistor to arduino pin 6.

Connect the fan GND pin to TIP41C collector pin and the fan positive pin to 12v power supply.

Make sure the power suppy GND pin is connected to arduino GND pin.


5. Now, Make a connection between arduino and DIY mini heater. The heater is made of nichrome wire which also works on 12 volts.

  • Connect TIP41C Emitter pin to breadboard GND side.
  • Connect a 1k resistor to the base pin of the TIP41C transistor. Now connect the end of the resistor to arduino pin 7.

Connect the heater GND pin to TIP41C collector pin and the heater positive pin to 12v power supply.

Make sure the power suppy GND pin is connected to arduino GND pin.


6. Now, Its time to connect the RGB LEDs to the arduino.

  • The RGB Led R pin is protected with a 220 ohm resistor, and the resistor end is attached to the Arduino pin 9. 
  • The RGB Led G pin is protected with a 220 ohm resistor, and the resistor end is attached to the Arduino pin 10. 
  • The RGB Led B pin is protected with a 220 ohm resistor, and the resistor end is attached to the Arduino pin 11.
  • Connnect RGB led GND pin to breadboard GND side.

In order to protect the LEDs, a 220 ohm resistor is used as a current limiter.


5. Last component is 16x2 LCD display with I2C driver.

  • The Arduino A5 pin should be connected to the LCD SCL pin.
  • The Arduino A4 pin should be connected to the LCD SDA pin.
  • The Arduino 5v pin should be connected to the LCD VCC pin.
  • The Arduino GND pin should be connected to the LCD GND pin.

Now the circuit is completed. Lets jump to the coding part.

 

 Coding: 

1. Before uploading the code, we need to install some libraries. 
For that, open Arduino software and go to Tool -> Manages libraries. Here search for the DHT11 sensor and install the library from Adafruit.
Then we need to install one more library for a 16x2 I2C LCD. Here you need to search for 16x2 I2C LiquidCrystall and install the library from Frank de Brabander.
2. Connect the Arduino Uno to the PC using a USB cable so we can upload the code.
3. In the Arduino ide, go to Tool --> select your board and COM port. 
4. Now, upoad the code. 
5. When the code is uploaded successfully, we need to check whether the DHT11 sensor is working.
For that, we need to open the serial monitor. We can find it in the top right corner, which looks like a search button.
6. In the serial monitor, we will get the reading of the DHT11 sensor data. The data will be room temperature and humidity readings.
7. If you are getting any problem, comment on it.  

 dht11 sensor arduino code. 
#include "DHT.h"
#include <LiquidCrystal_I2C.h>

#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float temp = 0;
float humi = 0;

int lcdColumns = 16;
int lcdRows = 2;
//If 0x3f address is not work, then change the address to 0x27
LiquidCrystal_I2C lcd (0x3f, lcdColumns, lcdRows); 

int buzzer = 5;
int fan = 6;
int heater = 7;
int rgb[3] = {9, 10, 11};

uint8_t buzz[8] = {B00001, B00011, B00111, B11111, B11111, B00111, B00011, B00001};
uint8_t degree[8] = {B00000, B11000, B11000, B00000, B00000, B00000, B00000, B00000};
uint8_t tem[8] = {B00100, B01010, B01010, B01110, B01110, B11111, B11111, B01110};
uint8_t hum[8] = {B00100, B00100, B01010, B01010, B10001, B10001, B10001, B01110};
uint8_t fanEmoji[8] = {B00000, B11011, B11011, B00100, B11011, B11011, B00000, B00000};
uint8_t heaterEmoji[8] = {B00000, B10001, B10001, B11111, B10001, B10001, B10001, B00000};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  dht.begin();
  lcd.init();
  lcd.backlight();

  lcd.createChar(0, buzz);
  lcd.createChar(1, degree);
  lcd.createChar(2, tem);
  lcd.createChar(3, hum);
  lcd.createChar(4, fanEmoji);
  lcd.createChar(5, heaterEmoji);

  pinMode(fan, OUTPUT);
  pinMode(heater, OUTPUT);
  pinMode(buzzer, OUTPUT);
  for (int i = 0; i < 3; i++) {
    pinMode(rgb[i], OUTPUT);
  }
  int t = 100;
delay(500); 
 for (int r = 0; r < 3; r++) {
    setColor(148, 0, 211);
    delay(t);
    setColor(0, 0, 255);
    delay(t);
    setColor(0, 191, 255);
    delay(t);
    setColor(0, 255, 0);
    delay(t);
    setColor(255, 255, 0);
    delay(t);
    setColor(255, 127, 0);
    delay(t);
    setColor(255, 0, 0);
    delay(t);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  printData();
  if (temp < 15 ) {
    setColor(0, 0, 255);
    analogWrite(fan, 0);
    digitalWrite(heater, HIGH); 
    
    lcd.setCursor(14, 0);
    lcd.write(0); 
    lcd.setCursor(15, 0);
    lcd.write(5);        
        
    tone(buzzer, 1000);
    delay(400);
    noTone(buzzer);
    delay(400);    
  }
  else if (temp > 20 && temp < 25) {
    setColor(255, 255, 255);
    analogWrite(fan, 51);
    lcd.setCursor(15, 0);
    lcd.write(4);
noTone(buzzer);    
  }
  else if (temp > 25 && temp < 30) {
    setColor(0, 255, 0);
    analogWrite(fan, 102);
    lcd.setCursor(15, 0);
    lcd.write(4);
noTone(buzzer);    
  }
  else if (temp > 30 && temp < 35) {
    setColor(255, 255, 0);
    analogWrite(fan, 153);
    lcd.setCursor(15, 0);
    lcd.write(4);
    noTone(buzzer);
  }
  else if (temp > 35 && temp < 40) {
    setColor(255, 90, 0);
    analogWrite(fan, 204);
    lcd.setCursor(15, 0);
    lcd.write(4);
    noTone(buzzer);
  }
  else if (temp > 40 && temp < 50) {
    setColor(255, 0, 0);
    analogWrite(fan, 255);    
    lcd.setCursor(14, 0);
    lcd.write(0);
    lcd.setCursor(15, 0);
    lcd.write(4);
    tone(buzzer, 1000);
  }
}

void printData() {

  delay(2000);
  lcd.clear();

  temp = dht.readTemperature();
  humi = dht.readHumidity();

  if (isnan(temp) || isnan(humi)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print(F("TEMP: "));
  Serial.print(temp);
  Serial.print("   ");
  Serial.print(F("HUMI: "));
  Serial.print(humi);
  Serial.println(F(" %"));

  lcd.setCursor(0, 0);
  lcd.print(F("Temp: "));
  lcd.print(temp);
  lcd.write(1);
  lcd.print(F("C"));

  lcd.setCursor(0, 1);
  lcd.print(F("Hum : "));
  lcd.print(humi);
  lcd.print(F(" %"));
}

void setColor(int r, int g, int b) {
  analogWrite(rgb[0], r);
  analogWrite(rgb[1], g);
  analogWrite(rgb[2], b);
}

Let me know in the comment section, What next project do you want to see.

Watch This Tutorial: 



Feel free to comment down if you have any problems.

Post a Comment

0Comments

Post a Comment (0)