Real-Time Energy Monitor with Arduino and LabVIEW

By on August 19, 2011

We present the candidature of Mr. Michele Mancini for the TiDiGino Contest. He proposes us a recent application with Arduino: Real-Time Energy Monitor

This is a simple power meter to analize the current consuming in a house using the led indicator of a house energy meter.

Reading the red led of a home energy counters the system detects the corrent consumption in a house.

It is a noninvasive method, not cut wire, no current disconnects, so a very interesting method…
The system consists of two parts: the Arduino board that detects the led pulses and sends the data via the XBee module, and a PC that recive the data through a USB/Xbee module and processes the data with LabVIEW so you can prepare and study the consumption in a very instant.
Arduino sends two datas to the PC:
1 – Real time datas
2 – Average consumption measured in a time of 5 minutes.

 

From the picture we see that the LED that indicates the current consumption is the red LED near to the display. In particular is the LED superior.

Arduino module
To detect the LED blinking you have to apply a simple photoresistor above the led and covered it with black tape. To read the analog voltage using the Arduino you have to use a resistive divider as shown in diagram:

The LED blinking causes the voltage drop down and this value is read by Arduino and compared with the voltage acquired by the potentiometer connected in the channel A0. This potentiometer has the task to adjust the sensitivity threshold.
The read data are processed from the sketch and then sends to the PC via Xbee module.

