Guide no. 44
A 16×2 display with the I²C module: four wires, one library, and Arduino writes a greeting and the seconds going by.
By Ada Intelisano · informaticait.it technical team
- Four wires: GND, VCC to 5V, SDA to A4, SCL to A5.
- The hd44780 library finds the module address by itself.
setCursor(column, row)andprint: counting starts at 0.- Blank display: adjust the contrast with the trimmer on the back.
So far Arduino has talked to you through the Serial Monitor, that is, through the computer. With a display it writes on its own: two rows of 16 characters. With the I²C module on the back, four wires are all you need.
1Get the parts ready
- a 16×2 LCD display with the I²C module already soldered on the back
- Arduino UNO and four female-to-male jumper wires
2Connect the four wires
- GND of the module → GND of the board (here the one at the top, next to pin 13);
- VCC → 5V;
- SDA → A4;
- SCL → A5.
On the UNO, pins A4 and A5 also work as SDA and SCL. The order of the four pins on the module changes from one manufacturer to another: read the labels printed next to the pins, don't trust the position.
3Install the library
In the Arduino IDE open the Library Manager, search for hd44780 and install the one by Bill Perry. It has a big advantage for beginners: it works out by itself the module address and how it is wired inside, two things that change from one module to another.
4Write and upload the sketch
// The LCD display: a greeting on the first row and the seconds ticking by on the second. #include <Wire.h> #include <hd44780.h> #include <hd44780ioClass/hd44780_I2Cexp.h> hd44780_I2Cexp lcd; // finds the address of the I2C module by itself void setup() { lcd.begin(16, 2); // 16 characters, 2 rows lcd.print("Hello, world!"); // writes from the first cell of the first row } void loop() { lcd.setCursor(0, 1); // column 0, row 1 (the second one: counting starts at 0) lcd.print("Seconds: "); lcd.print(millis() / 1000); delay(500); }
setCursor(column, row) moves the point where you will write. Counting starts at 0: setCursor(0, 1) is the first cell of the second row.millis() tells you how many thousandths of a second have passed since power-up. Divided by 1000, it gives the seconds.- The display is lit but blank, or shows only solid rectangles: turn the blue trimmer on the back (the contrast) with the screwdriver until the letters appear.
- It doesn't even light up: check VCC to 5V and GND to GND.
- Lit, contrast adjusted, but no text: SDA and SCL are swapped or not on A4 and A5. The library also has a diagnostic example, I2CexpDiag: upload it and read what it prints in the Serial Monitor.
5Challenge yourself
- Write your name in the middle of the first row: with 16 cells, which column do you start from?
- Show the TMP36 temperature (guide no. 40) instead of the seconds.
- Make a countdown from 10 to 0 and at the end write “Go!”. Watch out: when you go from 10 to 9 an extra digit is left behind; write a space after the number.
6And with the ESP32?
One word of caution here: this display runs at 5 V, while the ESP32 pins can take 3.6 V at most, and the module pulls the SDA and SCL lines up to 5 V. The fix is a level shifter between the two: we explain it in guides no. 21 and 28. To get started, use the display with the UNO.
- with the I²C module the display needs only four wires;
printwrites,setCursorchooses where; rows and columns are counted from 0;- blank screen? The contrast trimmer comes first.
To learn more: guide no. 28 compares this display with an OLED.
Useful products
Other guides
- Resistor colour code and tolerances
- N-channel and P-channel MOSFETs
- Bipolar transistor (BJT) or MOSFET?
- Relays: how to drive them and how much current they draw
- THT and SMD/SMT components
- XIAO board pinouts
- LEDs: forward voltage and series resistor
- The multimeter: measuring voltage and current
- Wemos D1 mini: first steps
- MOSFET module with Arduino and ESP32
- Relay module with Arduino and ESP32
- 3D printing filaments: PLA, PETG and fibre-filled versions
- Analog and digital: the differences
- ADS1115: 16-bit converter with Arduino and ESP32
- From bits to real values: converting sensor readings
- DS3231 RTC clock with Arduino and ESP32
- Linear or switching regulator: which one to choose
- Step-down, step-up and buck-boost: choosing the right module
- Voltage divider: reading voltages higher than 5 V or 3.3 V
- Pull-up, pull-down and bounce: wiring a button properly
- 3.3 V and 5 V logic levels: getting an ESP32 and an Arduino to talk
- The I²C bus: addresses, pull-ups and the scanner
- Lithium batteries: voltages, charging and protection
- ESP32 power consumption and deep sleep: how long the battery lasts
- Temperature sensors compared
- ESP32: which pins to use and which to avoid
- Getting started with the ESP32 in Arduino IDE 2 and PlatformIO
- SSD1306 OLED display and 16×2 I²C LCD with Arduino and ESP32
- PIR motion sensor and HC-SR04 ultrasonic sensor
- Date and time from the Internet with the ESP32: NTP, Italian time zone and daylight saving time
- MicroSD data logger: saving measurements to CSV
- Solar-powered ESP32: panel, charger and the numbers for Italy
- Web server on the ESP32: control a relay from your phone
- Your first LED: wire it up and make it blink
- The button: let Arduino decide
- The potentiometer: turn a knob and read its value
- Soft light: adjusting the brightness of an LED
- The buzzer: playing notes and melodies
- The traffic light: three LEDs in sequence
- The thermometer: reading the temperature with the TMP36
- The servo motor: moving an arm with Arduino
- The night light: the photoresistor and your first decision
- The relay: switching on a light bulb with Arduino
- The electronic dice: your first complete project
- The RGB LED: every color from three lights
- The joystick: two-axis control with a shield
- The LED ring: twelve colors from a single pin
- The DC motor: driving it with a MOSFET
- Soil moisture: the plant that asks for water
- The stepper motor: turn exactly as far as you want
- The parking sensor: faster and faster beeps
- The 7-segment display: big, bright numbers
- Automatic watering: the plant that waters itself
- The keypad: a lock with a secret code
- Networked weather station: values and chart on your phone
- A Telegram bot on the ESP32: your home from your phone
- MQTT with the ESP32: the language of connected devices
- Updating the ESP32 over Wi-Fi (OTA)
- ESP-NOW: two ESP32 boards talking without a router
- WebSocket with the ESP32: the LED that follows the slider
- Readings on a Google sheet, with deep sleep
- WiFiManager: choose the Wi-Fi from your phone
- Bluetooth LE with the ESP32: the phone without a network
- The camera in your browser with the ESP32-S3
- A portable Bluetooth speaker you build yourself
- Bluetooth desktop speakers, 2 × 20 W
- Stereo MP3 player with two buttons
- The shelf that plays music: a Visaton exciter
- How to solder well
- How much does it draw? Current and power with the INA219
- Load-cell scale with the HX711
- CO2 traffic light: when to open the windows
- RFID card door opener
- GPS: track logger on microSD
- LoRa: how far does it go? A range test with two boards
- Battery weather sign with an e-paper display
- Web radio with an ESP32 and an I2S amplifier
- Getting started with the Raspberry Pi Pico 2 in MicroPython
- Your first amplifier: the LM386 and a speaker
- Talking Arduino: the DFR0760 speech synthesis module
- The spectrum of your music on an LED matrix
- Drawing with 64 LEDs: the 8×8 matrix with the MAX7219
- A real voltage: the 12-bit MCP4725 DAC
- The heartbeat on Arduino: an ECG with the AD8232