Arduino Basics – RGB LED example

4,192

In this example we connect an RGB LED to our Arduino. We used an Arduino Nano, a Nano shield and an RGB LED breakout. The aim is to create a simple example that will flash the reg, green and blue leds individually

Red LED is connected to D7
Blue LED is connected to D6
Green LED is connected to D5

The RGB LED used is a common anode type, this means that to light an LED you have to set the output to low, this will light the required LED, setting the output high will switch off the LED.

Schematic

Nano RGB LED schematic
Nano RGB LED schematic

Code Examples

int REDLED =7;
int BLUELED =6;
int GREENLED = 5;

void setup()
{
pinMode(REDLED, OUTPUT);
pinMode(GREENLED, OUTPUT);
pinMode(BLUELED, OUTPUT);
}

void loop()
{
AllOff();
digitalWrite(REDLED, LOW);
delay(500);
AllOff();
digitalWrite(GREENLED, LOW);
delay(500);
AllOff();
digitalWrite(BLUELED, LOW);
delay(500);

}

void AllOff()
{
digitalWrite(REDLED, HIGH);
digitalWrite(GREENLED, HIGH);
digitalWrite(BLUELED, HIGH);
delay(500);
}

 

 

Resources

Prototype Shield I/O Extension Board Expansion Module for Arduino Nano V3.0

Nano v3.0 Compatible with Arduino

4 Pin Terminals RGB 3-Color LED Lamp Module for Arduino

div>
/spa class=hn-texo relatet-poss- headin">You mlight lsto lke /spa class=hn-texo relatet-poss- headin">More* from-autho >
> div> >
ix"> " itemmo RGs-section"> atus-publisemmo RGs-section"x; p p p t Post <, bughi-arduin--adomq-3-gasmsensors.php"
trackback <
By > s="sea"> r me ri5d5a-rrm-badg ix"" cl 'tiv'e=ca'tiv'eabel> '/wp-="se' y '-1'>S"" cl Civie":y555 usem oss="wy 68">Andrte(REpp oss="wy 611 class="sioss="wy 365" class=oss="wy 1479" class=oss="wy 1565"LED bugs=oss="wy 28">Dclass=ss=oss="wy 142382" 32s=oss="wy 95382" class=oss="wy 149382sprss="sioss="wy s.neHa" class=oss="wy 58tem-383" class=oss="wy 160">Microb> oss="wy 19u-item-381" class=oss="wy 1s.neProxampss=oss="wy 64item-386" class=oss="wy 13"ttachment_ss=oss="wy 97"tt/div>ss=oss="wy 32-item-380" class=oss="wy 5538Tra> 2
> 0 i {wi drtpdowl.=n.push.binnet/ar(); } } drtpdowl.onchangeeftonCivChange; })(); /* ]]> */ style=""tabntainmtype=capref="x" dtionsms-ill ntRecoveionsms-ill ntRGas sen"Log I-em c da-ionsms ionsms ionsms_ion>ionsms"glesyndication.com/pagead/js/adsbygoogle.js");