Hello World for LCD:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello, World!");
}
void loop()
{
}
//I2C Liquid Crystal Demo Program
//include <Wire.h>. //Wire Library for I2C
#include <LiquidCrystal_I2C.h>
// Arduino Liquid Crystal I2C library
//Connect Vcc to 5V, GND to GND, SDA-->A4, SCL--> A5
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
lcd.begin(); // initialize the LCD
lcd.backlight();
lcd.print("Hello, World!"); // Turn on the blacklight and print a message.
}
void loop(){
int numberOne = random(10,20);
int numberTwo = random(20,30);
lcd.clear();
lcd.setCursor(0,0); //line 1 of display
lcd.print("Number One =");
lcd.print(numberOne);
lcd.setCursor(0,1); //line two of display
lcd.print("Number Two = ");
lcd.print(numberTwo);
delay(1000);
}
LCD Display with DHT22 Temp/Humidity Sensor:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>// Liquid Crystal by Arduino, Adafruit
#include <DHT22.h> //DHT22 library by dvarrel
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
//Connect to 5V, GND, SDA to A4 , SCL to A5
#define pinDATA 2
//Connect DHT22 to +5V, GND, and Data to Pin 2
DHT22 dht22(pinDATA); //define pin data
void setup()
{
// Initialize the LCD
lcd.begin();
lcd.backlight();
Serial.begin(9600); //1bit=10µs
Serial.println("\ntest capteur DTH22");
}
void loop()
{
float t = dht22.getTemperature();
float h = dht22.getHumidity();
if (dht22.getLastError() != dht22.OK) {
Serial.print("last error :");
Serial.println(dht22.getLastError());
}
Serial.print("h=");Serial.print(h,1);Serial.print("\t");
Serial.print("t=");Serial.println(t,1);
delay(2000); //Collecting period should be : >1.7 second
lcd.clear();
// Display humidity on line 0
lcd.setCursor(0, 0); // First row
lcd.print("Humidity= ");
lcd.print(h);
// Display temperature on line 1
lcd.setCursor(0, 1); // Second row
lcd.print("Temperature= ");
lcd.print(t);
delay(5000); // Wait 5 seconds
}