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?
a schmitt trigger?
implemented in hardware preferably...
the arduino digital pins might suffice...
or u use an extra schmitt trigger (like BU4S584G2)...
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?
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)...
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.
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.
RIDDICK:
i think it might be a good idea to pull down the other 5 inputs...
because: a floating input wastes power...
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.
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.