Sistem kerja alat ini adalah menghitung jumlah masukan maupun pengeluaran data. Data masukan diperoleh dari penekanan tombol UP, sedangkan tombol DOWN digunkan untuk pengurangan data counter.
Alat ini terdiri dari Arduino UNO sebagai sistem pemroses & pengendali utama dari sistem. Tombol Up sebagai penamabah jumlah data counter sedangkan tombol DOWN untuk mengurangi isi counter. Sedangkan 7-Segment digunakan untuk display counter.
Kebutuhan Hardware
- Modul 7-segment 4 digit (Common Anoda)
- 3 Tombol push ON
- Modul Arduino UNO
- Power supply +5Volt
7-Segment | Source
Diagram Blok
Schematic
Koneksi Arduino UNO dengan 7-Segment
Source Code/Sketch
unsigned int count;
int segA = 2;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = 6;
int segF = 7;
int segG = 8;
int dig1 = 9;
int dig2 = 10;
int dig3 = 11;
int dig4 = 12;
void setup() {
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
digitalWrite(A2,1);
}
void loop() {
char seg1 = int(count)/1000;
char seg2 = (int(count)%1000)/100;
char seg3 = (int(count)%100)/10;
char seg4 = (int(count)%100)%10;
if (count < 10){
seg1=10;
seg2=10;
seg3=10;
}
else if (count < 100){
seg1=10;
seg2=10;
}
else if (count < 1000){
seg1=10;
}
digitalWrite(12,1);
digitalWrite(9,0);
displaySeg(seg1);
delay(5);
digitalWrite(9,1);
digitalWrite(10,0);
displaySeg(seg2);
delay(5);
digitalWrite(10,1);
digitalWrite(11,0);
displaySeg(seg3);
delay(5);
digitalWrite(11,1);
digitalWrite(12,0);
displaySeg(seg4);
delay(5);
if (digitalRead(A0)==0 && count < 9999){
count++;
delay(200);
}
else if(digitalRead(A1)==0 && count != 0){
count--;
delay(200);
}
else if(digitalRead(A2)==0){
count=0;
}
}
void displaySeg(char segment){
switch (segment){
case 0: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,1);
break;
case 1: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 2: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,1);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 3: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 4: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 5: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 6: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 7: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 8: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 9: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 10: digitalWrite(segA,1);
digitalWrite(segB,1);
digitalWrite(segC,1);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
}
}
int segA = 2;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = 6;
int segF = 7;
int segG = 8;
int dig1 = 9;
int dig2 = 10;
int dig3 = 11;
int dig4 = 12;
void setup() {
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
digitalWrite(A2,1);
}
void loop() {
char seg1 = int(count)/1000;
char seg2 = (int(count)%1000)/100;
char seg3 = (int(count)%100)/10;
char seg4 = (int(count)%100)%10;
if (count < 10){
seg1=10;
seg2=10;
seg3=10;
}
else if (count < 100){
seg1=10;
seg2=10;
}
else if (count < 1000){
seg1=10;
}
digitalWrite(12,1);
digitalWrite(9,0);
displaySeg(seg1);
delay(5);
digitalWrite(9,1);
digitalWrite(10,0);
displaySeg(seg2);
delay(5);
digitalWrite(10,1);
digitalWrite(11,0);
displaySeg(seg3);
delay(5);
digitalWrite(11,1);
digitalWrite(12,0);
displaySeg(seg4);
delay(5);
if (digitalRead(A0)==0 && count < 9999){
count++;
delay(200);
}
else if(digitalRead(A1)==0 && count != 0){
count--;
delay(200);
}
else if(digitalRead(A2)==0){
count=0;
}
}
void displaySeg(char segment){
switch (segment){
case 0: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,1);
break;
case 1: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 2: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,1);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 3: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 4: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 5: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 6: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 7: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 8: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 9: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 10: digitalWrite(segA,1);
digitalWrite(segB,1);
digitalWrite(segC,1);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
}
}
Jalannya Alat
1. Tampilan pertama pada 7 segment, menampilkan angka 0
2. Silahkan tekan tombol UP, sehingga counter menghitung jumlah penekanan tombol, dan hasilnya ditampilkan pada seven segment
4. Berikutnya tombol RESET digunakan untuk meng-nol-kan kembali isi counter.
Video untuk Proyek I - 2. Counter dengan 4 Digit 7-Segment berbasis Arduino
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment