Arduino LCD Projects
Arduino LCD Projects
This type of LCD is ideal for displaying text and numbers, hence the name ‘character
LCD’.
The I2C LCD that we are using comes with a small add-on circuit mounted on the back of
the module.
This module features a PCF8574 chip (for I2C communication) and a potentiometer to
adjust the LED backlight.
Standard LCDs typically require around 12 connections, which can be a problem if you do
not have many GPIO pins available.
If you look closely at the LCD, you can see the small rectangles that form the individual
characters of the LCD.
pixels.
Plug in the USB connector of the Arduino to power the LCD. You should see the backlight
light up. Now rotate the potentiometer until one (16×2 LCD) or 2 rows (20×4 LCD) of
rectangles appear. You can tweak the contrast later if needed.
To install this library, go to Tools > Manage Libraries (Ctrl + Shift + I on Windows) in
the Arduino IDE. The Library Manager will open and update the list of installed libraries.
If this is the case, you will need to nd the actual address of the LCD before you can start
using it.
/*I2C_scanner
This sketch tests standard 7-bit addresses.
Devices with higher bit address might not be seen properly.*/
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
fi
fi
fi
ff
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);
}
This example sketch will display the classic ‘Hello World!’ on the rst line of the LCD and ‘LCD
tutorial’ on the second line.
void setup() {
// Initiate the LCD:
lcd.init();
lcd.backlight();
}
void loop() {
// Print 'Hello World!' on the first line of the LCD:
lcd.setCursor(2, 0); // Set the cursor on the third column and first
row.
lcd.print("Hello World!"); // Print the string "Hello World!"
lcd.setCursor(2, 1); //Set the cursor on the third column and the
second row (counting starts at 0!).
lcd.print("LCD tutorial”);
}
fi
byte customChar[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000
};
#include <LiquidCrystal.h>
byte customChar[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000
};
void setup()
{
lcd.begin(16, 2); // set up number of columns and rows
void loop()
{
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int trigPin = 9;
const int echoPin = 10;
long duracion;
int distancia;
int ul maDistancia = 0;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
lcd.init();
ti
lcd.backlight();
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duracion = pulseIn(echoPin, HIGH);
distancia = (duracion * 0.034) / 2;
Serial.println(distancia);
if(distancia != ul maDistancia)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Distancia: "); // Prints string "Distance" on the LCD
lcd.print(distancia);
lcd.print(" cm");
ul maDistancia = distancia;
}
delay(500);
}
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define trigPin 13
#define echoPin 12
// Find LCD address for I2C in this tutorial it is 0x3f
LiquidCrystal_I2C lcd(0x3f, 16, 2);
ti
ti
int counter = 0;
int currentState1 = 0;
int previousState1 = 0;
int currentState2 = 0;
int previousState2 = 0;
int inside = 0;
int outside = 0;
void setup()
{
// initialize the LCD
lcd.begin();
//Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("IN: ");
lcd.setCursor(8, 0);
lcd.print("OUT: ");
lcd.setCursor(0, 1);
lcd.print("Total Inside: ");
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 9){
currentState1 = 1;
}
else {
currentState1 = 0;
}
delay(100);
if(currentState1 != previousState1){
if(currentState1 == 1){
counter = counter + 1;}
lcd.setCursor(14, 1);
lcd.print(counter);
inside = inside +1;}
lcd.setCursor(4, 0);
lcd.print(inside);
if (distance > 9 && distance <= 18){
currentState2 = 1;
}
else {
currentState2 = 0;
}
delay(100);
if(currentState2 != previousState2){
if(currentState2 == 1){
counter = counter - 1;}
lcd.setCursor(14, 1);
lcd.print(counter);
outside = outside +1;}
lcd.setCursor(13, 0);
lcd.print(outside);
lcd.setCursor(14, 1);
lcd.print(counter);
if (counter > 9 || counter < 0){
lcd.setCursor(14, 1);
lcd.print(counter);
delay(100);
lcd.clear();
}
}