top of page

LCD Display Fade

This project demonstrates how to create a fading effect on an LCD (Liquid Crystal Display) Shield using an Arduino. By varying the backlight brightness, you can create a smooth fading effect that adds visual appeal. This project is beneficial in teaching about direct plug-and-play shields for Arduinos. Arduino shields are boards that directly plug on-top of Arduinos for projects that require a specific task to be done.

​​

How It Works:

We will explore the use of PWM (Pulse Width Modulation) Pin for the brightness manipulation. It's a technique used to control the amount of power delivered to an electronic device by breaking up the signal into discrete on and off periods.

​

Materials Anchor

Materials

LCD Display Fade

To build a LCD fade project with an Arduino Uno, you'll need the following materials:

Components:

​

1) Arduino Uno (or any compatible Arduino board)

  • The microcontroller that will control the LCD and manage the fading effect.

​

2) 16x2 LCD Shield (with or without the buttons)

  • A standard alphanumeric LCD with a backlight to display text. Ensure it supports PWM control for the backlight.​​

​​

3) USB Cable

  • To connect the Arduino to your computer for programming and power.

Setup Anchor

Basic Setup

breadboard.png

1. Connect the LCD to the Arduino:

  • Align the LCD Shields' pins with the pins of the Arduino and attach the shield.​

​

2. Write the Sketch:

  • Use the LiquidCrystal library to control the LCD.

  • Write a sketch to gradually change the PWM signal on the backlight pin to fade the brightness.

Code
code.png

CODE BREAK-DOWN

Code Break Down

#include <LiquidCrystal.h>

  • Includes the LiquidCrystal library, which provides functions to control the LCD display.

​

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

  • Creates an instance of the LiquidCrystal object.

  • Specifies the Arduino pins connected to the LCD:

    • Pin 8 for RS (Register Select)

    • Pin 9 for Enable (E)

    • Pins 4, 5, 6, and 7 for the data lines (D4-D7)

​

const int backlightPin = 10;

  • Declares the backlight pin as 10, which will control the brightness using PWM.

​

int brightness = 0;

  • Initializes the brightness level to 0 (completely off).

​

int fadeAmount = 5;

  • Sets the increment or decrement amount for brightness during each fade cycle.

​

void setup() {

  • Begins the setup function, which runs once when the Arduino starts.

​

lcd.begin(16, 2);

  • Configures the LCD with 16 columns and 2 rows to match the 16x2 LCD dimensions.

​

lcd.print("Fading Backlight");

  • Displays the text "Fading Backlight" on the LCD.

​

pinMode(backlightPin, OUTPUT);

  • Sets the backlight pin (10) as an output pin for controlling the brightness.

​

void loop() {

  • Begins the main loop, which runs repeatedly after the setup.

​

analogWrite(backlightPin, brightness);

  • Sets the backlight brightness using PWM with the value of brightness (0 to 255).

​

brightness += fadeAmount;

  • Increases or decreases the brightness based on fadeAmount.

​

if (brightness <= 0 || brightness >= 255) {

  • Checks if the brightness reaches the minimum (0) or maximum (255) value.

​

fadeAmount = -fadeAmount;

  • Reverses the direction of fading when the brightness reaches its limits.

​

delay(30);

  • Pauses the program for 30 milliseconds to control the fading speed.

bottom of page