Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
MarioYellow
Published © GPL3+

LED Indicator with Potentiometer!

A simple indicator that uses a potentiometer and LEDs.

BeginnerFull instructions provided831
LED Indicator with Potentiometer!

Things used in this project

Hardware components

5 mm LED: Red
5 mm LED: Red
Can be any other color, unsure about the diameter
×6
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
I used this potentiometer (specifically the one in the Starter Kit), I'm not sure if other potentiometers work as well
×1
Resistor 220 ohm
Resistor 220 ohm
×6

Story

Read more

Schematics

Wiring on a breadboard

Code

Coding (written for an Arduino Uno)

Arduino
const int potPin = A0;
int potVal = 0;
int led = 0;

void setup() {
  Serial.begin(9600);
  for(int x = 2; x < 8; x++){
    pinMode(x, OUTPUT);
  }
  pinMode(potPin, INPUT);
}

void loop() {
  potVal = analogRead(potPin);
  Serial.print(potVal);
  led = map(potVal, 0, 1023, 0, 6);
  Serial.print(" ");
  Serial.println(led);
  if(led == 0){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
  }
  if(led == 1){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
    digitalWrite(2, HIGH);
  }
  if(led == 2){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
    for(int x = 2; x < 4; X++){
      digitalWrite(x, HIGH);
    }
  }
  if(led == 3){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
    for(int x = 2; x < 5; X++){
      digitalWrite(x, HIGH);
    }
  }
  if(led == 4){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
    for(int x = 2; x < 6; X++){
      digitalWrite(x, HIGH);
    }
  }
  if(led == 5){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
    for(int x = 2; x < 7; X++){
      digitalWrite(x, HIGH);
    }
  }
  if(led == 6){
    for(int x = 2; x < 8; x++){
      digitalWrite(x, LOW);
    }
    for(int x = 2; x < 8; x++){
      digitalWrite(x, HIGH);
    }
  }
}

Credits

MarioYellow

MarioYellow

0 projects • 0 followers

Comments