/* Voltmeter Voltmeter base on voltage divider concept. Code based on: http://www.clarenceho.net:8123/blog/articles/2009/05/17/arduino-test-voltmeter Coded by: arduinoprojects101.com */ // include the library code: #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(P2_4, P2_3, P1_5, P1_4, P1_3, P1_2); // variables for input pin and control LED int analogInput = 1; float vout = 0.0; float vin = 0.0; float R1 = 50000.0; // !! resistance of R1 !! float R2 = 4400.0; // !! resistance of R2 !! // variable to store the value int value = 0; void setup(){ lcd.begin(16, 2); lcd.print("MSP430 voltmeter"); lcd.setCursor(1, 1); // set cursor location on LCD lcd.print("by Mybuster"); delay(4000); // declaration of pin modes pinMode(analogInput, INPUT); // set up the LCD's number of columns and rows: lcd.begin(16, 2); lcd.print("Vin="); lcd.setCursor(0, 1); // set cursor location on LCD lcd.print("measured voltage"); } void loop(){ // read the value on analog input value = analogRead (analogInput); vout = (value * 5.0) / 1024.0; vin = vout / (R2/(R1+R2)); // print result to lcd display lcd.setCursor(4, 0); lcd.print(vin); lcd.print("V"); // sleep... delay(500); }