Series: Using the GT-SP Touch Panel TFT Display with Arduino

Automatically Controlling Display Brightness Using a Light Sensor

Automatically Controlling Display Brightness Using a Light Sensor

DownloadDownload sample project & program (for GT Design Studio & Arduino)

Hello everyone, I’m @kissaten, a beginner in electronics. In this series, I’m explaining the process of connecting a 7-inch touch display (GT-SP series “GTWV070S3A00P”) to an Arduino and working on various projects.

The GT-SP has a control command that allows the host computer to adjust the screen brightness. This time, we will use this along with a light sensor to create a mechanism that automatically adjusts the screen’s brightness according to the current ambient light.

For example, this is intended for use in situations where you want to keep the display at an optimal brightness according to the time of day or environment, such as a control panel installed in an environment where the ambient light changes frequently, or a smart home switch used in a dark room at night.

Adding the Connection Between Arduino and Light Sensor

To read the ambient light this time, we will add a light sensor and a fixed resistor (10kΩ) to the circuit. A voltage divider circuit is formed by the light sensor and the fixed resistor, and the Arduino reads the voltage that changes according to the ambient light.

Connect the junction of the light sensor and the fixed resistor to the analog input pin (A0) of the Arduino. Please refer to the circuit diagram below for specific connection points.

Picture by [Fritzing (CC BY-SA)]

The objective this time is to read the difference in light intensity between a dark room and a bright room as a numerical value with the sensor, and reflect it directly in the GT-SP backlight brightness.

Creating the Program to Write to Arduino

Here is the program we created this time.

DownloadDownload sample project & program (for GT Design Studio & Arduino)

 

Understanding the Program

When the light sensor reads the ambient light, the Arduino converts that numerical value into the screen brightness for the GT-SP and sends it to the display.

Specifically, in the loop function, which is the main part of the program, processing is performed in several steps.

First, the readAverageSensor function reads the numerical value of the light sensor. Here, instead of picking up the value just once, we calculate the average of 10 continuous measurements. This allows us to receive a stable numerical value without being confused by noise or momentary flickering.

Next, the constrain function is used to securely keep the read value within the expected range (100 to 1000), and then the map function is used to smoothly convert it to the GT-SP screen brightness scale (3 to 255). It is thanks to this calculation that seamless dimming is possible, rather than step-by-step changes.

Then, we check if there is a difference between the calculated “target brightness” and the “current brightness”. If there is a difference, the update_brightness function is called to update the brightness. In this function, an upper and lower limit safety check is performed so that the calculated result does not exceed 255 or fall below 3, and finally, it is sent from the host computer to the GT-SP as a control command to change the brightness, thereby switching the display’s light and dark levels.

Furthermore, even if there is no change in brightness, a mechanism is included to resend the current brightness every 5 seconds. This automatically restores the original brightness when the GT-SP side restarts.

Summary

When we write the program and actually turn the room lights on and off, the GT-SP screen smoothly follows the changes in ambient light and changes its brightness. Even in a dark room, the screen is not too dazzling, and you can check the display comfortably.

Next time, we will continue to introduce practical electronic construction ideas using the GT-SP.

Series: Using the GT-SP Touch Panel TFT Display with Arduino

Series: Using the GT-SP Touch Panel TFT Display with Arduino