Arduino code program to display text on the LCD

  Arduino code program to display text on the LCD

To interface an Arduino Uno with an LCD, you typically use an LCD module with an HD44780 controller. This is one of the most common types of LCDs used in Arduino projects. Below is a step-by-step guide:

Components Required

  1. Arduino Uno
  2. 16x2 LCD (HD44780 compatible)
  3. 10k Ohm potentiometer (for contrast adjustment)
  4. Breadboard and jumper wires
  5. 220 Ohm resistor (for backlight LED)



Arduino Code Example

Here’s a simple program to display text on the LCD:


#include <LiquidCrystal.h> // Initialize the library with the pins connected to the LCD LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // Set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("Hello, Arduino!"); } void loop() { // Move the cursor to the second line lcd.setCursor(0, 1); // Print another message lcd.print("LCD Interface"); }

Explanation of the Code

  1. #include <LiquidCrystal.h>
    This includes the LiquidCrystal library that provides functions to control the LCD.

  2. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    Defines the Arduino pins connected to the LCD. The order of pins corresponds to:

    • RS = Pin 12
    • E = Pin 11
    • D4, D5, D6, D7 = Pins 5, 4, 3, 2
  3. lcd.begin(16, 2);
    Initializes the LCD to work in 16x2 mode (16 columns and 2 rows).

  4. lcd.print()
    Displays a string of text on the LCD.

  5. lcd.setCursor(col, row);
    Sets the cursor position for the next text. (0, 0) is the top-left corner.


How to Adjust the Contrast

  • Rotate the 10k potentiometer to adjust the contrast of the characters on the LCD screen. If nothing appears, make sure the connections are correct and the contrast is properly set.

Note: I2C Module (Optional)

To reduce the number of wires, you can use an I2C module for the LCD. It simplifies wiring and uses only two pins:

  • SDA: A4 on Arduino Uno
  • SCL: A5 on Arduino Uno

Use the following pin connections:

LCD PinLCD FunctionConnect to Arduino
1 (VSS)GroundGND
2 (VDD)Power Supply5V
3 (VO)Contrast AdjustmentMiddle pin of potentiometer
4 (RS)Register SelectDigital Pin 12
5 (RW)Read/WriteGND
6 (E)EnableDigital Pin 11
11 (D4)Data Pin 4Digital Pin 5
12 (D5)Data Pin 5Digital Pin 4
13 (D6)Data Pin 6Digital Pin 3
14 (D7)Data Pin 7Digital Pin 2
15 (A)Backlight (+)5V (via 220 Ohm resistor)
16 (K)Backlight (-)
GND
 
 This is the Proteus circuit diagram; it is just a guild for your connection 
follow the list above for the detail connection Thanks 




















Comments

Popular posts from this blog

Arduino Push Button in proteus Simulation

School Project: Temperature Controlled Fan using Arduino in Proteus