Skip to the content
2 layers80 × 70 mmPCB RGB, the printed circuit board in 3D

An automated RGB night light system powered by STM32, featuring an OLED display, dynamic lighting effects, and a configurable sleep timer.

Size
80 × 70 mm
Copper layers
2
Thickness
1.6 mm
Parts
6
Nets
44
Pads
64
Tracks, vias
48, 0
Pours
1
Routed
Yes
KiCad
KiCad 10.0 (file 20260206)
Created
5 Aug 2026
Updated
5 Sep 2026

Overview

PCB RGB is an open-source printed circuit board by MinhDangEE, from the MinhDangEE/Multi-mode-RGB-Mood-Lamp repository on GitHub. It is a 2-layer board of 80 × 70 mm with 6 parts on 44 nets, routed with 48 tracks and 0 vias.

Its parts include 3 connectors, 1 IC and 1 switch. It belongs with the lEDs and displays and interfaces and adapters boards of this library.

README

README.md

Multi-Mode RGB Mood Lamp with Auto-Off Timer on STM32F103C8T6

This project implements an embedded ambient lighting system using the STM32F103C8T6 (ARM Cortex-M3) microcontroller. It combines 3-channel 16-bit Timer PWM color blending, real-time potentiometer brightness regulation via ADC, rotary encoder countdown scheduling with instant cancellation, an SSD1306 OLED interface, and a browser-based Web Serial control dashboard communicating over UART at 115200 baud.


Table of Contents

  1. System Overview
  2. Hardware Bill of Materials
  3. System Flowchart & Control Logic
  4. Hardware Pinout & Peripheral Mapping
  5. Operational Lighting Modes
  6. Auto-Off Countdown Timer
  7. Web Serial Control & UART Protocol
  8. Demo Video
  9. Limitations and Future Improvements
  10. Authors

1. System Overview

The firmware leverages hardware peripherals of the STM32F103C8T6 MCU to drive a common-cathode RGB LED and manage interactive controls:

TIM3 generates 1 kHz PWM across channels 1, 2, and 3 (PA6, PA7, PB0) for independent color mixing. Analog input from a 10k potentiometer on PA1 is converted through ADC1 to scale total luminous output from 0% to 100%. User control is handled via an external mode toggle button on PB12 and a KY-040 rotary encoder module on PB14 and PB15, which adjusts the auto-off timer in 10-second increments with step debouncing. The timer push button (PB13) cancels active countdowns. Status information is rendered on a 128x64 SSD1306 OLED module over software I2C.


2. Hardware Bill of Materials

The complete hardware prototype is constructed using the following components and breakout modules:

Component / ModuleSpecification / ModelQuantityRole in System
Microcontroller BoardSTM32F103C8T6 Blue Pill (ARM Cortex-M3, 72 MHz, 64KB Flash)1Master embedded processing unit
RGB LED ModuleCommon-Cathode RGB LED Breakout Module13-channel PWM mood light emitter
Rotary Encoder ModuleKY-040 Quadrature Rotary Encoder Breakout Module1Auto-off timer adjustment and instant cancel push switch
OLED Display Module0.96 inch SSD1306 I2C OLED Module (128x64 pixels, Blue/White)1Real-time status, mode, and countdown visualization
Potentiometer10k Linear Rotary Potentiometer (B10K)1Analog 0% to 100% master brightness regulator
Mode Push Button6x6mm Tactile Momentary Push Button1External hardware mode toggle trigger
USB-to-UART AdapterCP2102 USB to Serial TTL Adapter1Bidirectional PC/Web Serial interface (115200 baud)
Debugger / ProgrammerST-Link V2 USB Dongle1SWD firmware flashing and hardware debugging
Prototyping AccessoriesSolderless Breadboard and Jumper Wires1 setCircuit interconnects and power distribution

3. System Flowchart & Control Logic

The execution flow, mode transition logic, potentiometer ADC brightness mapping, and countdown timer routine are illustrated in the architecture flowchart below:

System Flowchart

4. Hardware Pinout & Peripheral Mapping

Device / ModuleModule PinSTM32 PinPeripheral FunctionElectrical Role
RGB LED ModuleRed Channel (R)PA6TIM3_CH11 kHz PWM Output
Green Channel (G)PA7TIM3_CH21 kHz PWM Output
Blue Channel (B)PB0TIM3_CH31 kHz PWM Output
Common Ground (-)GNDGroundCommon Cathode Reference
10k PotentiometerWiper PinPA1ADC1_IN1Analog Voltage Input (0V to 3.3V)
Outer Rails3.3V / GNDPower RailsVoltage Divider Reference
KY-040 Encoder ModuleCLK (Phase A)PB15EXTI15Dual-Edge Step Interrupt
DT (Phase B)PB14EXTI14Direction Logic Input
SW (Push Switch)PB13EXTI13Falling-Edge Timer Cancel
Power (+ / GND)3.3V / GNDPower RailsModule 3.3V Supply
Mode ButtonTactile SwitchPB12EXTI12Falling-Edge Mode Toggle
SSD1306 OLED ModuleSCLPB6GPIO Output PPSoftware I2C Clock
SDAPB7GPIO Output PPSoftware I2C Data
Power (VCC / GND)3.3V / GNDPower RailsModule Display Power
USB-UART BridgeTXD / RXDPA10 / PA9USART1 (RX/TX)115200 8N1 Serial Protocol
ST-Link V2SWDIO / SWCLKPA13 / PA14SWD DebugFirmware Flash & Debug

5. Operational Lighting Modes

The lamp implements five discrete operational states:

  1. Solid White: Drives Red, Green, and Blue channels at full duty cycle. Overall luminous intensity is dynamically scaled by the PA1 potentiometer.
  2. Breathing White: Modulates intensity through a 3000 ms periodic cycle applying a non-linear Gamma 2.2 curve (Duty = MaxBright * Progress^2.2) to match human eye lightness perception.
  3. Rainbow Spectrum: Cycles through six chromatic spectrum zones (Red -> Yellow -> Green -> Cyan -> Blue -> Magenta -> Red) over a 6000 ms period using linear PWM crossfading without color jumping.
  4. Custom RGB: Directly applies color coordinates transmitted over UART from the Web Serial palette.
  5. Sleep / Standby: Sets all PWM compare registers to zero, turning off the LED completely upon manual selection or timer expiration.

6. Auto-Off Countdown Timer

Turning the KY-040 encoder clockwise increases timer duration by 10 seconds per detent click, while counter-clockwise rotation decreases duration by 10 seconds. Pressing the encoder shaft switch (PB13) clears the timer and disables countdown tracking.

A background timer tick decrements remaining time once per second. When the counter reaches zero, the firmware automatically switches to Sleep Mode (Mode 0) and blanks the LED output. Remaining time is continuously updated on the OLED display and echoed over UART.


7. Web Serial Control & UART Protocol

The browser interface connects directly to the STM32 USART1 port via the Web Serial API at 115200 baud. It includes a native color picker, individual R/G/B sliders, mode preset buttons, and a line-stream buffered serial log.

Command PacketTarget ActionExample / Details
1\n or w\nSwitch to Solid WhiteConstant white illumination
2\n or b\nSwitch to Breathing WhiteGamma 2.2 breathing cycle
3\n or r\nSwitch to Rainbow Spectrum6-phase chromatic crossfade
4\n or c\nSwitch to Custom RGBUses current custom RGB registers
0\n or s\nSwitch to Sleep ModeTurns off PWM channels
n\n or SpaceNext ModeCycles sequentially through states
C:R,G,B\nSet Custom RGB CoordinatesExample: C:255,120,40\n
#RRGGBB\nSet Custom Hex ColorExample: #FF7828\n

To operate the web controller, open web/index.html in Chrome or Edge, click Connect STM32, choose the active COM port, and select colors or modes in real time.


8. Demo Video

Functional testing footage, hardware validation, potentiometer brightness control, encoder timer countdown, and web serial communication can be reviewed here:

Demo Video


9. Limitations and Future Improvements

