Arduino/Netduino: Using the RGB smt LED Keynes Sensor

I am using the Keyes Sensor which came in a kit I bought from, you can get the sensor kit cheaper elsewhere (now I know).  The LED looks like the picture.  The LED has a blue, red and green LEDs on it.  The leads on my sensor appear to be incorrect, the Green and Red are reversed.  Which could be a problem if you want to issue a red light to stop something.  In this case, you need to know that the manufacturers often makes these kinds of mistakes, and if you order 20,000 units with the wrong pin out, you might want to issue a new version of your software and change the output in software.  Or have your buyer send the product back, but you might miss the business deadline.  Your choice.  Now the technology:

LEDs may have specifications you can locate, but if you can’t find them, then in general the following data will usually work (and if it doesn’t, don’t  blame me, I have burned out a number of LEDs):

  • Diode forward voltage specification from the manufacture's website or packaging, if no information, then generally the voltage is as follows:

  • If you do not have this information you can use the following to estimate:

    • Red or Orange 2.0 V
    • Yellow 2.1 V
    • Green 2.2 V
    • Blue (430 nm) 4.6 V
    • In this case I am pretty sure that the specifications for this LED is:
      • True Green, Blue, White 3.3 V
    • LEDs can be hooked in series, but not in parallel (most times), in this case you will use them one at a time.

Calculate the required LED resistor value.

  • Determine the LED Resistance  Value, in the case of the Netduino Plus 2 I will start off with the supply voltage of 3.3 volts
    • R=(supply voltage – LED Voltage) / LED current
    • Or just use a 330 Ohm resistor, which is what I did.  Why? Because it was laying in the box, and I know that in general it will work.
    • 360 ohms is likely the correct value, or this sensor may have internal resistors, but since it is apparently a line “leftover” or salvage the precise data is not available.
    • And it appears that I burned out the Red LED, but the Green and Blue work fine.  Nice

Now that we have the LED hooked up and tested, as well as broken, it’s time to implement the .NET Micro Framework blinky with the 3_clor LED, which apparently is now a 2_clor since the Red no longer works. 🙁

Here is the flow for the sensor (and yes the LED in this configuration is a sensor).


Code to blink the lights:

(Note: Netduino first, Arduino is the same, except the coding is different, use the Blink sample and add an LED, change the variable names so that you have two LEDs and Two outputs.


Netduino, connect the digital pin 12 to the “R” on the Keyes 3_Clor sensor (this will be green not red on my sensor, but it would reasonably be red).  For this code to work as written, you must have the keyes 3_clor cnt1 3 Color LED that is included in the Sunfounder Labs kit available from Amazon or (cheaper but slower shipping).  You need to have your Netduino up to the latest firmware (on 5/29/2014 it was Solution Release Info Solution Vendor Info: Netduino Plus 2 (v4.3.1.0) Software Version Build Date: Feb 25 2014, follow the instructions at: .

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace Blinky
    public class Program
        public static void Main()
            // write your code here
            OutputPort led12 = new OutputPort(Pins.GPIO_PIN_D12, false);
            OutputPort led13 = new OutputPort(Pins.GPIO_PIN_D13, false);
            while (true)





This code is from: which is provided with the sensor, I removed the redpin wiring.  If you are using VisualMicro, just create a new sketch (make sure that you are do not have an existing sketch, I think both will be installed on the board).  I am using an UNO.

int redpin = 11;    // select the input pin for the potentiometer

int bluepin =10;      // select the pin for the LED

int yellowpin =9;

int val;

void setup() {
    pinMode(redpin, OUTPUT);
    pinMode(bluepin, OUTPUT);
    pinMode(yellowpin, OUTPUT);


void loop()

    for(val=255; val>0; val--)
        analogWrite(11, val);
        analogWrite(10, 255-val);
        analogWrite(9, 128-val);

    for(val=0; val<255; val++)
        analogWrite(11, val);
        analogWrite(10, 255-val);
        analogWrite(9, 128-val);
    Serial.println(val, DEC);




The code for the Arduino is very similar to the Netduino, exception is that the *.ino files do not support object oriented programming like the Netduino.  It is nice to just write functional programming though.   Issues with the Arduino devices is that there seems to be a problem with the USB ports that shut down due to over-current scenarios.  Not a big deal, but be aware if you are having problems with USB port, some computers have one USB port that can handle more current than the other ones (or one).  If this happens, shutting the computer down can release the “crow-bar” situation on the USB port that isn’t working, it isn’t broken, it just turned itself off.

/* Code starts below */

  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led13 = 13;
int led12 = 12;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led13, OUTPUT);    
  pinMode(led12, OUTPUT);    

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  digitalWrite(led12, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led12, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second

Comments (1)

  1. Edison Opto Viet Nam says:

    Thanks for your sharing. I'm learning about den led

Skip to main content