CE451 Embedded Systems · Ashesi University
An RTOS-based smart light dimmer built on the STM32 microcontroller.
This project implements a real-time, closed-loop light dimming system using FreeRTOS on an STM32 microcontroller. Three Light Dependent Resistors (LDRs) continuously sense ambient light conditions; their ADC readings are averaged and used to automatically adjust LED brightness via PWM. The system is hardened with a watchdog timer, low-light alarms, standby mode, and serial status reporting — making it a robust embedded control application.
| Feature | Description |
|---|---|
| 3× LDR Sensing | Three LDRs are read via ADC and averaged for noise-resilient light measurement |
| Moving Average Filter | Smooths ADC samples to eliminate transient noise spikes |
| PWM Brightness Control | LED brightness is adjusted automatically every 300 ms based on filtered sensor data |
| IWDG Watchdog | Independent Watchdog Timer resets the system if any task stalls or hangs |
| Heartbeat Indicator | Dedicated LED blinks periodically to confirm the system is alive and running |
| Standby Mode | System enters a low-power standby state when sustained low activity is detected |
| USART Status Reporting | Sensor readings, brightness levels, and system state are broadcast over serial |
| Low-Light Alarm | Triggers an alert when ambient light drops below a configurable threshold |
- Microcontroller: STM32 (STM32F4 series recommended)
- Light Sensors: 3× LDR (Light Dependent Resistors) with voltage divider pull-down resistors
- Output: LED(s) driven via PWM-capable GPIO timer channel
- Communication: USART serial interface (for status output / debugging)
- Watchdog: IWDG (Independent Watchdog) peripheral
Refer to the schematic above for wiring and pin assignments.
The firmware is structured as a set of concurrent FreeRTOS tasks:
┌──────────────────────────────────────────────────────────┐
│ FreeRTOS Kernel │
├────────────────┬───────────────┬────────────┬────────────┤
│ Sensor Task │ Dimmer Task │ Monitor │ Heartbeat │
│ (ADC + MAF) │ (PWM output) │ Task │ Task │
│ 300ms period │ 300ms period │ (USART) │ (LED) │
└────────────────┴───────────────┴────────────┴────────────┘
│ │
Shared Queue / Semaphore (thread-safe sensor data)
- Sensor Task — samples all 3 LDR ADC channels and applies a moving average filter
- Dimmer Task — reads the filtered light value and updates the PWM duty cycle
- Monitor Task — transmits system status over USART; raises low-light alarms
- Heartbeat Task — toggles an LED to indicate the system is running normally
- IWDG — independently kicks the watchdog; resets on task deadlock or failure
- STM32CubeIDE (or STM32CubeMX + your preferred toolchain)
- STM32 HAL / CMSIS libraries
- FreeRTOS (included via STM32Cube middleware)
- ST-Link programmer / debugger
- Clone the repository:
git clone https://github.com/ShadrackAgyei/RTOS-smart-light-dimmer.git
- Open the project in STM32CubeIDE (
File → Open Projects from File System). - Build the project (
Project → Build All). - Connect your STM32 board via ST-Link and flash (
Run → DebugorRun → Run).
Connect a serial terminal (e.g., PuTTY, CoolTerm, or the STM32CubeIDE console) to the USART port at the configured baud rate to view live sensor readings, brightness percentages, and alarm events.
RTOS-smart-light-dimmer/
├── Code Files/ # STM32 firmware source code
├── schematic.jpeg # Hardware wiring schematic
├── Embedded project addDetails.pdf # Detailed project report
├── embeded_final.mov # Demo video
└── LICENSE
A demonstration video (embeded_final.mov) is included in the repository, showing the system responding dynamically to changes in ambient light.
This project is licensed under the MIT License — see the LICENSE file for details.
Shadrack Agyei Nti
CE451 Embedded Systems · Ashesi University · 2026
