Skip to content

Instantly share code, notes, and snippets.

@padillla
Created February 2, 2015 03:15
Show Gist options
  • Save padillla/e1c0fc02f19e4ea327fa to your computer and use it in GitHub Desktop.
Save padillla/e1c0fc02f19e4ea327fa to your computer and use it in GitHub Desktop.
Arduino serial DC Voltmeter.
/*
DC Voltmeter
Based on Arduino DVM based on voltage divider concept
T.K.Hareendran
*/
int voltsInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K)
float R2 = 10000.0; // resistance of R2 (10K)
int value = 0;
void setup(){
pinMode(voltsInput, INPUT);
Serial.begin(9600);
Serial.println("DC VOLTMETER");
}
void loop(){
// read the value at analog input
value = analogRead(voltsInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) {
vin=0.0;//statement to quash undesired reading !
}
Serial.println("INPUT V= ");
Serial.println(vin);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment