Home Energy Monitoring via flashing LED on Meter

I have seen some posts around the net on Monitoring your home electricity meter by counting the flashes on the LED that most have.

In my case it is a red led that flashes 1600 times for 1 KW.

I have simulated this setup with 2 arduino's

I am using a TSOP4136 IR Receiver

A the moment the IR Receiver's out is fed into pin 3 on the arduino duemilanove.

I am using this code

/*-----( Declare Constants )-----*/
#define ANALOG_SENSOR_PIN  A0 
#define DIGITAL_SENSOR_PIN 3  
#define LEDPIN    13  // The onboard LED

int Counter = 0;

/*-----( Declare Variables )-----*/
int  switch_state;  /* Holds the last digital value */
int  LightAnalogValue; /* Holds the last analog value */
unsigned long pulseCount = 0;  // Counts power pulses in interrupt, 1 pulse = 1 watt
unsigned long pulseTotal = 0;  // Total power used since the sketch started
 
volatile int pulseFlag = 0;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
       /*Initialize INT0 for accepting interrupts */
     PORTD |= 0x04; 
     DDRD &=~ 0x04;
     
  pinMode(LEDPIN, OUTPUT);
  Serial.begin(9600);          // Enable the Serial data output
//Enable interrupt for light sensor on Digital 3

  attachInterrupt(1, Pulse, FALLING);
}/*--(end setup )---*/

void Pulse() // routine called when light sensor interrupt is triggered
{
    detachInterrupt(0); 
    pulseFlag = 1;
}

void loop()
{  
  if (pulseFlag == 1) 
    logPulse();  //if interrupt caused by light sensor, count the pulse
}

void logPulse() //count a pulse from the light sensor
{
   pulseCount ++;
   pulseFlag = 0;
   Serial.print("Pulse Count: "); 
   Serial.println(pulseCount);
   Serial.println(millis());
   delay(10);
   attachInterrupt(0, Pulse, LOW);  
}

Now this seems to work but looking with a scope the signal is noisy and it is not a nice square wave - almost a sine wave.

What is the best way to clean this up and make it a square wave?

Chris

is it "1600 times for 1KWh"...? :slight_smile:

a schmitt trigger?
implemented in hardware preferably...
the arduino digital pins might suffice...
or u use an extra schmitt trigger (like BU4S584G2)...

or u try to do it with analogRead()...

or u use this button library:
http://www.arduino.cc/playground/code/bounce

RIDDICK:
1.
is it "1600 times for 1KWh"...? :slight_smile:

... or even kWh 8)

JimboZA:

RIDDICK:
1.
is it "1600 times for 1KWh"...? :slight_smile:

... or even kWh 8)

Actually

1600 Imp KwH

Or something like that - it is dark. So 1600 flashes per Kilo Watt Hour!

Thanks for the tip on the Schmitt Trigger - RIDDICK

Chris

OK - I am getting myself lost here.

My TSOP136 IR Receiver is pulsing like this

1 pulse
2 pulses
1 pulse
2 pulses

and sometimes

1 pulse
1 pulse
2 pulses

Now the RED LED is pulsing just one per second. So that should be

1 pulse
1 pulse
1 pulse
etc

a Red LED is around the 650 nm wave length and the IR Receiver I assume since it is IR is more like 875 or so. It is oviously pickin up the flash but maybe in this case it is too smart since it says in the docs

"PIN Diode, pre-amplifier, AGC, pass Filter and demodulator"

Would I be better off with a LDR feeding into a Schmitt Trigger?

I went out and bought the wrong schmitt IC today at the local JAYCAR - I ended up buying a 4093 QUAD 2-INPUT NAND SCHMITT TRIGGER CMOS IC instead of 74C14 HEX SCHMITT TRIGGER CMOS IC

Do you think the lack of a Schmitt Trigger could be causing this double counting sometimes?

Chris

u can use a nand schmitt trigger too...
X = ((HIGH NAND X) NAND HIGH)
F = ((T) NAND T)=F
T = ((F) NAND T)=T

a LDR sounds good too...

i still think that the arduino pin has something like a schmitt trigger builtin...

what does the scope say?

did u try that debounce library? i guess those blinks r 30msec long...
even if u tell the debounce library to skip 40msec, u could detect >10Hz...
after 160secs u could have 1kWh (max)...
that limits ur load to 22.5kW (22 vacuum cleaners)...

do u know this site:
http://www.bwired.nl/Stroom.asp
?
they use an IR sensor 2...

RIDDICK:
u can use a nand schmitt trigger too...
X = ((HIGH NAND X) NAND HIGH)
F = ((T) NAND T)=F
T = ((F) NAND T)=T

Thanks I thought it should work but I will buy some straight triggers tomorrow.

