int sensorpin = A0; // input pin for power (positive)
int sensorValue = 0; // variable to store the value coming from the sensor
double Vout; // voltage output
double i; // amps (current)
double p; // watts
double r1 = 7.5;
double r2 = 5.0;
double r = 12.5; // resistance value (ohms) 7.5k and 5k resistor
double c = 204.8; // constant value divider (1024 / 5) to get correct ratio. Analog pin reads up to 5v in 1024 increments.
#include <LiquidCrystal.h> // include the library code
LiquidCrystal lcd(12, 11, 8, 7, 4, 2); // numbers of the interface pins, more space between pins compared to last code
void setup() {
lcd.begin(20, 4); // sets up the LcD's number of columns and rows:
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
}
void loop() {
sensorValue = analogRead(A0); // read the value from the sensor:
Vout=(sensorValue/c) * (r2/r); //vout = vin(Divided by c to scale down to 5v) * r2/(r1+r2)
i=Vout/r; // current = V/r
p=Vout*Vout/r; // power = (V^2)/r
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Amps= ");
lcd.print(i);
lcd.setCursor(0, 1);
lcd.print("Volts= ");
lcd.print(Vout);
lcd.setCursor(0, 2);
lcd.print("Watts= ");
lcd.print(p);
lcd.setCursor(0, 3);
lcd.print("SensorValue= ");
lcd.print(analogRead(A0));
delay(500); // delay in between reads for stability
}