Arduino LCD display with only 4 wires

In this tutorial I will be explaining how to use a sixteen by two line LCD with an I2C bus. You will only be needing some wires and an Arduino.

First of all, you will have to connect some wires. Connect the SCL pin on the bus to analog five on the arduino, SDA to analog four, VCC to the five volt pin on the arduino and finally, GND to GND. With the easy part done, we can start programming the arduino.

To make everything a lot easier, we will be using a library to program the I2C bus. To install this library, you will have to go to Tools --> Manage Libraries and search for LiquidCrystal_I2C. Then click on install at the one that is made by Frank de Brabander.

LCD library by frank de brabander.

Now that you have installed the library, we can start coding. First of all, you will have to include the library and initialize everything.

#include <LiquidCrystal_I2C>
#include <Wire.h> 
LiquidCrystal_I2C lcd(0x27,16,2);

 void setup()
 {
   lcd.init(); // Initializing the lcd.
   lcd.backlight(); // Turing on the backlight.
 }

Next, we will start a loop in which we will change one piece of text every time. When doing lcd.setCursor, we change the place where the text starts. After that, clearing the lcd will make room for the next piece of text.

void loop() {
   lcd.clear();// Clearing the lcd to make space for new text.
   lcd.setCursor(2, 0); 
// Telling the lcd to start writing at the second colomn and the first line.
   lcd.print("Hello World!"); // Printing Hello World! 
   delay(500);// Waiting half a second
   lcd.clear();
   lcd.setCursor(2, 0);
   lcd.print("LCD tutorial"); 
   delay(500);
 }

Now just upload everything and you should be seeing the text change every half a second. This piece of hardware is obviously very useful, and is therefore vital to know about.

Leave a Reply

[]