Actuator

๐ŸŒˆ RGB LED

๐Ÿ“Œ Description

An RGB LED is a special light that can shine in red, green, and blue. By mixing these colors, it can create almost any color you can imagine.

๐ŸŽฏ Use

In our projects, RGB LEDs are used to:

  • Show different states with colors (e.g., red = stop, green = go).
  • Make robots more expressive with colorful lights.
  • Create fun visual effects and patterns.

๐Ÿ‘‰ Think of the RGB LED as the robotโ€™s mood light โ€” it changes color to communicate or decorate.

Module parameters

Pin nameDescription
GNDGND (Power Input Negative)
BDigital signal pins
RDigital signal pins
GDigital signal pins
  • Supply voltage: 3.3V/5V

  • Connection: PH2.0 2P and Dupont 2P terminal wire

  • Installation method: double screw fixing


๐Ÿ–ฅ๏ธ Code Explanation

import machine
import time

pin17 = machine.Pin(17, machine.Pin.OUT)  # Red LED pin
pin16 = machine.Pin(16, machine.Pin.OUT)  # Green LED pin
pin27 = machine.Pin(27, machine.Pin.OUT)  # Blue LED pin

while True:
    pin17.value(1)      # Turn on RED
    time.sleep(1)       # Wait 1 second
    pin17.value(0)      # Turn off RED

    pin16.value(1)      # Turn on GREEN
    time.sleep(1)       # Wait 1 second
    pin16.value(0)      # Turn off GREEN

    pin27.value(1)      # Turn on BLUE
    time.sleep(1)       # Wait 1 second
    pin27.value(0)      # Turn off BLUE

Step by Step

  1. Import machine & time โ†’ Tools to control pins and add pauses.
  2. Set pins 17, 16, 27 as outputs โ†’ Each pin controls one color: red, green, blue.
  3. Forever loop (while True) โ†’ Keeps repeating the light sequence.
  4. Red on โ†’ wait โ†’ off โ†’ The LED shines red for 1 second.
  5. Green on โ†’ wait โ†’ off โ†’ Then it shines green for 1 second.
  6. Blue on โ†’ wait โ†’ off โ†’ Finally, it shines blue for 1 second.
    ๐Ÿ‘‰ Together, the LED cycles through red โ†’ green โ†’ blue, one second each.

โœ… Conclusion of the Test

  • If the RGB LED lights up red, then green, then blue in order, the program is working.
  • This test shows how we can control each color separately.
  • Later, we can combine colors (red + green = yellow, red + blue = purple, etc.) to make more creative effects.
On this page