Sistem Kerja Alat
Arduino UNO membaca nilai analog input di A0 kemudian hasilnya ditampilkan dalam bentuk bargraph di LED.
Kebutuhan Hardware
- Arduino UNO Board
- Potensiometer sebagai voltage divider
- Modul LED bargraph (10 LED)
- Power Supply 7-9 Vdc
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);
}
}
}
Jalannya Alat
Putar potensio yang terhubung ke ADC0 dan perhatikan LED bargraph akan nyala sesuai dengan tegangan yang masuk ke ADC0. Jika tegangan maksimal (5 V) maka 10 LED pada LED bargraph akan nyala semua.
Video Project II - 20. Analog Input dengan LED Bar Graph berbasis Arduino Uno
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment