Cathode led segment fading out9/4/2023 Now, let’s work on the Common Anode version. Pay close attention to the direction of current-it will flow in the opposite direction with the Common Anode design (covered next). Kleenex, white paper, or a ping pong ball (with a hole in it for the LED) works well too!īelow, we show a video animation of the code executing and resulting circuit behavior. The yogurt container is used to diffuse the light. In the video below, I’m running our BlinkRGB code, which is the same as above but includes some Serial.print calls for debugging (see this mini-tutorial on using the Serial.print and the Arduino IDE’s Serial Monitor for debugging) const int DELAY_MS = 1000 // delay between color changes in ms const int RGB_RED_LED_PIN = 6 // indicated by orange wire const int RGB_GREEN_LED_PIN = 5 // indicated by green wire const int RGB_BLUE_LED_PIN = 3 // indicated by blue wire void setup () Step 4: Compile, upload, and run NOTE: For those familiar with html, this is very similar to html hexadecimal color codes where red, for example, is specified by #FF0000, green by #00FF00, blue by #0000FF, and so on.Īs usual, we introduce some constants for our literal assignments and then setup our pins as OUTPUT. In this example, we will flash the following sequence: Similarly, to make the RGB LED turn green, we would write: digitalWrite ( RGB_RED_LED_PIN, LOW ) digitalWrite ( RGB_GREEN_LED_PIN, HIGH ) digitalWrite ( RGB_BLUE_LED_PIN, LOW ) We will control the RGB LED color by outputting HIGH (5V) or LOW (0V) using digitalWrite to these pins.įor example, to make the RGB LED turn red, we would write: digitalWrite ( RGB_RED_LED_PIN, HIGH ) digitalWrite ( RGB_GREEN_LED_PIN, LOW ) digitalWrite ( RGB_BLUE_LED_PIN, LOW ) Recall that the embedded red LED is hooked up to Pin 6, the blue LED to Pin 5, and the green LED to Pin 3. We are going to write code that flashes through a sequence of colors. Notice how the schematic highlights how the current flows from the I/O pins, through the resistors, into the RGB LED, and then down to ground. Here’s the wiring without a breadboard (not recommended but perhaps easier to see the circuit itself):Īnd here’s the wiring with a breadboard (the schematic on the right is the same either way). We could have used any digital I/O pins however, we chose Pins 6, 5, and 3 for red, blue, and green respectively (these pins support PWM and thus, we’ll be able to use the same circuit for our next tutorial on cross-fading colors with RGB LEDs). With a Common Cathode design, the 2nd leg needs to be hooked up to the GND pin and the 1st (red), 3rd (blue), and 4th (green) legs should connect to digital I/O pins ( don’t forget a current limiting resistor for each). We’re going to start with a Common Cathode circuit + code because it’s more intuitive (and similar to our red LED tutorials) before covering the Common Anode version. Notice how the RGB LED type is clearly labeled. Here are two screenshots of supplier websites ( Sparkfun and Adafruit). It’s called diffused because the epoxy casing is scratchy and not perfectly transparentĪ clear Common Cathode RGB LED from Sparkfun. Instead, consult the supplier website, the datasheet, or experiment with the LED yourself (remember, diodes only work in one direction so as long as you include your current limiting resistors, you should be fine!).Ī diffused Common Anode RGB LED from Adafruit. You cannot tell whether you have a Common Anode or Common Cathode RGB LED by visual inspection. How can I tell if I have a Common Anode or Cathode RGB LED? So, you drive each individual color leg with a higher voltage source. Here, all three embedded LEDs share the cathode leg. In contrast, the Common Cathode works much more like a typical LED ( e.g., like the red LED from our previous lessons).For example, with a 5V voltage source connected to the common anode leg, setting the three other legs (red, green, blue) to 5V would, somewhat counterintuively, turn off the LED. To control the RGB LED’s color, you must hook up the anode to the higher voltage source and connect the red, green, and blue legs to lower voltage levels ( e.g., ground). With the Common Anode, the three embedded LEDs share the anode leg. Importantly but somewhat confusingly, there are two RGB LED designs-the Common Anode and the Common Cathode-which differ in the leg shared between the three embedded LEDs. While capable of displaying thousands of color combinations, RGB LEDs are actually quite simple they contain three separate LEDs in one package: red, green, and blue. RGB LED (Either Common Cathode or Common Anode) L4: Feature Selection and Hyperparameter Tuning.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |