DHT11 and LCD-I2C Interfaced with Arduino

Sometimes we are more likely to be fond of that, the temperature shall be visible on the screen. More often to check the temperature we use an application. Liquid crystal display comes with a module which helps in reduction of wire connections.

Requirements

  1. Arduino UNO
  2. Temperature Sensor DHT11
  3. LCD I2C 
  4. Jumper Wires

Schematics

How to Install LiquidCrystalI2C Library?

Code

The code below prints “Robonamix” and “Miles ahead” on Liquid Crystal display. 

				
					#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x3F for a 16 chars and 2 line display

void setup() {
  lcd.init();
  lcd.clear();         
  lcd.backlight();      // Make sure backlight is on
  
  // Print a message on both lines of the LCD.
  lcd.setCursor(2,0);   //Set cursor to character 2 on line 0
  lcd.print("Robonamix");
  
  lcd.setCursor(2,1);   //Move cursor to character 2 on line 1
  lcd.print("Miles Ahead");
}

void loop() {
}
				
			

The code below is for DHT11 interfaced with Arduino UNO and LCD I2C module. 

				
					#include <dht.h>	// Include library
include <LiquidCrystal_I2C.h>
#define outPin 8	// Defines pin number to which the sensor is connected
LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
dht DHT;			// Creates a DHT object

void setup() {
	lcd.init();
    lcd.clear();         
    lcd.backlight();      // Make sure backlight is on
}

void loop() {
	int readData = DHT.read11(outPin);

	float t = DHT.temperature;	// Read temperature
	float h = DHT.humidity;		// Read humidity

	lcd.setCursor(0,0);
	lcd.print("Temp.: ");
	lcd.print(t);
	lcd.print((char)223);//shows degrees character
	lcd.print("C");

	lcd.setCursor(0,1);
	lcd.print("Humi.: ");
	lcd.print(h);
	lcd.print("%");

	delay(2000); // wait two seconds
}
				
			

Conclusion

Hence the temperature will be visible on LCD. If the LCD is not working, try to get its address. 

How to get the Address of LCD I2C Module?

Upload the code below and open serial monitor. Get the address and change it in the code above.

				
					#include <Wire.h>

void setup() {
  Serial.begin (9600);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}
				
			
Leave a Reply

Your email address will not be published.