You are on page 1of 14

SensorUserManual

TriColourLED
ByCHAUTszLing(53554446),WANPuiYin(53444350),POONManTing(53553056)

SensorName:
TriColorLED
Costperunit:
$5HKD
InformationURLtodatasheet:
http://cdn.sparkfun.com/datasheets/Components/LED/YSLR596AR3G4B5CC10.pdf

GeneralInformation

AboutLED

LEDstandsforLightEmittingDiode.Theyarediodesthataredesignedtogiveoff
light.

LEDsarespeciallybuiltintoroundedplasticbulbstomakethellightappearbrighter
andmoreconcentrated.DifferentcolorsofLEDhavedifferentwavelengthwhich
determinewhatcolorwillshowup.Forexample,whenthewavelengthisabout
630640
nanometers,itappearsasredcolor,while,whenwavelengthisabout
465475
nanometers,wecanseethelightasbluecolor.

WhatdoesLEDdo?

LEDtechnologyisaconvenient,energysavingandfastresponselightsource.
Becauseofthesefeatures,itiscommonlyappliedindifferentdevicesinourdailylife,
suchasroadmessagedisplay,trafficlight,flashlightetc.

HowdoesLEDemitslight?

Whenadiodeisforwardbiasedsothatelectronsandholesarezippingbackand
forthacrossthejunction,they'reconstantlycombiningandwipingoneanotherout.
Soonerorlater,afteranelectronmovesfromthentypeintotheptypesilicon,itwill
combinewithaholeanddisappear.Thatmakesanatomcompleteandmorestable
anditgivesoffalittleburstofenergyintheformofatiny"packet"orphotonoflight.

AboutTriRGBLED

Diffused5mmtricolorLEDwithseparatered,greenandblueLEDchipsinside.3
distinctcolorsinsidecandisplayseparatelyandindependentlycontrolledbytheuser.
TheseareCommonCathodetypewhichmeansyouconnectonepinto5Vorsoand
thentietheotherthreelegstogroundthrougharesistor.WecarryanduseCAmore
thanCCbecausemultiLEDdriverchips(suchastheTLC5940/TLC5941)areoften
designedexclusivelyforCAandcan'tbeusedwithCommonCathode.

Afourleadarrangementistypicalwithonecommonlead(anodeorcathode)andan
additionalleadforeachcolor(RedGreenBlue).

Features&Specifiations

ForwardVoltage:R:1.82.2G:3.03.4B:3.03.4
IV:R:50006000G:60007000B:25003000
XY/WLD:R:620625G:515520B:460465
LightColor:RGB
Size:5mm
EmittedColour:Red/Green/Blue
Possiblenumbersofcoloremitted:256^3(256foreachRGB)
Pinssequence:RED/CommonCathode(positiveterminal)/Green/Blue
LensColor:Diffused
LuminousIntensity:4000/8000/5000mcd
ForwardVoltage(V):2.1~3.4
ViewAngle:60degree.
easytoburnouttheLEDresistanceofafewhundredto1000ohm
R:wavelength630640nmBrightness10001200mcdVoltage1.82.0V
G:wavelength515512nmBrightness30005000mcdVoltage3.23.4V
B:wavelength465475nmBrightness20003000mcdVoltage3.23.4V

Gettingittowork!

Insertthe2LEDsfollowingthisdirection.Thelongestlegconnected
toground.

Examplecode:

/*triLEDplay*/
intbutton1=13
intval1
intred1=9
intgreen1=10
intblue1=11
intbutton2=2
intval2
intred2=3
intgreen2=5
intblue2=6
intbright[6]={
250,125,5,250,125,5}
intfade[6]={
5,5,5,5,5,5}

booleanmode1=false
booleanr1=false
booleang1=false
booleanb1=false
booleanmode2=false
booleanr2=false
booleang2=false
booleanb2=false
inttime

constintpot=0
intpotVal=0

intpwmVal=0

voidsetup(){

pinMode(button1,INPUT)
pinMode(red1,OUTPUT)
pinMode(green1,OUTPUT)
pinMode(blue1,OUTPUT)

pinMode(button2,INPUT)
pinMode(red2,OUTPUT)

pinMode(green2,OUTPUT)
pinMode(blue2,OUTPUT)

Serial.begin(9600)
}

