Maker.io main logo

Interface an LCD with an Arduino

2016-07-08 | By All About Circuits

License: General Public License Arduino

Courtesy of All About Circuits

Learn to create a user interface by pairing an Arduino with an LCD and then display a counter.

Today we’ll go over how to hookup an LCD screen to an Arduino and then how to enter a command to display on your LCD screen.

 

In step one, we’ll interface the Arduino with an LCD.

In step two, we’ll set up a counter to display on our new LCD setup.

Here’s what you’ll specifically need to follow along with this tutorial:

Get to Know Your LCD

Liquid crystal display (LCD) screens are by far the most popular screens for electronics today. If you look around you, you’re likely to see at least one or two, possibly on your microwave or landline caller ID box.

Your LCD has a total of 16 pins. Here’s what each pin is designed to do:

Pins 1 and 16: These are your power and ground.

Pin 3: Used to adjust the brightness of the LCD.

Pins 4-6: Used to operate the LCD.

Pins 7-14: Used as data lines.

Pins 15-16: Used to power the LCD’s backlight.

Accordingly, here’s a table to demonstrate how we’ll want to connect the LCD to the rest of the project:

Interface an LCD with an Arduino

Step 1: Connect Your LCD to Your Arduino

First we’ll need to connect your LCD pins to the Arduino pins.

Here’s a table to help:

Interface an LCD with an Arduino

Your potentiometer should connect via its two outer terminals to 5V and to GND. The middle terminal should connect to pin 3 on your LCD. By connecting it this way, your potentiometer can now be rotated to control how bright the backlight of your LCD is.

Code:

To run your LCD off of your Arduino, input the following code: 

Copy Code
#include "LiquidCrystal.h"

// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);

void setup() {
lcd.begin(16,2);

// set cursor position to start of first line on the LCD
lcd.setCursor(0,0);
//text to print
lcd.print(" 16x2 LCD");
// set cusor position to start of next line
lcd.setCursor(0,1);
lcd.print(" DISPLAY");
}
void loop()
{}

 

For this part, our goal is to set up a counter. The Arduino will count up to a value of 100, ticking up once per second.

Code:

To display the counter on your LCD, input the following code:

Copy Code
#include "LiquidCrystal.h"

// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);

void setup() {
lcd.begin(16,2);

// set cursor position to start of first line on the LCD
lcd.setCursor(0,0);
//text to print
lcd.print(" COUNTER");
delay(100);

int a=0;
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(a);
while(a<=100)
{
a=a 1;
delay(1000);
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(a);
}
}
void loop()
{
lcd.clear();
}

You should now have a successful interface between your Arduino and your LCD. On top of that, you should also be able to run a counter on your LCD screen. Good luck!

Interface an LCD with an Arduino

Scheme-it

Interface an LCD with an Arduino

制造商零件编号 LCM-S01602DSR/A
LCD MOD 32 DIG 16 X 2 REFLECTIVE
Lumex Opto/Components Inc.
制造商零件编号 MIKROE-2023
JUMPER M/M VARIOUS 75PCS
MikroElektronika
制造商零件编号 PDB181-K420K-502B
POT 5K OHM 1/5W CARBON LINEAR
Bourns Inc.
制造商零件编号 A000067
ARDUINO MEGA2560 ATMEGA2560
Arduino
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum