Wireles control RGB LED with PWM


In this article you can read about working with RGB LED diode. You can display 8 colors using one LED diode. LED is connected by 3 pins to MCU for control color and by 1 pin is connected to MCU via transistor to regulate brightness (see scheme). Regulation of brightness is performed by PWM.

What do we need?

  • CK-USB
  • 2 RF modules (1 is replaceable by USB gateway)
  • At least 1 RGB LED
  • Some transistor for controlling state of LED (transistor is connected between LED and ground – see in the scheme)

How does it work?

You are controlling color and brightness from terminal on PC by RF (use E03-TR application programmed in the USB gateway or in another RF module, for controlling brightness you have to have checked “Use numbers”). By sending the packet with specific structure which is described below, you can choose module to which you are sending this packet and with this packet you can change the color or brightness.

What is PWM

PWM means pulse-width modulation and it’s modulation for the transfer of analogue signal by two-point signal (zeroes and ones). The main magic of PWM is fast switching the state on/off. So LED is for small moment on and for next small moment off. When you are switching these states fast, the human eye perceives less shine of LED.

What is structure of packet

Packet contains 4-6 characters. The First two characters are the address of the module which we want to control. Next one character is letter ‘P’ or ‘T’. We use ‘P’ for controlling brightness and ‘T’ for changing color.
In case of ‘P’ the next character is number from 0 (less) to FF (more). This number means the time, when the LED is on. You must to check “Use numbers” in terminal.
In case of ‘T’ next 3 characters mean the code of color. These three characters are on positions of red (the first of them), green (the second) and blue (last position). They can be only 0 (off) or 1 (on), so you can make 8 colors – red, green, blue, magenta, cyan, yellow, white and no light).

Circuit diagram



Address of module (for example 01), ‘T’ means set of color, red color

Address of module (for example 01), ‘T’ means set of color,blue color

Address of module (for example 01), ‘P’ means set of PWM, value (longer time LED is on)

Address of module (for example 01), ‘P’ means set of PWM, value (shorter time LED is on)

Full souce code is attached

Author: Martin Strouhal

Download Attachments

  • c rgbl_3led.c
    RGB LED driver source code
    File size: 3 kB Downloads: 273
  • zip rgbl_macros.zip
    Macros for IDE
    File size: 435 B Downloads: 232

Leave a Reply

Your email address will not be published. Required fields are marked *