Weâve learned how to read sensors and turn on LEDs, but reading raw data off the Serial Monitor feels like hacking the matrix, and not in a cool way. A real standalone project needs its own screen. Enter the 16x2 LCD Display.
Normally, wiring these requires a horrifying ratâs nest of cables. But we are going to cheat and use an I2C interface, which drops the wire count to four. Youâre welcome.
An I2C 16x2 LCD display allows you to present data elegantly with minimal wiring.
A standard 16x2 LCD requires up to 16 pins to be wired to your Arduino. Thatâs a mess of cables and eats up almost all of your digital pins!
By attaching an I2C âbackpackâ module to the back of the LCD, it communicates using the I2C protocol. This means you only need two data wires (SDA and SCL) plus power and ground.
Wiring the I2C LCD is incredibly simple. Connect the four pins from the I2C backpack as follows:
Before uploading the code, youâll need the LiquidCrystal_I2C library. Go to Sketch > Include Library > Manage Libraries in the Arduino IDE, search for âLiquidCrystal I2Câ (by Frank de Brabander), and install it.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
// Note: If 0x27 doesn't work, your address might be 0x3F.
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD
lcd.init();
// Turn on the backlight
lcd.backlight();
// Print a message to the LCD
lcd.setCursor(0, 0); // Column 0, Row 0
lcd.print("Hello, World!");
lcd.setCursor(0, 1); // Column 0, Row 1
lcd.print("Arduino Rocks!");
}
void loop() {
// Nothing to do here for a static display!
}
Upload the code, and if everything is wired correctly, your screen should light up and display the message! If you see blank squares or nothing at all, grab a small Phillips screwdriver and adjust the tiny blue potentiometer on the back of the I2C module to change the screenâs contrast.
Next time, weâll learn how to feed live sensor data into our new display!