An LCD or Liquid Crystal Display is a low-cost solution for displaying information in microcontroller projects. The displays we have are 16x2 character displays meanings they have 16 columns & 2 rows to display 32 characters total.
Note: the potentiometer is for dialing in the contrast. Sometimes, it comes loose and may cause nothing to show up on your screen. To avoid this, you can find fixed resistance values that work for your screen. I have found that connecting a 1 kOhm resistor between V0 and GND and a 10 kOhm resistor between V0 and 5V works well.
https://create.arduino.cc/editor/mjdargen_ravens/c1dba938-3d12-4190-b5e4-83d22edc6cd6/preview
To use the LCD character displays, we will use the LiquidCrystal library: https://www.arduino.cc/en/Reference/LiquidCrystal
#include <LiquidCrystal.h>
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
lcd.begin(col, row)
16
2
lcd.setCursor(col, row)
col
: the column to position the cursor, starts at 0 (0-15)row
: the row to position the cursor, starts at 0 (0-1)lcd.setCursor(2, 1)
- Sets position to the 3rd character on row 2.lcd.print(text)
text
: variable to be displayed on LCD. Must be <= 16 chars.lcd.clear()
lcd.setCursor(0, 0); lcd.print(" ");
lcd.setCursor(0, 1); lcd.print(" ");
lcd.setCursor(7, 1); lcd.print(" ");