// include the library code:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
float R1 = 1;
float R2 = 1;
int via = 0;
float vi, vo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(" ");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void voltage() {
// via = Serial.read();
// via=analogRead(A5); //Input Analog Voltage
via = 512;
vi = map(via, 0,1023, 0,500) / 100.0; //Input Voltage
// float viaf = via * 0.01;
// float vi=(5*viaf)/1023; //Voltage
vo=((R1+R2)/R2)*vi;
Serial.println(vi);
Serial.print(vo);
Serial.println(" V");
}
void display() {
/*
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print(vo);
lcd.print(" V");
}
void loop() {
// put your main code here, to run repeatedly:
voltage();
display();
delay(1000);
}