Project tutorial

For those LED's a leg short of three.

• 1,855 views
• 2 respects

## Components and supplies

×1
 Arduino UNO & Genuino UNO
×1

## Apps and online services

 Arduino IDE

### Description:

This circuit came about during some experiments I was doing in relation to building a transistor tester. Identifying the pins of a transistor using an Arduino involves altering the output pin directions and taking voltage measurements. This set me wondering, what would happen if I connected up a 2 lead bi-colored LED (with resistor) and alternated the output pin directions. I hoped the LED would alternately flash both of its colors, I was not disappointed.

### Circuit description:

The circuit comprises of an Arduino (UNO) a 2 wire bi-colored LED and a 270 ohm resistor.

The resistor value used is somewhat arbitrary, I had salvaged the LED I used so I first connected it to 5 volts via a 1k resistor and measured the voltages across it (2v green, 1.6v red).

Using the standard formula (supply voltage-LED voltage drop)/current, with current set to 20 milliamps (pretty standard for LED's), gives resistor values of 150 and 170 ohms respectively for the recorded voltages.

The nearest value in my tub of components was the 270 ohm so re-arranging the formula to (supply voltage-LED voltage drop)/resistance (270 ohm) shows we have LED operating currents of 10 and 12 mA for 2 and 1.6 volts respectively, in my view this gives sufficient brightness.

### Software description:

The code for this project is very simple:

In the code setup section:

We assign the 2 pins we are using as output.

In the code loop section:

We call the function which sets the output pin voltages for the led.

We delay 2 seconds.

We call our function again this time with the pin identifiers reversed.

We delay 2 seconds.

At this point we go back to the start of our loop.

The function first sets both output pins to 0 volts, this is important as you don't want both pins pushing 5 volts into each other, and then sets one pin to 5 volts before exiting.

## Code

```/*
Test to see if you can flash 2 lead bi led using 2 ports -> you can
*/

//the pins -> red and green indicate positive connection pin for that colour
const int pin_red=2;
const int pin_green=3;

void setup() {
pinMode(pin_red,OUTPUT);
pinMode(pin_green,OUTPUT);
}

void loop() {

set_outputs_plus_ground(pin_red,pin_green);
delay(1000);
set_outputs_plus_ground(pin_green,pin_red);
delay(1000);

}

//my_functions
void set_outputs_plus_ground(int pin_plus, int pin_ground)
{
//set both pins low first so you don't have them pushing 5 volts into eachother
digitalWrite(pin_plus,LOW);
digitalWrite(pin_ground,LOW);
//set output pin as high
digitalWrite(pin_plus,HIGH);
}
```

## Schematics

• 6 projects
• 15 followers

#### Published on

April 11, 2017
See similar projects
you might like

#### LED Emergency Lights using WS2812 RGB LED Module

Project tutorial by bigboystoys13

• 15,535 views
• 34 respects

#### Bluetooth control led with lcd led status display real time.

Project tutorial by Youssef Sabaa

• 28,581 views
• 54 respects

• 13,522 views
• 28 respects

• 11,394 views
• 18 respects

#### LED Roulette Game

Project tutorial by Arduino “having11” Guy

• 12,816 views
• 23 respects

• 3,554 views
• 1 comment
• 11 respects