Arduino Tutorial for Beginners – How to Use an LCD Display with Arduino




In this post on Arduino Tutorial For Beginners, this topic about how to use an LCD to display with Arduino.
In this tutorial we will use LCD(16×02 – 16 columns, 2 rows), there are many types of LCD as 20×02, 32×02,.. Beside that we can use LCD with I2C module support or not.
About LCD without I2C module : More wires connection
About LCD with I2C module : Less wires connection
You can research more about this on google because with Arduino everything is easy for newbies, now i only put the picture of LCD with I2C below

LCDi2c

To use LCD above, with newbies we don’t need to have more knowledge about I2C protocol you just need to know I2C is a protocol help us communicate between Arduino and LCD with I2C module. And with I2C we only use 2pins to communicate that is SCL(Clock) and SDA(Data), and we have 2 places to connect I2C LCD on Arduino as picture below (Only use one place)

I2Cpins

This is the library of LCD with I2C module : Scan I2C module address
Select as the pictures below and browse to the .zip file you downloaded to add library to Arduino IDE.

Addlib

Okay, now we will start working with LCD. Let’s connect as the diagram below

LCDConnection

First, to use an LCD with I2C module. We have to scan out which address the module are holding, we need to use block of code below to get it. You can watch the video above or just copy – paste – upload code to your sketch and then open Serial Monitor to see it.


#include
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial); // 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
}

Okay, After you find out which address your I2C module are holding, just copy and replace the address in the block code below to start using LCD.

#include
#include LiquidCrystal_I2C lcd(0x3F,16,2); // Put your I2C module address here
void setup()
{
lcd.init(); // Initialize the lcd
lcd.backlight(); // Turn on backlight
lcd.clear(); // Clear LCD
lcd.setCursor(0,0); // Put character on LCD at column = 0, row = 0
lcd.print("Welcome to"); // Print "Welcome to"
lcd.setCursor(0,1); // Put character on LCD at column = 0, row = 1
lcd.print("Prog Knowledge"); // Print "Prog Knowledge"
}
void loop()
{
delay(4000); // Delay 4secs
lcd.clear(); // Clear LCD
lcd.setCursor(0,0); // Put character on LCD at column = 0, row = 0
lcd.print("Hello World!"); // Print "Prog Knowledge"
}

This is some LCD’s function you can try:

lcd.init(); Init the lcd
lcd.clear(); Clear all display
lcd.print(“Welcome to PK”); Display (Welcome to PK) to LCD
lcd.cursor(); Display the cursor
lcd.noCursor(); No display the cursor
lcd.blink(); Blink the cursor
lcd.noBlink(); No blink the cursor
lcd.backlight(); Turn on LCD backlight
lcd.noBacklight(); Turn off LCD backlight
lcd.scrollDisplayLeft(); Scroll all your text to left 1 column
lcd.scrollDisplayRight(); Scroll all your text to right 1 column


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*