The Arduino code acquisition is as follows:

 
   delay(10); //10ms
   val_pot = analogRead(POT);   
   delay(10); //10ms
   val_sensore = analogRead(SENSORE);
  if((val_sensore > val_pot)&(flag_acquire == 0)){ 
      flag_acquire = 1;
      digitalWrite(LED, LOW);

With this code Arduino acquires the two voltages, the photoresistor voltage compared with the voltage of the potentiometer, if the value is greater than the sketch actives the flag “flag_acquire = 1″, then read how much time has passed to another flash.
To do this use arduino to read a statement in an internal counter that returns the milliseconds since power on. The instruction is “millis ()” code here:

pre_tmS = cur_tmS;
      cur_tmS = millis();
      if( cur_tmS > pre_tmS ) {
        tm_diffS = cur_tmS – pre_tmS;
     }

There are 2 variables pre_tmS and cur_tmS, “cur_tmS” needs to read the current value of the internal counter: cur_tmS = millis (); Then if the condition (cur_tmS> pre_tmS) is true, I note the elapsed time between cycles, ie between the LED ON and the next cycle of the LED ON and write it on the variable “pre_tmS”. Now we have to send to the PC via the serial port using XBee with these instructions:

Serial.print(“S”); 
      Serial.println(tm_diffS); 
     delay(10); //10ms

First Arduino sends a marker “S” used to labview to recognize that this value is part of the reading that real-time instant, then send the value in milliseconds elapsed. Now you have to reset the flag when the LED goes OFF using this statement:

  if((val_sensore < val_pot)&(flag_acquire == 1)){ 
      flag_acquire = 0;
     digitalWrite(LED, HIGH);
      impulsi++;         
      delay(10); //10ms 
  }

You have to check the voltage acquired by the sensor, if it falls below the potentiometer value and the flag is active “flag_acquire == 1″ then you have to reset the flag. Note that the statement “impulsi++;” is simply a counter that counts the cycles of the LED power meter, this is to make an average energy consumed every 5 minutes. The third task is similar to the first task, wait 1 second, and increments the counter “time_flag++,” which is the fourth task of counting 300secondi (5 minutes). In addition, this task blinks the LED connected to pin 12 at a rate of 1 second.
The fourth task as mentioned above waiting 5 minutes and then sent via serial marker “L” is used to program labview to recognize that the data sent is the data on the average found in 5 minutes.

 

The sketch

 

#define POT 0
#define SENSORE 1
#define LED 13
#define LED1sec 12

// definire il tempo casuale che varia tra 40ms e 250ms
#define TimeAcquire  1000      //1sec
#define Time5Minuts  300      //5 minuti = 300sec 

unsigned long cur_tm = millis();
unsigned long pre_tm = cur_tm;
unsigned int tm_diff = 0;  

unsigned long cur_tmS = millis();
unsigned long pre_tmS = cur_tmS;
unsigned int tm_diffS = 0;  

unsigned int time_flag=0;

unsigned int impulsi=0;
unsigned int val_pot=0;
unsigned int val_sensore=0;
char flag_acquire=0;
char flag_time=0;

void setup() {  

  pinMode(LED, OUTPUT);
  pinMode(LED1sec, OUTPUT);
  Serial.begin(115200);          //  setup serial 115200
  Serial.println("ENEL KW/h reader!");

}  

void loop() {

  //Acquisisco
   delay(10); //10ms
   val_pot = analogRead(POT);    // read the input pin
   delay(10); //10ms
   val_sensore = analogRead(SENSORE);    // read the input pin

  if((val_sensore > val_pot)&(flag_acquire == 0)){
      flag_acquire = 1;
      digitalWrite(LED, LOW);

      pre_tmS = cur_tmS;
      cur_tmS = millis();
      if( cur_tmS > pre_tmS ) {
        tm_diffS = cur_tmS - pre_tmS;
      }
      Serial.print("S");
      Serial.println(tm_diffS);  

      delay(10); //10ms

  }
  if((val_sensore < val_pot)&(flag_acquire == 1)){
      flag_acquire = 0;
      digitalWrite(LED, HIGH);
      impulsi++;          //Incrementa impulsi
      delay(10); //10ms
  }

  //------Ogni 5 minuti invia "impulsi" ----------
  pre_tm = cur_tm;
  cur_tm = millis();
  if( cur_tm > pre_tm ) {
    tm_diff += cur_tm - pre_tm; //+=
  }
  if( tm_diff >= TimeAcquire ) { //Task ogni secondo
    tm_diff = 0;

    time_flag++;

    if(flag_time==0){
      digitalWrite(LED1sec, HIGH);
      flag_time = 1;
    }else{
      digitalWrite(LED1sec, LOW);
      flag_time = 0;
    }

  }

  if(time_flag>=Time5Minuts){
//Sono passati 5 minuti ? ..... Invia "impulsi" rilevati dal contatore
      Serial.print("L");
      Serial.println(impulsi);
      impulsi = 0;
      time_flag = 0;
  }

 //--------------------------------------------------

}

LABVIEW interface
To recive the data we use the XBee UartSbee V3.1 module from Futura Elettronica.


The interface created in LabVIEW is simple to use:

As can be seen from this figure, the top graph shows the average consumption every 5 minutes, while the bottom graph shows the real-time energy consumption. It ‘can save the data using the device as a data logger.

Download

Download ZIP File  Arduino Sketch
 Download ZIP File  LabVIEW (VI file)
 Download ZIP File  Schematics (eagle file)

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.
  • Pingback: Electronics-Lab.com Blog » Blog Archive » Real-Time Energy Monitor with Arduino and LabVIEW

  • Pingback: Mesurer et Suivre sa conso électrique

  • Neit

    Can You answer on this questions, please:
    How this program on LabView can count Energy of any energy meters, if they are have individual constant (Impulses/(1Kw*h))?
    Whats correlation between Energy (W*h) and Time of one impulse (ms)?
    PS: Sorry for my bad english :)

    • BorisLandoni

      This sketch is specific for Italian Energy meter. You have to adapt it for your Energy meter.

      • Neit

        Thanks for information, I does not known it.
        I got this formula:
        P(Kw*h)=3600/(t(sec)*A)
        A – constant of energy meter (impulses/Kw*h).
        t – time of one impulse
        (I write it here, if anybody will need in future)
        So, constant for Your energy meter is 1000 (impulses/Kw*h).
        PS: Is it energy meter on image №2?! When I saw this, I thought that is self-made energy meter made from shell of the hard drive!

        • BorisLandoni

          Thank you.

  • ShaamN

    Good
    day! Please tell me how to work photoresistor in this scheme (as I know
    the photoresistor slow response) On what the maximum load power meter
    tested this device?

    • BorisLandoni

      The led don’t blink too fast

  • suma
  • Pingback: Cubietruck | Pearltrees