Monday, December 15, 2014

ARDUINO 0-5 V Voltmeter

ARDUINO 0-5 V Voltmeter
Using the equipped analog to digital converter with Arduino uno board we can make a 0-5v voltmeter and display it in a 4 digit 7 segment display.
Arduino voltmeter 7 segment
ARDUINO 0-5 V voltmeter code:
const unsigned char srdata=2, srclk=3, digit4=4, digit3=5, digit2=6, digit1=7;
unsigned int i = 0;
float j = 0;
unsigned char d=0,k=0,l=0,m=0,n=0,s=0;

int seg (){
  if (k==0) l=64;
  if (k==1) l=121;
  if (k==2) l=36;
  if (k==3) l=48;
  if (k==4) l=25;
  if (k==5) l=18;
  if (k==6) l=2;
  if (k==7) l=120;
  if (k==8) l=0;
  if (k==9) l=16;
  return k;
}

void setup() {
  pinMode(srdata, OUTPUT);
  pinMode(srclk, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit1, OUTPUT);
    }

void loop(){
  j = analogRead(A0);
  i = j*5000/1023;
   if(d==0) {digitalWrite(digit4,LOW); digitalWrite(digit3,HIGH);
             digitalWrite(digit2,HIGH);digitalWrite(digit1,HIGH);
 k=i%10;
 seg();
 n=0;
 for(m=0;m<7;m++){
   digitalWrite (srdata,bitRead(l,n));
   digitalWrite (srclk,1);
   digitalWrite (srclk,0);n++;
   }delay(4);
   d=1;
 }
 
 if(d==1) {digitalWrite(digit4,HIGH); digitalWrite(digit3,LOW);
           digitalWrite(digit2,HIGH);digitalWrite(digit1,HIGH);
 k=(i/10)%10;
 seg();
 n=0;
 for(int m=0;m<7;m++){
   digitalWrite (srdata,bitRead(l,n));
   digitalWrite (srclk,1);
   digitalWrite (srclk,0);n++;
   }delay(4);d=2;
 }
 
 if(d==2) {digitalWrite(digit4,HIGH); digitalWrite(digit3,HIGH);
             digitalWrite(digit2,LOW);digitalWrite(digit1,HIGH);
 k=(i/100)%10;
 seg();
 n=0;
 for(int m=0;m<7;m++){
   digitalWrite (srdata,bitRead(l,n));
   digitalWrite (srclk,1);
   digitalWrite (srclk,0);n++;
   }delay(4);d=3;
 }
 
 if(d==3) {digitalWrite(digit4,HIGH); digitalWrite(digit3,HIGH);
            digitalWrite(digit2,HIGH);digitalWrite(digit1,LOW);
 k=(i/1000)%10;
 seg();
 n=0;
 for(int m=0;m<7;m++){
   digitalWrite (srdata,bitRead(l,n));
   digitalWrite (srclk,1);
   digitalWrite (srclk,0);n++;
   }delay(4);d=0;
 }
}