The TEMT6000 is a light-dependent sensor that reacts to ambient light intensity, making it useful for applications requiring automatic brightness adjustment. In this tutorial, we will interface the TEMT6000 sensor with an Arduino Nano, control an LED based on light intensity, and display real-time data on an OLED screen.
Components Required
- Arduino Nano
- TEMT6000 Ambient Light Sensor
- OLED Display (SSD1306, 128x64, I2C)
- 5mm LED
- Connecting/Jumper Wires
- Breadboard
- Arduino Nano Cable
About the Component
TEMT6000 Ambient Light Sensor
The TEMT6000 is an ambient light sensor designed to detect light intensity similar to the human eye's response. It is widely used in applications requiring automatic brightness control, daylight sensing, and energy-efficient lighting.
This sensor works as a phototransistor, meaning its resistance changes based on the intensity of ambient light. The more light it receives, the higher the current it allows to pass. This current is converted into a voltage output that can be read by an ADC (Analog-to-Digital Converter) in a microcontroller like Arduino.
Features and Specifications
- Operating Voltage: 3.3V to 5V
- Current Consumption: Typically very low
- Spectral Response: Close to human eye sensitivity (similar to the photopic curve)
- Light Sensitivity Range: ~1 to 1000 lux
- Output Type: Analog (voltage proportional to light intensity)
- Package Type: SMD or through-hole
Arduino TEMT6000 Ambient Light Sensor Circuit Diagram


