Example Code for Arduino-Backlight Fade
Last revision 2026/06/05
Follow the pin description to connect the hardware, then download the sample code to UNO. After upload finished, you can see the LCD display and backlight gradient effect.
Hardware Preparation
- DFRduino UNO R3 with IO Expansion Shield and USB Cable A-B
- Gravity: I2C LCD1602 Arduino LCD Display Module (Gray)
- Sensor cable x1
Software Preparation
- Development Tool: Arduino IDE; Download Link: Click to Download Arduino IDE from Arduino?
- DFRobot LCD Library:Click to Download DFRobot LCD Library(Github)
- Library installation guide: How to install Libraries in Arduino IDE
Wiring Diagram
| UNO R3 | PIN | LCD 1602 | PIN |
|---|---|---|---|
| UNO R3 | VCC | LCD 1602 | VCC(RED) |
| UNO R3 | GND | LCD 1602 | GND(BLACK) |
| UNO R3 | SCL | LCD 1602 | SCL(BLUE) |
| UNO R3 | SDA | LCD 1602 | SDA (GREEN) |
Sample Code
/*!
* file Fade.ino
* brief Fade.
*
* Copyright [DFRobot](https://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V1.0
* date 2018-1-13
*/
#include "DFRobot_RGBLCD1602.h"
/*
Change the RGBaddr value based on the hardware version
-----------------------------------------
Moudule | Version| RGBAddr|
-----------------------------------------
LCD1602 Module | V1.0 | 0x60 |
-----------------------------------------
LCD1602 Module | V1.1 | 0x6B |
-----------------------------------------
LCD1602 RGB Module | V1.0 | 0x60 |
-----------------------------------------
*/
DFRobot_RGBLCD1602 lcd(/*RGBAddr*/0x6B ,/*lcdCols*/16,/*lcdRows*/2); //16 characters and 2 lines of show
void breath(unsigned char color){
for(int i=0; i<255; i++){
lcd.setPWM(color, i); // set backlight, set i as 0 means close the backlight
delay(5);
}
delay(500);
for(int i=254; i>=0; i--){
lcd.setPWM(color, i);
delay(5);
}
delay(500);
}
void setup() {
// initialize
lcd.init();
// Print a message to the LCD.
lcd.setCursor(4, 0);
lcd.print("DFRobot");
lcd.setCursor(1, 1);
lcd.print("lcd1602 module");
}
void loop() {
breath(lcd.REG_ONLY);
}
Result
- In the first row, the fifth pane of the screen shows "DFRobot"
- The second row, the second pane of screen shows "lcd1602 module"
- The screen backlight shows the breathing state while the caption is displayed
Was this article helpful?
