I2C LCD Controller Part II

9,754

30

8

About: Master Diesel Tech, in California. I love electronics and everything science .

Intro: I2C LCD Controller Part II

Now that we have install and assemble the controller here is a little project. we are going to build a thermometer.

Parts list

1. Arduino

1. I2C LCD

1. DHT11 Temp Sensor

1. 1k Resistor

7. Jumper wires

     

Step 1:

Connecting the LCD is very simple

LCD                 Arduino

5VCD               5VCD

GND                 GND

SDA                  PIN 20 (SDA on MEGA)

SCL                   PIN 21 (SCL on Mega)

Now the DHT11

DHT 11              Arduino

PIN 1                 5VCD

PIN2                  PIN 2

PIN 3                 N/A ( not used)

PIN 4                 GND

note: you can use a pull up resitor on PIN 2, but not necessary. Also you will need to install the library for the DHT11.

Step 2: THe Code

I am a beginner at this, so my programing  is not that great but it works.
It is very very basic and very simple.  

#include <Wire.h>                        //libraries needed
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <dht11.h>


//I2C Controller
#define I2C_ADDR    0x20  // Define I2C Address for controller
#define BACKLIGHT_PIN  7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3
#define  LED_OFF  0
#define  LED_ON  1

//DHT11
#define DHT11PIN 2


LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
dht11 DHT11;

void setup()
{
 
    lcd.begin (16,2);
    // Switch on the backlight
    lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
    lcd.setBacklight(LED_ON);
}

void loop() 
{
 
  lcd.clear();
  lcd.home();
 
  int chk = DHT11.read(DHT11PIN);
 
  lcd.setCursor(0,0);
  lcd.print("Humy (%): ");
  lcd.print((float)DHT11.humidity, 2);
 
  lcd.setCursor(0,1);
  lcd.print("Temp (oF): ");
  lcd.print(Fahrenheit(DHT11.temperature), 2);

    delay(5000);
    
}

//temp conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest

    8 Discussions

    0
    None
    matti.virta.1

    1 year ago

    i test code manytime and have alltime different error, dht.h lcd.h not found, liguidcrystal.h not work. but i no found all libraries anywere. were have LCD and DHT11 and goow liguidcrystal_i2c, because i test many liguidc.h and any not working. my lcd addres i cahnge and work only test "hello world" 0x3F addres and this code(under) not working me alltiem error lcd.h, dht11.h and liguidcrustal.h i has load many different library but any not working :( i tes arduino ide 1.6.5 r2 1.6.7 1.6.11 and last not working anythink ecample code. what have proplem whit libraries ? i no understand.

    0
    None
    killeriq

    2 years ago

    Had to modify it for my LCD:

    //I2C Controller

    #define I2C_ADDR 0x3F // Define I2C Address for controller

    #define BACKLIGHT_PIN 3

    #define En_pin 2

    #define Rw_pin 1

    #define Rs_pin 0

    #define D4_pin 4

    #define D5_pin 5

    #define D6_pin 6

    #define D7_pin 7

    #define LED_OFF 1

    #define LED_ON 0

    0
    None
    killeriqironhide707

    Reply 2 years ago

    this should help https://arduino-info.wikispaces.com/LCD-Blue-I2C

    0
    None
    昕育鄭

    2 years ago

    https://www.facebook.com/photo.php?fbid=1706642296234464&set=pcb.1163322010361915&type=3&relevant_count=1

    use

    lcd.print((char)223); //degree sign
    lcd.print("F"); instead of "oF" for degree F ;)