arduino voltmeter 827 Bytes
Newer Older
Arlo's avatar
Arlo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int analogInput = 1;
float Vout = 0.00;
float Vin = 0.00;
float I = 0.00;
float R1 = 98000.00; // resistance of R1 (100K) 
float R2 = 9880.00; // resistance of R2 (10K) 
int val = 0;
void setup(){
   pinMode(analogInput, INPUT); //assigning the input port
   Serial.begin(9600); //BaudRate
}
void loop(){
   
   val = analogRead(analogInput);//reads the analog input
   Vout = (val * 5.11) / 1024.00; // formula for calculating voltage out i.e. V+, here 5.00
   Vin = Vout / (R2/(R1+R2)); // formula for calculating voltage in i.e. GND
   I = Vin/(R2/(R1+R2));
   //if (Vin<0.09)//condition 
   {
     //Vin=0.00;//statement to quash undesired reading !
  } 
Serial.print("\t V = ");
Serial.print(Vin);
Serial.print("\t I = ");
Serial.print(I);
Arlo's avatar
Arlo committed
26
delay(2000); //for maintaining the speed of the output in serial moniter, in ms 
Arlo's avatar
Arlo committed
27
}