KY-011 Two color LED module

1,640

 

The KY-011 Two color LED module consists of a common cathode 3mm red/green LED. You can adjust the amount of each color using PWM, so we will use 2 PWM pins on our Arduino later on to demonstrate this

 

Connection

Its best to use a couple of current limiting resistors since the module does not have any on board

KY-011ResistorArduino
G330Ω resistorPin 10
R330Ω resistorPin 11
YGND

 

Code

// Arduino test code for KY011
int redpin = 11; // select the pin for the red LED
int greenpin = 10; // select the pin for the green LED
int val;
void setup () {
   pinMode (redpin, OUTPUT);
   pinMode (greenpin, OUTPUT);
}
void loop () {
   for (val = 255; val> 0; val--)
      {
      analogWrite (greenpin, val);
      analogWrite (redpin, 255-val);
      delay (15);
   }
   for (val = 0; val <255; val++)
      {
      analogWrite (greenpin, val);
      analogWrite (redpin, 255-val);
      delay (15);
   }
}

 

Links

37 in 1 box Sensor Kit For Arduino Starters brand in stock

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.