SMD 3Color LED Module(KY-009)

아두위키 : Arduwiki
ArduWiki (토론 | 기여)님의 2024년 4월 3일 (수) 15:11 판 (Created page with "{{#seo:|title=아두위키 : 아두이노 3색 LED SMD 모듈 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, 3색 LED SMD 모듈, 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 3색 LED SMD 모듈을 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}} File:Smd3led대표이미지.jpg|center|cla...")
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

This is an LED module that controls Red, Blue, Green primary colors with values from 0 to 255.

It is similar to a 3-color LED model.

Specifications

  • Operating Voltage: 5V
  • Operating Current: 20mA ~ 30mA

Example Usage Hardware (excluding cables and breadboard)

  • Arduino board
  • SMD 3Color LED Module
  • Push button
  • Jumper cables

Connection

Use pins D9, D10, D11 for PWM output for analog output.

Arduino SMD 3Color LED Module PUSH Button
GND - connected
D12 connected
D11 R
D10 G
D9 B

Example Code

This is an example where the LED color changes every time the button is pressed.

#define btn1 12
#define red 11
#define green 10
#define blue 9

int btnFlg1 = 0;

int btn1Chk() {
  if (digitalRead(btn1) == 0) {
    btnFlg1 = 1;
    return 0;
  }
  if (btnFlg1 == 1) {
    btnFlg1 = 0;
    return 1;
  }
  return 0;
}

int state = 0;

void setup() {
  pinMode(btn1, INPUT_PULLUP);
}

void loop() {
  if (btn1Chk()) {
    switch (state) {
      case 0:
        analogWrite(red, 255);
        break;
      case 1:
        analogWrite(red, 0);
        analogWrite(green, 255);
        break;
      case 2:
        analogWrite(green, 0);
        analogWrite(blue, 255);
        break;
      case 3:
        analogWrite(red, 255);
        analogWrite(green, 255);
        analogWrite(blue, 0);
        break;
      case 4:
        analogWrite(red, 255);
        analogWrite(green, 0);
        analogWrite(blue, 255);
        break;
      case 5:
        analogWrite(red, 0);
        analogWrite(green, 255);
        analogWrite(blue, 255);
        break;
      case 6:
        analogWrite(red, 255);
        analogWrite(green, 255);
        analogWrite(blue, 255);
        break;
      case 7:
        analogWrite(red, 0);
        analogWrite(green, 0);
        analogWrite(blue, 0);
        break;
      default:
        break;
    }
    state++;
    if (state > 7) state = 0;
  }
  delay(10);
}

Execution Result

Please check the working video at the link.