RIDDICK:
a LDR sounds good too...

I will try this and see if this is better or not - I guess with a volage dividor and a schmitt trigger it would be good if it is fast enough.

RIDDICK:
i still think that the arduino pin has something like a schmitt trigger builtin...

No idea myself.

RIDDICK:
what does the scope say?

I will try tomorrow and post results here

RIDDICK:
did u try that debounce library? i guess those blinks r 30msec long...
even if u tell the debounce library to skip 40msec, u could detect >10Hz...
after 160secs u could have 1kWh (max)...
that limits ur load to 22.5kW (22 vacuum cleaners)...

No I did not since my code is using interrupts and the debounce is not.

RIDDICK:
do u know this site:
http://www.bwired.nl/Stroom.asp
http://webcache.googleusercontent.com/search?q=cache:Fp9kltwbJicJ:www.bwired.nl/Stroom.asp+&cd=1&hl=de&ct=clnk&gl=de

I have seen it years ago and was thinking about it a week or two back. Amazing what one can monitor but toilet flushes do not interest me.

Cheers

Thanks for your help

Chris

here they describe how they built the sensors:
http://www.bwired.nl/How_rfxcom.asp

they use a
http://www.bwired.nl/images/how/bpw85.pdf

sounds similar to ur meter...
but it blinks about 3 times less often per 1kWh...
btw: they write kW too...

OK

I have started from scratch as far as the hardware goes - the software is the same as earlier in this post history for this topic.

The image contains most of the hardware but I will repeat it here:

1 x 4.7K OHM Resister
1 x LDR (10M in the dark, 0 in the light)
1 x 40106 Schmitt Trigger - Inverting.
Hookup Wire

This along with the original code from above is nicely capturing the pulses from LED on arduino board, and also a torch.

I will next need to do some testing with the actual live meter.

Next problem is the meter is in a steel box on the outside of the house - I need to figger out a wireless solution but am happy at the moment.

Chris

Your TSOP4136 sensor is for a signal of 36kHz. It is used for remote controls.
So it will work for a certain IR wave lenght, which is coded at a frequency of 36kHz.

Is the led a normal red led ? then it is certainly not IR, and it is not coded with 36kHz.
You need a phototransistor or photodiode.

i think it might be a good idea to pull down the other 5 inputs...
because: a floating input wastes power... :slight_smile:

good luck for ur test...

RIDDICK:
i think it might be a good idea to pull down the other 5 inputs...
because: a floating input wastes power... :slight_smile:

Thanks for the advise.

I take it that pulling it down means connecting a resister to GND?

If so how do I calculate the correct value for a resister to GND?

Should I be looking at the datasheet for this type of Information? I am a newbee and want to learn so if you can point me to a web site that would be great, even just letting me know a 10K resister etc would.

Chris

i would connect it with very low resistance...
is "pull down" wrong for that?
i mean "short" to ground (but just the inputs)... :wink:

I tried it with the TSOP4136 too, on a Itron CL200 meter in the USA. It never worked well and consistently. I thought it was a noise issue too.

After some trial and error, I discovered that the TSOP4136 is totally unsuitable this purpose. It detects modulated signals, and I am not even sure that my electric meter was outputting modulated signals. Their technical specs for the meter don't mention anything about it.

On a hunch, I tried just an simple infrared detector from Sparkfun, SEN-00241 https://www.sparkfun.com/products/241 That did the trick. Now I detect the pulses extremely reliably, to every single watt-hour to be able to predict when the meter will flip over to the next kWh digit. The only possible issue is that the sensor is certainly sensitive to ambient illumination, so I have to shield it. The ambient infrared tends to pull the signal low, so to get a clear HIGH and LOW signal, I route it through a comparator, comparing it against a reference voltage of about 3.5 V (arrived at by trial and error). I don't have a scope to verify the purity of my signal, but I was able to measure the pulse width to be consistenly 10.025+/- 8 milliseconds.

If you have a LED that produces visible light, then an infrared sensor that captures invisible light (different wavelength) is hardly an optimal solution.

As others have already mentioned, TSOPs are common in decoding infrared remote controller signals, which use high frequency carrier signal (such 36kHz, 52kHz or something like that), and modulate this when keys of the remote controller are pressed. Definitely not optimal for calculating pulses of a visible light LED.

A simple LDR sensor, light dependent resistor, easily does the trick. If you connect it to Arduino, you don't need any fancy extra components. Just sample that sensor fast enough and do all the signal processing with software. This method allows logging and plotting the actual signal, and tuning your algorithm for it.

I've written quite a detailed series of articles about exactly this use case at SensorBay.com. These should be very helpful for you and others who are building the same thing - even if you decide to use your own HW method.

HW: sensorbay.com
SW: sensorbay.com
Data: sensorbay.com