Arduino - LED Bar Graph

Arduino - LED Bar Graph



Arduino - LED Bar Graph


OVERVIEW


This example shows you how to read an analog input at analog pin 0, convert the values from analogRead() into voltage, and print it out to the serial monitor of the Arduino Software (IDE).

Components Required

You will need the following components −

  • 1 × Breadboard
  • 1 × Arduino Uno R3
  • 1 × 5k ohm variable resistor (potentiometer)
  • 2 × Jumper
  • 8 × LED or you can use (LED bar graph display as shown in the image below)

Procedure

Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below.

Bar BreadboardConnection to Bar Breadboard

Sketch

Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New.

Sketch

10 Segment LED Bar Graph

LED Bar Graph

These 10-segment bar graph LEDs have many uses. With a compact footprint, simple hookup, they are easy for prototype or finished products. Essentially, they are 10 individual blue LEDs housed together, each with an individual anode and cathode connection.

They are also available in yellow, red, and green colors.

Note − The pin out on these bar graphs may vary from what is listed on the datasheet. Rotating the device 180 degrees will correct the change, making pin 11 the first pin in line.

Arduino Code

/*     LED bar graph     Turns on a series of LEDs based on the value of an analog sensor.      This is a simple way to make a bar graph display.      Though this graph uses 8LEDs, you can use any number by        changing the LED count and the pins in the array.     This method can be used to control any series of digital        outputs that depends on an analog input.  */    
// these constants won't change:  
const int analogPin = A0; // the pin that the potentiometer is attached to  const int ledCount = 8; // the number of LEDs in the bar graph  int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // an array of pin numbers to which LEDs are attached    

void setup() {
     // loop over the pin array and set them all to output:     
	 for (int thisLed = 0; thisLed < ledCount; thisLed++) {        pinMode(ledPins[thisLed], OUTPUT);     
	 }  
	 }    
	 void loop() {
	      // read the potentiometer:     
		  int sensorReading = analogRead(analogPin);     
		  // map the result to a range from 0 to the number of LEDs:     
		  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);     
		  // loop over the LED array:     
		  for (int thisLed = 0; thisLed < ledCount; thisLed++) {        
		  // if the array element's index is less than ledLevel,        
		  // turn the pin for this element on:        
		  if (thisLed < ledLevel) {           
		  digitalWrite(ledPins[thisLed], HIGH);        
		  }else { // turn off all pins higher than the ledLevel:           
		  digitalWrite(ledPins[thisLed], LOW);        
		  }
	}
} 

Code to Note

The sketch works like this: first, you read the input. You map the input value to the output range, in this case ten LEDs. Then you set up a for-loop to iterate over the outputs. If the output's number in the series is lower than the mapped input range, you turn it on. If not, you turn it off.

Result

You will see the LED turn ON one by one when the value of analog reading increases and turn OFF one by one while the reading is decreasing.

Comments

