RGB LED is a kind of LED that can emit light in three different colors: red, green and blue. In this experiment, we are going to make RGB LED shifts its light among the three different colors gradually.

Components List:


Tips: If you want to buy all components above, you may need Elecfreaks Micro:bit Starter Kit.

Major Components Introduction


RGB LED is a kind of LED that has integrated red LED, green LED, and blue LED into a component. We all knows that the three primary colors of light are red, green, and blue. With different groups of the three color lights, we can create all colors of the world. Similarly, if we use RGB LED to group lights with different brightness, then it can form various colors.

RGB LED can be divided into 2 types: common anode and common cathode. In common-cathode RGB LED, its common port usually connects GND, while in common-anode RGB LED, its common port connects VCC. In this experiment, we choose common-cathode RGB LED.

Experimental Procedure

Hardware Connection

Connect your components according to the picture below:

You would see as below after you finish the connection:

Software Programming

Click to open Microsoft Makecode, write the following code in the editor.

Program as the picture shows:

Details for the code:



You can also download the links directly:


Press button A, LED turns red. Press button B, LED turns green. Press button A+B, LED turns blue.


If we want to use RGB LED to emit cyan light, magenta light, yellow light, then how to design circuit and program?