Go Down

Topic: Home Energy Monitoring via flashing LED on Meter (Read 5 times) previous topic - next topic

iisfaq

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

http://uk.farnell.com/vishay/tsop4136/photodiode-ir-receiver-36khz/dp/4913164

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

I am using this code

Code: [Select]

/*-----( 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

RIDDICK

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

2.
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
-Arne

JimboZA

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

iisfaq

#3
Jul 14, 2012, 11:18 am Last Edit: Jul 14, 2012, 12:10 pm by iisfaq Reason: 1


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



... 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

iisfaq

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

Go Up