TechnicalEngineer
Published © GPL3+

Arduino Based Wattmeter

When we connect this wattmeter to a device which is in operation, the 16*2 LCD displays its power consumption value in Watts.

IntermediateFull instructions provided2,599
Arduino Based Wattmeter

Story

Read more

Schematics

Arduino based Wattmeter

Code

Arduino based Wattmeter

C/C++
// include the library code:

#include <LiquidCrystal.h>

 

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 

int adc_value = 0;

int voltage_peak_value = 0;

float voltage_average_value = 0;

float dc_voltage_V0 = 0;

float ac_voltage_V0 = 0;

float dc_voltage_V1 = 0;

float ac_voltage_V1 = 0;

float dc_current_I0 = 0;

float ac_current_I0 = 0;

float dc_power = 0;

float ac_power = 0;

unsigned long resistance;

unsigned long sample_count = 0;

 

void setup()

{

  // set up the LCD's number of columns and rows:

  lcd.begin(16, 2);

  // Print a message to the LCD.

  lcd.print("    EG LABS    ");

  pinMode(13, OUTPUT);

}

 

void loop()

{

 

//  Serial.println("=============================== VOLTAGE ========================================");

 

  voltage_peak_value = 0;

  for(sample_count = 0; sample_count < 5000; sample_count ++)

  {

      adc_value = analogRead(A0);

      if(voltage_peak_value < adc_value)

          voltage_peak_value = adc_value;

      else;

      delayMicroseconds(10);

  }

 

  dc_voltage_V0 = voltage_peak_value * 0.00488;

  ac_voltage_V0 = dc_voltage_V0 / 1.414;

 

   

//  Serial.println("================================ CURRENT ========================================");

 

  voltage_peak_value = 0;

  for(sample_count = 0; sample_count < 5000; sample_count ++)

  {

      adc_value = analogRead(A2);

      if(voltage_peak_value < adc_value)

          voltage_peak_value = adc_value;

      else;

      delayMicroseconds(10);

  }

 

  dc_voltage_V1 = voltage_peak_value * 0.00488;

  ac_voltage_V1 = dc_voltage_V1 / 1.414;

 

  dc_current_I0 = (dc_voltage_V1 - dc_voltage_V0) * 100;

  ac_current_I0 = (ac_voltage_V1 - ac_voltage_V0) * 100;

 

  //================================= POWER =========================================

 

  dc_power = dc_current_I0 * dc_voltage_V1;

  ac_power = ac_current_I0 * ac_voltage_V1; 

 

  lcd.clear();

  lcd.setCursor(0, 0);

  lcd.print(dc_power);

  lcd.print(" mW"); 

 

 //=================================================================================

 

  delay(1000);   

}

Credits

TechnicalEngineer
4 projects • 51 followers
Contact

Comments

Please log in or sign up to comment.