ApbSwarge
AUTsanlilm
nslsgqWracy
Angelspeypt
Stevenneire
eninemaqivob
abetokoqifasa
ucozbaduvi
obopehu
ofeyoavi
uhiqoxo
oguravoxe
oseqahamikaja
otuumusonik
idefitoge
iomemnulade
enireavujlim
ozewaqg
epesurulorolu
amahove
NathanCaX
eluyoira
etakedomu
ihecotazxeyi
isiviatpobi
oxetojabecidi
oyoqupowupiwa
JamieCrymn
JamieCrymn
Donaldfew
Donaldfew
Arthurdript
DonaldReund
DonaldReund
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
KennethWet
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
WilliamRom
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
DonaldReund
DonaldReund
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
DonaldReund
DonaldReund
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
DonaldReund
Haroldfrini
DonaldReund
Haroldfrini
DonaldReund
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
DonaldReund
DonaldReund
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
Haroldfrini
Jacobquaft
Jacobquaft
Haroldfrini
Haroldfrini
Jacobquaft
Jacobquaft
Matthewneato
Matthewneato
Matthewneato
Matthewneato
Jacobquaft
Jacobquaft
Matthewneato
Matthewneato
Jacobquaft
Jacobquaft
Josephsut
Jacobquaft
Josephsut
Jacobquaft
Josephsut
Jacobquaft
Josephsut
Jacobquaft
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Jacobquaft
Jacobquaft
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Jacobquaft
Jacobquaft
Josephsut
Josephsut
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
Josephsut
JeremyKaf
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
JeremyKaf
Josephsut
JeremyKaf
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
JeremyKaf
JeremyKaf
Josephsut
Josephsut
JeremyKaf
JeremyKaf
Martindob
Josephsut
Josephsut
Josephsut
Josephsut
Josephnal
Josephnal
Josephsut
Josephsut
Josephnal
Josephnal
Josephsut
Josephsut
Josephnal
Josephnal
Josephsut
Josephsut
Josephnal
Josephnal
Josephnal
Josephnal
SheltonCow
SheltonCow
SheltonCow
Josephnal
SheltonCow
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
Josephnal
SheltonCow
Josephnal
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
SheltonCow
SheltonCow
Josephnal
Josephnal
Josephnal
SheltonCow
SheltonCow
SheltonCow
SheltonCow
Haroldnof
Haroldnof
DavidPed
Haroldnof
DavidPed
Haroldnof
Haroldnof
DavidPed
Haroldnof
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
Haroldnof
DavidPed
Haroldnof
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
Haroldnof
DavidPed
Haroldnof
DavidPed
Haroldnof
Haroldnof
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
DavidPed
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Williammef
Frankfitle
Frankfitle
Frankfitle
Frankfitle
Frankfitle
Frankfitle
Frankfitle
Frankfitle
DavidBib
Frankfitle
Frankfitle
ThomasAnots
Jamesglync
ScottloN
MichaelGrarm
SusanSex
CraigOwnef
Servicepiy
DianeOblix
Justinphymn
Jamesinfap
Viktoraffon
Alfredikgaw
MelissaRit
DanielheS
MichaelGrarm
EssaeeyKab
CoreyUtera
Ddarlyltor
Michaellog
ThomasLoure
AnnaFrolova
Alberthow
DanielheS
Trentexhig
Georgeinhab
Jamesevads
ThomasLoure
ThomasLoure
Racyrom
Alexmop
Jamesbilia
Taksi77Bic
gelenlKAL
MaxAvticr
ThomasLoure
Josephabnop
Ralphanist
CalvinCof
Gregorysib
ElmerWah
Raymondrag
Irbosnat
ThomasLoure
ManuelDic
Dustinwrile
AmmayAtompitte
SonjaRoure
Cecilblarp
Ralphanist
Calvinkilia
Blago93Oi
Richardsoofs
JamesCheep
RichardSlump
Justinmeela
Williamblurb
HenryDourf
Merbertmof
SEOFleef
Tylerhag
Haroldnilla
CharlesHAT
MichaelDatty
MichaelDatty
MichaelDatty
Charlesunuri
SonjaRoure
JosephWeake
Dennisjoisp
Charlesunuri
Jamestroli
LouiseViowl
LindseyKt
LindseyKt
Sheilapex
MichaelDatty
MichaelDatty
MichaelDatty
SonjaRoure
JeremyOreva
Get A Loan
MarcusBib
Pay Day Loan
Speedycash
bakuninaThops
DenGurcaupe
AnnaFrolova
DavidTHIFF
LolaPraste
RobertJum
LiftekKit
rosievh18
Stephenmet
Speedycash
advokatbup
ScottyTex
HelenassoP
SormatsZ
HelenassoP
HelenassoP
tammibz2
SormatsZ
Bernardlooky
caseyeh69
LowellDus
Dannyvlw
evangelinewl60
Normanruism
DerekSkews
HelenassoP
HelenassoP
EverlFax
HelenassoP
DianeSam
HelenassoP
HelenassoP
AllanquOrm
HelenassoP
HelenassoP
HelenassoP
HelenassoP
HelenassoP
HelenassoP
HelenassoP
HelenassoP
HelenassoP
HelenassoP
WarzenBleda
IsrafacePag
Daniilvon
Alyasoofs
RobertJum
Get A Loan
bruibiaStata
bruibiaStata
bruibiaStata
Dannysoz
Payday Loan
drokendalkNamn
drokendalkNamn
drokendalkNamn
Danielwouth
Payday Loan
bruibiaStata
drokendalkNamn
drokendalkNamn
IgnatriP
HelenDow
NormanTip
DerekSkews
Canadmanst
Stephenmet
Nikeadown
JasonCob
Justnikebit
MichaelTOk
el0umb5r
RobertJum
KennethGeobe
vernonvm11
Michaelhoade
joniyb18
IlyacaT
Michaelhoade
Abakbakocex
RobertAccog
Rustydroto
Bogdankbe
Stephenmus
Rudolphwhove
TimothyWeert
Bogdankbe
CkarboGurce
Nikeadown
Bogdankbe
Rustydroto
TimothyWeert
Abakbakocex
IsrafacePag
Abakbakocex
DorrisDat
Rustydroto
patricaek1
Pavloskin
corneliapm60
Pavloskin
DorrisDat
forum_y0472
Pavloskin
Pavloskin
KINO ONLINE
Pavloskin
Pavloskin
RobertJum
Pavloskin
Pavloskin
Nikeadown
Justnikebit
Dgeksututedy
LeonidImpof
tameraeq60
KINO ONLINE
KINO ONLINE
SEOFleef
MakarDeday
AllanquOrm
Pavloskin
Markfeeft
KarinaSaP
Pavloskin
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
paulettejt18
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
Michaelvenmus
WilliamggLog
WilliamggLog
Pavloskin
WilliamggLog
WilliamggLog
albertoop11
WilliamggLog
WilliamggLog
WilliamggLog
WilliamggLog
Rysrueswam
WilliamggLog
agrohimars
WilliamggLog
Helenaggd
WilliamggLog
Payday
WilliamggLog
WilliamggLog
WilliamggLog
agrohimars
WilliamggLog
Nikitadrave
WilliamggLog
WilliamggLog
WilliamggLog
agrohimars
Beverlyabarp
WilliamggLog
WilliamggLog
Helenaggd
Nikolaytaini
andreamy16
agrohimars
agrohimars
Olegsow
agrohimars
agrohimars
AaykiFlapy
Loan
Beverlyabarp
SpencerLance
Hurtepreine
Seobortru
Michaellog
Richardirrap
agrohimars
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
RobertJum
WilliamruLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
AlenaThevy
WilliamggLog
WilliamruLog
WilliamruLog
WilliamggLog
agrohimars
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
DermanJaw
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
agrohimars
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
Victoragemy
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamruLog
agrohimars
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
agrohimars
WilliamggLog
WilliamruLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
Anthonyimper
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
WilliamggLog
WilliamruLog
michellegc1
WilliamruLog
WilliamggLog