-
TEMT6000 Sensor Connections:
-
VCC → 5V (Arduino Nano)
-
GND → GND (Arduino Nano)
-
OUT → A0 (Arduino Nano)
-
-
OLED Display Connections:
-
VCC → 5V (Arduino Nano)
-
GND → GND (Arduino Nano)
-
SCL → A5 (Arduino Nano)
-
SDA → A4 (Arduino Nano)
-
-
LED Connection:
-
Anode (+) → D9 (Arduino Nano, PWM Pin)
-
Cathode (-) → GND
-
Code Explanation for TEMT6000 Ambient Light Sensor with Arduino
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
-
Wire.h
→ Required for I2C communication (used by the OLED display). -
Adafruit_GFX.h
→ Graphics library for text and shapes on displays. -
Adafruit_SSD1306.h
→ OLED driver library for SSD1306-based screens.
#define TEMT6000_PIN A0 // Light Sensor connected to A0
#define LED_PIN 9 // LED connected to PWM pin D9
- The TEMT6000 light sensor is connected to Analog Pin A0.
- The LED is connected to Digital Pin D9, which supports PWM (Pulse Width Modulation).
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin not used
- Defines the OLED screen's resolution as 128x64 pixels.
- The OLED does not use a reset pin, hence
-1
.
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- Creates an OLED display object named
display
with the specified dimensions and I2C communication.
int currentBrightness = 0; // Stores the LED's current brightness
int targetBrightness = 0; // Target brightness based on sensor reading
const int fadeSpeed = 5; // Adjust speed of brightness change (1-10, higher = faster)
-
currentBrightness
→ The current PWM value applied to the LED. -
targetBrightness
→ The desired LED brightness based on the light sensor. -
fadeSpeed
→ Controls how fast the LED transitions to the new brightness.
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
- Initializes serial communication at 9600 baud for debugging.
- Configures LED pin (D9) as an output.
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Default I2C address: 0x3C
Serial.println("SSD1306 OLED failed to initialize!");
while (1); // Halt execution
}
- Initializes the OLED display using I2C address 0x3C.
- If the OLED fails to initialize, the system halts execution.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.println("TEMT6000 Ready");
display.display();
delay(2000);
- Clears the screen.
- Sets text properties (size: 1, color: white).
- Displays "TEMT6000 Ready" message for 2 seconds.
int lightValue = analogRead(TEMT6000_PIN); // Read light sensor (0-1023)
float voltage = lightValue * (5.0 / 1023.0); // Convert to voltage (0-5V)
-
Reads the analog value from the TEMT6000 sensor (range:
0
to1023
). -
Converts the analog value into voltage using the formula:
- Uses
map()
to invert brightness:- Bright light → Low LED brightness.
- Dark environment → High LED brightness.
-
map(value, fromLow, fromHigh, toLow, toHigh)
convertslightValue
from0-1023
to255-0
.
if (currentBrightness < targetBrightness) {
currentBrightness += fadeSpeed; // Increase brightness gradually
if (currentBrightness > targetBrightness) currentBrightness = targetBrightness;
} else if (currentBrightness > targetBrightness) {
currentBrightness -= fadeSpeed; // Decrease brightness gradually
if (currentBrightness < targetBrightness) currentBrightness = targetBrightness;
}
- Smoothly transitions the LED brightness to the target value.
- If
currentBrightness
is lower thantargetBrightness
, it increases. - If
currentBrightness
is higher, it decreases. - The adjustment happens in steps of
fadeSpeed
to create a gradual fade effect.
analogWrite(LED_PIN, currentBrightness); // Apply smooth brightness transition
- Sends the
currentBrightness
value to the LED using PWM.
Serial.print("Light Intensity: ");
Serial.print(lightValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.print("V | LED Brightness: ");
Serial.println(currentBrightness);
- Prints light intensity, voltage, and LED brightness to the Serial Monitor.
display.clearDisplay();
display.setTextSize(1);
display.setCursor(10, 5);
display.println("TEMT6000 Sensor");
display.setCursor(10, 20);
display.print("Intensity: ");
display.println(lightValue);
display.setCursor(10, 35);
display.print("Voltage: ");
display.print(voltage, 2); // 2 decimal places
display.println("V");
display.setCursor(10, 50);
display.print("LED: ");
display.print(currentBrightness);
display.println(" PWM");
display.display();
delay(20);
- Displays a title.
- Displays light intensity.
- Displays sensor voltage (formatted to 2 decimal places).
- Displays the current LED brightness level (PWM value).
- Updates the OLED display with new information.
- Adds a small 20ms delay to smooth out brightness transitions.
The Arduino Nano reads light intensity from the TEMT6000 sensor and uses it to control the brightness of an LED. The brightness is adjusted inversely—higher light levels result in a dimmer LED and vice versa. The sensor data, including light intensity, voltage, and LED brightness, is displayed on an OLED screen.
This Arduino TEMT6000 sensor project demonstrates how to interface a TEMT6000 light sensor with an Arduino Nano to control an LED’s brightness dynamically. The OLED display provides real-time feedback, making it suitable for various automation and smart control applications. By integrating this setup into larger systems, we can enhance energy efficiency and user experience in multiple domains.
TEMT6000 Ambient Light Sensor Real-Life Applications
-
Automatic Street Lighting: The system can be used in streetlights to dim or brighten based on ambient light.
-
Smartphone Screen Brightness Adjustment: Similar sensors are used in smartphones to automatically adjust display brightness.
-
Home Automation: Used in automated lighting systems to optimize energy consumption based on natural light availability.
-
Photography Light Metering: Photographers use such sensors to measure light intensity for optimal exposure settings.
TEMT6000 Ambient Light Sensor Arduino Code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define TEMT6000_PIN A0
#define LED_PIN 9
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int currentBrightness = 0;
int targetBrightness = 0;
const int fadeSpeed = 5;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 OLED failed to initialize!");
while (1);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.println("TEMT6000 Ready");
display.display();
delay(2000);
}
void loop() {
int lightValue = analogRead(TEMT6000_PIN);
float voltage = lightValue * (5.0 / 1023.0);
targetBrightness = map(lightValue, 0, 1023, 255, 0);
if (currentBrightness < targetBrightness) {
currentBrightness += fadeSpeed;
if (currentBrightness > targetBrightness) currentBrightness = targetBrightness;
} else if (currentBrightness > targetBrightness) {
currentBrightness -= fadeSpeed;
if (currentBrightness < targetBrightness) currentBrightness = targetBrightness;
}
analogWrite(LED_PIN, currentBrightness);
Serial.print("Light Intensity: ");
Serial.print(lightValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.print("V | LED Brightness: ");
Serial.println(currentBrightness);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(10, 5);
display.println("TEMT6000 Sensor");
display.setCursor(10, 20);
display.print("Intensity: ");
display.println(lightValue);
display.setCursor(10, 35);
display.print("Voltage: ");
display.print(voltage, 2);
display.println("V");
display.setCursor(10, 50);
display.print("LED: ");
display.print(currentBrightness);
display.println(" PWM");
display.display();
delay(20);
}