Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RTOS Smart Light Dimmer

Circuit Schematic

CE451 Embedded Systems · Ashesi University
An RTOS-based smart light dimmer built on the STM32 microcontroller.


Overview

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.


Features

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

Hardware

  • 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.


Software Architecture

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

Getting Started

Prerequisites

  • STM32CubeIDE (or STM32CubeMX + your preferred toolchain)
  • STM32 HAL / CMSIS libraries
  • FreeRTOS (included via STM32Cube middleware)
  • ST-Link programmer / debugger

Building & Flashing

  1. Clone the repository:
    git clone https://github.com/ShadrackAgyei/RTOS-smart-light-dimmer.git
  2. Open the project in STM32CubeIDE (File → Open Projects from File System).
  3. Build the project (Project → Build All).
  4. Connect your STM32 board via ST-Link and flash (Run → Debug or Run → Run).

Serial Monitor

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.


Project Structure

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

Demo

A demonstration video (embeded_final.mov) is included in the repository, showing the system responding dynamically to changes in ambient light.


License

This project is licensed under the MIT License — see the LICENSE file for details.


Author

Shadrack Agyei Nti
CE451 Embedded Systems · Ashesi University · 2026

About

RTOS-based smart light dimmer on STM32 — reads 3 LDRs via ADC with moving average filtering, adjusts LED brightness via PWM at 300ms intervals, features IWDG watchdog, heartbeat, standby mode, USART status reporting, and low-light alarms. CE451 Embedded Systems @ Ashesi University.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages