Halaman

Rabu, 13 September 2017

voltage monitor pakai arduino dan seven segment

Bikin voltage monitor pakai arduino ama seven segment meski cuma ampe 5 volt doang...(ngapain coba mahal2 bikin pake ini??) Maklum justru lagi ada yang nganggur kagak kudu beli sepeser pun.


kodenya nih.

/*
Read me

Use all this information at your own risk, i hold no responsibility for any and all indirect or dicrect damage to your arduino, hardware and software of your pc, any electronic devices if you choose to use this information.

This meter only can measure up to 5V

This meter cannot measure negative voltage and make sure you connect the probes to the battery in the correct way (red probe(A0) to the positive side of the battery and black probe(GND) to the negative side of the battery)

*/
int a=13;
int b=12;
int c=11;
int d=10;
int e=9;
int f=8;
int g=7;
int deci = 3;
int gnd1=6;
int gnd2=5;
int gnd3=4;
int inp=A0;

float Reading;
int OneDigit, TenDigit, HundredDigit;

void mask(int num, int aa, int bb, int cc, int dd, int ee, int ff, int gg) 

switch (num) 

case 0 :
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, HIGH);
digitalWrite(ee, HIGH);
digitalWrite(ff, HIGH);
digitalWrite(gg, LOW);
break;

case 1 : 
digitalWrite(aa, LOW);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, LOW);
digitalWrite(ee, LOW);
digitalWrite(ff, LOW);
digitalWrite(gg, LOW);
break;

case 2 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, LOW);
digitalWrite(dd, HIGH);
digitalWrite(ee, HIGH);
digitalWrite(ff, LOW);
digitalWrite(gg, HIGH);
break;

case 3 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, HIGH);
digitalWrite(ee, LOW);
digitalWrite(ff, LOW);
digitalWrite(gg, HIGH);
break;

case 4 : 
digitalWrite(aa, LOW);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, LOW);
digitalWrite(ee, LOW);
digitalWrite(ff, HIGH);
digitalWrite(gg, HIGH);
break;

case 5 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, LOW);
digitalWrite(cc, HIGH);
digitalWrite(dd, HIGH);
digitalWrite(ee, LOW);
digitalWrite(ff, HIGH);
digitalWrite(gg, HIGH);
break;

case 6 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, LOW);
digitalWrite(cc, HIGH);
digitalWrite(dd, HIGH);
digitalWrite(ee, HIGH);
digitalWrite(ff, HIGH);
digitalWrite(gg, HIGH);
break;

case 7 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, LOW);
digitalWrite(ee, LOW);
digitalWrite(ff, LOW);
digitalWrite(gg, LOW);
break;

case 8 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, HIGH);
digitalWrite(ee, HIGH);
digitalWrite(ff, HIGH);
digitalWrite(gg, HIGH);
break;

case 9 : 
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, HIGH);
digitalWrite(ee, LOW);
digitalWrite(ff, HIGH);
digitalWrite(gg, HIGH);
break;

}
}

void setup()
{
 pinMode(a,OUTPUT);
 pinMode(b,OUTPUT);
 pinMode(c,OUTPUT);
 pinMode(d,OUTPUT);
 pinMode(e,OUTPUT);
 pinMode(f,OUTPUT);
 pinMode(g,OUTPUT);
 pinMode(deci,OUTPUT); 
 pinMode(gnd1,OUTPUT);
 pinMode(gnd2, OUTPUT);
 pinMode(gnd3, OUTPUT);
 pinMode(inp, INPUT); 
 digitalWrite(deci, HIGH);
}

void loop ()
{
  float TempOneDigit;
  int i;
Reading = (analogRead(inp)*5.00/1023.00);
HundredDigit = int(Reading) % 10;
TenDigit = int ((Reading-HundredDigit )*10) % 10;
TempOneDigit = int(Reading * 10);
OneDigit = int ((Reading - float(TempOneDigit/10))* 100) %10;

for (i=0 ; i<20 ; i++) {
mask (OneDigit, a, b, c, d, e, f, g);
digitalWrite(gnd3,LOW);
digitalWrite(gnd2, HIGH);
digitalWrite(gnd1, HIGH);
delay(5);
mask (TenDigit, a, b, c, d, e, f ,g);
digitalWrite(gnd3,HIGH);
digitalWrite(gnd2, LOW);
digitalWrite(gnd1, HIGH);
delay(5);
mask (HundredDigit, a, b, c, d, e, f ,g);
digitalWrite(gnd3,HIGH);
digitalWrite(gnd2, HIGH);
digitalWrite(gnd1, LOW);
delay(5);

}

}

##sumber http://forum.arduino.cc/index.php?topic=233532.msg1681606#msg1681606



Tidak ada komentar:

Posting Komentar