Arduino UNO processes analog input value data (ADC) at A0 pin, then the result is displayed in bargraph form on LED. The analog data is can adjustable by using potentiometer.
Hardware Requirement
- 10 LED
- Arduino UNO
- Power supply +5 Volt
- Potentiometer as voltage divider
LED | Source
Schematic
Source Code/Sketch
const int ledCount = 10;
int adc0;
int ledPins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};
void setup() {
for (int Led = 0; Led < ledCount; Led++) {
pinMode(ledPins[Led], OUTPUT);
}
}
void loop() {
adc0 = analogRead(A0);
int ledLevel = map(adc0, 0, 1023, 0, ledCount);
for (int Led = 0; Led < ledCount; Led++) {
if (Led < ledLevel) {
digitalWrite(ledPins[Led], LOW);
}
else {
digitalWrite(ledPins[Led], HIGH);
}
}
}
int adc0;
int ledPins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};
void setup() {
for (int Led = 0; Led < ledCount; Led++) {
pinMode(ledPins[Led], OUTPUT);
}
}
void loop() {
adc0 = analogRead(A0);
int ledLevel = map(adc0, 0, 1023, 0, ledCount);
for (int Led = 0; Led < ledCount; Led++) {
if (Led < ledLevel) {
digitalWrite(ledPins[Led], LOW);
}
else {
digitalWrite(ledPins[Led], HIGH);
}
}
}
How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
4. Rotate the the potentiometer that connected to ADC0.
5. Focus on the LED, LED will light up like bargraph according to the input voltage
6. The maximum voltage (5 V), if it's reach then 10 LEDs on the LED bargraph will flame all.
Video for Project II - 20. Analog Input wiith Bar Graph LED (Arduino Uno Based)
Download the required file.
No comments:
Post a Comment