Arduino led wiring options

Today I wanted to do a basic test: Send a value (0 or 1) via a Java application to my Arduino board. If the value 1 is received, a led should light up, in all other cases the led should be off. Quite simple, I thought. In reality it wasn’t…

Main problem was the wiring of the two LEDs. Depending how the wiring was done, the digitalWrite statement needs ‘HIGH’ or ‘LOW’ to power on the led. In my code, I assumed digitalWrite(redLed, HIGH) always turned a led on. On a forum I found a good explanation about the two possible wiring schema’s. Find below an extract of the topic:

There are two ways to power and light up a resistor/led string to an Arduino output pin.
#1   output pin > anode of diode > resistor > ground
#2   output pin > cathode of diode > resistor > +5vdc.
In number one if the output pin is high the LED draws current and lights up. The output pin is said to be sourcing current.
In number two if the output pin is low the LED draws current and lights up. The output pin is said to be sinking current.

As I was using – without knowing this would have severe impact – the second wiring schema, the LEDs remained off using the code below:

/**
 * Just a simple test to see how the applied wiring scheme interprets HIGH and LOW values on the digital outputs.
 * @Author Maarten Van Damme
 */
int greenLed = 10;
int redLed = 11;

void setup() {
  Serial.begin(9600);
  pinMode(greenLed, OUTPUT);
  pinMode(redLed, OUTPUT);

}
/* Send text to the serial output */
void loop() {

  digitalWrite(greenLed, HIGH);//Depending on the wiring of the led, the led will be on or off.
  digitalWrite(redLed, HIGH);//Depending on the wiring of the led, the led will be on or off.
  delay(1000);
}

It’s a really basic thing, but still it took me some time and frustration to figure out why it didn’t work. Now I know… I feel happy again 🙂 .

Time to play with the kids (who I neglected the past hour 😳 ).

Leave a Reply

Your email address will not be published. Required fields are marked *