voidloop(){

val1=digitalRead(button1)
val2=digitalRead(button2)
potVal=analogRead(pot)

pwmVal=map(potVal,0,1023,0,100)

Serial.print("pot=")

Serial.print(potVal)
Serial.print("\tpwm=")
Serial.println(pwmVal)

//player1

if(val1==1){
if(!mode1){
mode1=true
}
else{
mode1=false
bright[0]=250
bright[1]=125
bright[2]=5
}
}

if(mode1){
time=pwmVal*10
if(!r1){
bright[0]=250
bright[1]=0
bright[2]=0
r1=true
b1=false
}
elseif(r1&&!g1){

bright[0]=0
bright[1]=250
bright[2]=0
g1=true
}
elseif(r1&&g1&&!b1){
bright[0]=0
bright[1]=0
bright[2]=250
b1=true
r1=false
g1=false
}
}
else{
time=pwmVal

for(inti=0i<3i++){
if(bright[i]<=0||bright[i]>=255){
fade[i]=fade[i]
}
bright[i]=bright[i]+fade[i]
}
}

//player2
if(val2==1){
if(!mode2){
mode2=true
}
else{
mode2=false

bright[3]=250
bright[4]=125
bright[5]=5
}
}

if(mode2){
time=pwmVal*10

if(!r2){
bright[3]=250
bright[4]=0
bright[5]=0
r2=true
b2=false
}
elseif(r2&&!g2){
bright[3]=0
bright[4]=250
bright[5]=0
g2=true
}
elseif(r2&&g2&&!b2){
bright[3]=0
bright[4]=0
bright[5]=250
b2=true
r2=false
g2=false
}
}
else{
time=pwmVal

for(inti=3i<6i++){
if(bright[i]<=0||bright[i]>=255){
fade[i]=fade[i]
}
bright[i]=bright[i]+fade[i]
}
}

analogWrite(red1,bright[0])
analogWrite(green1,bright[1])
analogWrite(blue1,bright[2])
analogWrite(red2,bright[3])
analogWrite(green2,bright[4])
analogWrite(blue2,bright[5])
delay(time)

CodeinEnglish

intbutton1,val1,red1,green1,blue1,button2,val2,red2,green2,blue2

Setvariablesforeachbutton,buttonvalue(0/1,on/off),theRGBcolourandtheir
correspondingport,inordertoreadthedatafromtheswitchandcontroleachRGB
colourofeachLEDrespectively.
intbright[6]={250,125,5,250,125,5}
intfade[6]={5,5,5,5,5,5}
inttime

SetarrayfrothebrightnessofeachLEDsRGBcoloursandalsogiveafadingvalue.
Settimeforthechangeofdurationofdelay.
booleanmode1,r1,g1,b1,mode2,r2,g2,b2

Setbooleanforthemodeswitchtingofthelight.
constintpot=0
intpotVal=0

intpwmVal=0

Settingofpotentiometre.TheeanalogpinA0willbeconnected,readingthedatathen
saveinvariablepotVal,pwmValisthevariableformappinginthelaterpart.
pinMode(button1,INPUT)
pinMode(red1,OUTPUT)
pinMode(green1,OUTPUT)
pinMode(blue1,OUTPUT)

pinMode(button2,INPUT)
pinMode(red2,OUTPUT)
pinMode(green2,OUTPUT)
pinMode(blue2,OUTPUT)

TellArduinothemodeofeachpin,whethertheyareusingasdatainputoroutput.

val1=digitalRead(button1)
val2=digitalRead(button2)
potVal=analogRead(pot)

pwmVal=map(potVal,0,1023,0,100)

Savethedataofthebuttonvalue(0/1,on/off)andpotentiometrevalueinvariables.
Writteninvoidloop(),asthevalueshouldbereadthroughouttheprocess.After
readthepotVal,alsomappingthevaluefrom01023to0100forfurtheruse.

Serial.print("pot=")

Serial.print(potVal)
Serial.print("\tpwm=")
Serial.println(pwmVal)

Printthepotentiomerevaluereadandthemappingresultintheserialmonitor.
if(val1==1){
if(!mode1){
mode1=true
}
else{
mode1=false
bright[0]=250
bright[1]=125
bright[2]=5
}
}

Afterreadingthevaluefromtheswitch,determinewhichmodetousebysimple
ifelsestatement.Alsoresetthebrightnessofthelightafterusinganothermodein
ordertogivethesameeffect.
if(mode1){
time=pwmVal*10
if(!r1){
bright[0]=250
bright[1]=0

bright[2]=0
r1=true
b1=false
}
elseif(r1&&!g1){
bright[0]=0
bright[1]=250
bright[2]=0
g1=true
}
elseif(r1&&g1&&!b1){
bright[0]=0
bright[1]=0
bright[2]=250
b1=true
r1=false
g1=false
}
}else...

Foronmode,theLEDwillbbeshowingthecolourpatternred,green,blueinrythm.
Nowsetthetimeofdelayaccordingtothevalueofthepotentiometre,buttimes10
otherwisethechangeoflightwillbetoofast.Thethreeifelseifstatementistocontrol
thecolourpattern.Afterredlighton,thengreenlight,andbluelight,thenloopagain.

...else{
time=pwmVal

for(inti=0i<3i++){
if(bright[i]<=0||bright[i]>=255){
fade[i]=fade[i]
}
bright[i]=bright[i]+fade[i]
}
}

Foroffmode,theLEDwillbefading,combiningdifferentcolours.Resetthetime,but
notmultiplying10thistimeasthatwillbetooslowforfadingeffect.Aforloopisused
heretocallthearrayandtellseachRGBlighttofade.

Thewholeifelsestatementwillberepeatedonceforthesameoperationofasecond
LEDandsecondplayer.
analogWrite(red1,bright[0])
analogWrite(green1,bright[1])
analogWrite(blue1,bright[2])

analogWrite(red2,bright[3])
analogWrite(green2,bright[4])
analogWrite(blue2,bright[5])
delay(time)

Finallywritetheresultoutaccordingtothesituations,matchingeachlightwitheach
brightnessvalue.Delaythewholeprocessforaspecifictimedecidedbythevalueof
potentiometre.

Reference

Chris,W
.
(2004,Aug11).DiodesandLEDs.Retrievedfrom
http://www.explainthatstuff.com/diodes.html

Adafruit.
DiffusedRGB(tricolor)LEDCommonAnode
productdescription.

Retrievedfrom
http://www.adafruit.com/products/159

ebay.(
2015,Apr22).
100x5mm4pinRGBTriColorDiffusedCommonCathodeLED
LampEmittingDiod.Retrievedfrom
http://www.ebay.com/itm/100x5mm4pinRGBTriColorDiffusedCommonCathodeL
EDLampEmittingDiode/370946258804
Sarah,L.(2013,Sep13).
TheApplicationofLEDTechnologyinDailyLife.Retrievedfrom

http://www.lightingever.com/blog/theapplicationofledtechnologyindailylife/

You might also like