#include <LiquidCrystal.h>
const int voltagePin = A0; // Analog pin for voltage measurement
const int currentPin = A1; // Analog pin for current measurement
const int resistorPin = A2;
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// Set up the number of columns and rows on the LCD
Serial.begin(9600);
lcd.begin(15, 2);
}
void loop() {
float voltage = analogRead(voltagePin) * (5.0 / 1023.0); // Convert ADC value to voltage
float current = analogRead(currentPin) * (5.0 / 1023.0); // Convert ADC value to current
float resistor = analogRead(resistorPin) * (5.0 / 1023.0);
// Power factor calculation
float powerFactor =((current * current )* resistor) / (voltage * current);
// Display power factor on LCD
lcd.clear();
lcd.print("Power Factor:");
Serial.print("Power Factor: ");
Serial.println(powerFactor);
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.print(" V, Current: ");
Serial.print(current);
if (powerFactor >= 0.0 && powerFactor <= 0.3) {
lcd.setCursor(0, 3);
lcd.print("Bad PF: Improve");
}
else if (powerFactor > 0.3 && powerFactor <= 0.7) {
lcd.setCursor(0, 3);
lcd.print("Good PF: Optimize");
}
else if (powerFactor > 0.7 && powerFactor <= 1.0) {
lcd.setCursor(0, 3);
lcd.print("Excellent PF!");
}
else if (powerFactor >1){
lcd.print("overload");
lcd.setCursor(0, 3);
}
delay(2000); // Delay for stability
}