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
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.
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;
}
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;
}