What am I doing wrong here? I'm not getting any values of power.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7);
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
//voltage variables
int sensorValue = 0;
double voltage = 0;
int voltagepin = A0;
//current variables
double current = 0;
int currentpin = A1;
//power reading variables
double power = 0;
int V = 0;
int C = 0;
void Voltage();
void Current();
void Power();
void setup() {
// put your setup code here, to run once:
lcd.begin(20,4);
lcd.setBacklightPin(3, POSITIVE);
//LCD backlight
lcd.setBacklight(HIGH);
Serial.begin(9600);
emon1.current(currentpin, 111.1);// Current: input pin, calibration.
lcd.home();
lcd.setCursor(7,1);
lcd.print("Power");
lcd.setCursor(4,2);
lcd.print("Measurement");
delay(5000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
Voltage();
Current();
Power();
}
void Power(){
V = voltage;
C = current;
power = V * C;
lcd.setCursor(7,2);
lcd.print(power);
lcd.setCursor(7,3);
lcd.print("Watts");
//delay(1000);
}
void Voltage(){
// read the input on analog pin 0:
int sensorValue = analogRead(voltagepin);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 250V):
float voltage = (sensorValue * (220.0 / 1024.0)) + 0.2;
// print out the value you read:
//lcd.clear();
lcd.home();
//lcd.print("AC Voltage: ");
Serial.print("AC Voltage: ");
//lcd.setCursor(0,1);
lcd.print(voltage);
Serial.print(voltage);
lcd.setCursor(0,1);
lcd.print("Volts");
Serial.println(" Volts");
//delay(500);
}
void Current(){
current = emon1.calcIrms(1480); // Calculate Irms only
//Serial.print(Irms*230.0); // Apparent power
//Serial.print(" ");
//lcd.home();
//lcd.print("AC Current: ");
lcd.setCursor(14,0);
lcd.print(current);
lcd.setCursor(14,1);
lcd.print(" Amps");
Serial.print("AC Current: ");
Serial.print(current);// Irms
Serial.println("Amps");
//delay(500);
}