This project demonstrates the integration of an STM32F103C6 microcontroller with the APDS-9005 ambient light photo sensor. The sensor provides an analog output corresponding to ambient light levels, which the STM32 reads using its ADC and transmits via UART for monitoring or control.
The APDS-9005 is ideal for applications requiring ambient light measurement to optimize display backlighting, making it suitable for mobile devices, notebooks, consumer electronics, and automated lighting systems.
By continuously converting sensor voltage outputs to luminance in Lux, this project enables real-time monitoring and control of lighting conditions.
Overview of the APDS-9005 Sensor
- Spectral Responsivity: Matches human eye sensitivity (CIE photopic standard)
- Miniature ChipLED Surface-Mount Package: 0.55 mm × 1.60 mm × 1.50 mm
- Low Sensitivity Variation: Consistent performance across light sources
- Operating Temperature: -40°C to 85°C
- Supply Voltage (Vcc): 1.8V – 5.5V
- Lead-Free Package: RoHS compliant
- Output Linearity: Maintains linear response across wide illumination range
Applications
- Display Backlighting Control: Smartphones, PDAs, notebooks, TVs, cameras
- Automatic Lighting Management: Residential, commercial, automotive interior lighting
- MCU Selection: STM32F103C6 (8 MHz clock)
- ADC1 Configuration:
-
Channel: IN0 (PA0)
-
Resolution: 12-bit
-
Continuous Conversion Mode: Enabled
- UART1 Configuration:
-
Baud Rate: 115200
-
Word Length: 8 bits
- Generate initialization code in STM32CubeIDE.
Key Functions
- Sensor Initialization:
-
Initialize the APDS-9005 sensor with the STM32 ADC and UART handles.
-
LightSensor_Init(&hadc1, &huart1);
- Read Analog Voltage from Sensor:
-
The ADC reads the sensor output voltage, which is converted to a float in volts.
-
float vout = LightSensor_ReadVout(); // Reads voltage from APDS-9005
- Convert Voltage to Luminance (Lux):
-
Uses a multi-point mapping function to convert measured voltage into corresponding Lux values.
-
float lux = LightSensor_ReadLuminance(); // Converts voltage to Lux
- Print Readings via UART:
-
Sends both voltage and Lux readings to the terminal for monitoring.
-
LightSensor_PrintReadings(); // Prints Vout and Luminance to UART
- Main Loop (Continuous Monitoring):
-
Continuously reads the sensor and outputs voltage and Lux every 500 ms.
while (1)
{
LightSensor_PrintReadings(); // Read sensor and print values
HAL_Delay(500); // Delay between readings
}
Components
- STM32F103C6 microcontroller
- APDS-9005 sensor (simulated with potentiometer)
- Virtual Terminal
Connections
- PA0 → Sensor VOUT
- PA9 → Terminal RX
Simulation Steps
- Load the generated.hex file into STM32 in Proteus.
- Adjust the potentiometer to simulate varying ambient light.
- Observe corresponding Lux values on the Virtual Terminal.
If you have any questions or suggestions, don’t hesitate to leave a comment below.
Comments