While the current system operates reliably, several hardware and software limitations offer clear opportunities for future development:

  1. State Persistence: Current configuration parameters (active mode, custom RGB values, timer states) reside in volatile RAM and reset upon power loss. Emulating EEPROM in Flash memory (internal Flash pages) would enable persistent state recovery across reboot cycles.
  2. Wireless Connectivity: Communication currently requires a physical USB-UART cable. Integrating an ESP32 or BLE module (e.g., nRF52) would allow wireless Web Bluetooth or MQTT/Home Assistant IoT integration.
  3. Encoder Sensor Upgrade: The mechanical KY-040 encoder has finite mechanical contact life. Upgrading to a magnetic Hall-effect rotary encoder or optical encoder would eliminate mechanical wear and long-term contact degradation entirely.
  4. Acoustic / Sound Sync Mode: Adding an analog electret microphone with an operational amplifier or an I2S digital microphone (e.g., INMP441) would allow hardware FFT analysis on the STM32 to create audio-reactive music visualization.
  5. Power Management: In Sleep Mode, the microcontroller remains in full run mode with peripherals active. Implementing STM32 Stop Mode or Standby Mode with EXTI wakeup would significantly reduce idle current consumption for battery-powered operation.

10. Authors

  • Dang Quang Minh
  • Duong Minh Trong
  • Ho Thanh Nhan

Parts

6
QtyValueFootprintReferences
2Conn_01x04_SocketConnector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_VerticalJ1, J4
110KPotentiometer_THT:Potentiometer_Vishay_148-149_Single_HorizontalRV1
1Conn_01x05_SocketConnector_PinSocket_2.54mm:PinSocket_1x05_P2.54mm_VerticalJ2
1MODEButton_Switch_THT:SW_PUSH_6mm_H5mmSW2
1YAAJ_BluePill_Part_Like_SWD_BreakoutYAAJ_STM32:YAAJ_BluePill_SWD_1U3

Similar boards

  • 2 layers18.5 × 11.1 mmSwitch, the printed circuit board in 3D

    Switch

    byrantech/laptop

    anyon_e, a highly integrated, high end, open source laptop. Attempt the impossible.

    6 parts4.3kMIT
  • 2 layers14.6 × 33 mmBrain board SD Card 1, the printed circuit board in 3D

    Brain board SD Card 1

    rusefi/rusefi

    rusefi - GPL internal combustion engine control unit

    6 parts1.2k
  • 2 layers9 × 9 mmDpoint, the printed circuit board in 3D

    Dpoint

    Jcparkyn/dpoint

    Open-source digital stylus using camera tracking and inertial measurements

    6 parts1.1kMIT
  • 2 layers51.5 × 16.6 mmMicroswitchXY Endstop, the printed circuit board in 3D

    MicroswitchXY Endstop

    VoronDesign/Voron-Hardware

    Cool Hardware designed by the Voron Design group

    6 parts1.1kGPL-3.0
  • 2 layers21.9 × 76.7 mmAmiga External, the printed circuit board in 3D

    Amiga External

    hoglet67/RGBtoHDMI

    Bare-metal Raspberry Pi project that provides pixel-perfect sampling of Retro Computer RGB/YUV video and conversion to HDMI

    6 parts1kGPL-3.0
  • 2 layers88.9 × 50.8 mmBusinesscard, the printed circuit board in 3D

    Businesscard

    hackclub/OnBoard

    💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

    6 parts915
  • 2 layers20.3 × 15.2 mmL0 RGB led, the printed circuit board in 3D

    L0 RGB led

    Luos-io/luos_engine

    Open-source and real-time orchestrator for cyber-physical-systems, to easily design, test and deploy embedded applications and digital twins.

    6 parts546MIT
  • 2 layers9 × 3.6 mmOpticalEncoder, the printed circuit board in 3D

    OpticalEncoder

    adamb314/ServoProject

    Getting the most out of your hobby servo

    6 parts545

Questions

How big is the PCB RGB PCB?

It measures 80 × 70 mm and has 2 copper layers, 1.6 mm thick.

What parts does the PCB RGB use?

6 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the PCB RGB KiCad files?

From the MinhDangEE/Multi-mode-RGB-Mood-Lamp repository on GitHub, at the commit this page was made from: the board is docs/Simulation/PCB_RGB.kicad_pcb and its schematic docs/Simulation/PCB_RGB.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the PCB RGB design in my own project?

Its repository states no licence, so its author keeps all rights: ask MinhDangEE before reusing the design.