Connecting LCD with Arduino used to be complicated enough since it has many wires. And we also need to use a potentiometer to dim the LCD.
But now there is an i2c LCD backpack on the market that really helps us overcome this issue.
If you already have the LCD and I2C backpack, just solder on the right position like video below.
Then just wire LCD and arduino this way.
VCC -> 5V
GND -> GND
SDA -> A4
SCL -> A5
If wiring is done, now you should upload to your arduino I2C scanner to detect the address of your I2C LCD. Here’s the sketch.
I2C Scanner to Find the LCD address
// -------------------------------------- // i2c_scanner // // Version 1 // This program (or code that looks like it) // can be found in many places. // For example on the Arduino.cc forum. // The original author is not know. // Version 2, Juni 2012, Using Arduino 1.0.1 // Adapted to be as simple as possible by Arduino.cc user Krodal // Version 3, Feb 26 2013 // V3 by louarnold // Version 4, March 3, 2013, Using Arduino 1.0.3 // by Arduino.cc user Krodal. // Changes by louarnold removed. // Scanning addresses changed from 0...127 to 1...119, // according to the i2c scanner by Nick Gammon // http://www.gammon.com.au/forum/?id=10896 // Version 5, March 28, 2013 // As version 4, but address scans now to 127. // A sensor seems to use address 120. // Version 6, November 27, 2015. // Added waiting for the Leonardo serial communication. // // // This sketch tests the standard 7-bit addresses // Devices with higher bit address might not be seen properly. // #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan }
The Code For I2C LCD backpack
After uploading the sketch you should now see the address for the LCD. For me it’s 0x27. So I put the address and the size of LCD at the sketch. You can always watch the video for the detail. Upload the code and now your LCD should works.
#include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display void setup() { lcd.init(); // initialize the lcd\ // Print a message to the LCD. lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Hello"); lcd.setCursor(0, 1); lcd.print("From miliohm.com"); } void loop() { }
LiquidCrystal_I2C lcd(0x27, 16, 2);
Change the above line match to your address and LCD size
Use Multiple LCD with one arduino
Now if you want to connect more than one LCD with only a single arduino. You can just connect the second LCD the same way at the same pins. But the key is you should has a different address for every LCD. So since my LCDs have the same address. it’s 0x27. So I change the second LCD address, to do that I solder A0 in the back of the I2C LCD module. You can see the detail in the video.
Wiring Diagram for Multiple LCDs
You need to upload the I2C scanner again and open the serial monitor. And there should be two addresses shown up. So now, you should declare the second LCD at the code. Here’s the code.
The Code For Multiple LCDs with single Arduino
#include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display LiquidCrystal_I2C lcdsmall(0x26, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display void setup() { lcd.init(); // initialize the lcd\ // Print a message to the LCD. lcd.backlight(); lcdsmall.init(); // initialize the lcd\ // Print a message to the LCD. lcdsmall.backlight(); lcd.setCursor(0, 0); lcd.print("Hello"); lcd.setCursor(0, 1); lcd.print("How are you?"); lcd.setCursor(0, 2); lcd.print("Happy Coding!!"); lcd.setCursor(0, 3); lcd.print("From miliohm.com"); lcd.setCursor(0, 0); lcd.print("Hello small"); lcd.setCursor(0, 1); lcd.print("I'm small hehe"); lcd.setCursor(0, 2); } void loop() { }
In my case, my first LCD address is 0x27 and the second is 0x26. You should change according to your addresses.
Upload the code and now you should be able to see the two LCD working as we want.