Things used in this project

Hardware components:
09590 01
LED (generic)
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1
Mfr 25fbf52 221r sml
Resistor 221 ohm
×1
11026 02
Jumper wires (generic)
×1
09939 01
Rotary potentiometer (generic)
×1
Software apps and online services:
Ide web
Arduino IDE

Schematics

Bar Graph
Bargraph bb mfhm8kyoal

Code

GraphC/C++
const int analogPin = A0;   // the pin that the potentiometer is attached to
const int ledCount = 10;    // the number of LEDs in the bar graph

int ledPins[] = {
  2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};   // 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);
    }
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW);
    }
  }
}

Credits

Arduino icon 2 oz4hdh5f0y
Tudose Matei

I'm a beginner and I love Arduino ! I discovered hardware and software at academy "inventeaza.ro" . This academy is brilliant !

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Grove starter kit for arduino - piezo vibration sensor
Easy
  • 117
  • 4

Protip

teaches you how to use the piezo vibration sensor in the Arduino Grove starter kit.

Happy birthday melody on Arduino Nano with 3-way polyphony
Easy
  • 1,138
  • 19

Full instructions

Playing polyphony Happy birthday theme on Arduino Nano with three buzzers on a single mini breadboard.

Kaleidoscope Infinity Mirror
Easy
  • 2,012
  • 25

Full instructions

Build a beautiful “infinity mirror” Illusion that you can control by changing this mirrors' orientation. Rotate for changing colors!

Weekly Scheduling with Arduino UNO
Easy
  • 1,081
  • 19

Protip

Human habits are usually different between weekdays and weekend. Therefore, smart devices should be able to switch their task based on this.

Measuring seismic activity using ProtoCentral OpenPressure
Easy
  • 23
  • 1

Protip

Seismic activity or "Vibrations of the earth" is measured using ProtoCentral's OpenPressure 24-bit DAQ System

ProjectsCommunitiesContestsLiveJobsBetaFree StoreBlogAdd projectSign up / Login
Respect project