Offline
Jr. Member
Karma: 0
Posts: 99
|
 |
« on: July 14, 2012, 12:54:38 am » |
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/4913164A 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
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #1 on: July 14, 2012, 03:41:52 am » |
1. is it "1600 times for 1KW h"...?  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
|
|
|
|
|
Logged
|
-Arne
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #2 on: July 14, 2012, 03:47:59 am » |
1. is it "1600 times for 1KW h"...?  ... or even kWh 
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 99
|
 |
« Reply #3 on: July 14, 2012, 04:18:03 am » |
1. is it "1600 times for 1KW h"...?  ... or even kWh  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
|
|
|
|
« Last Edit: July 14, 2012, 05:10:20 am by iisfaq »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 99
|
 |
« Reply #4 on: July 15, 2012, 12:56:20 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #5 on: July 15, 2012, 01:40:09 am » |
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...
|
|
|
|
« Last Edit: July 16, 2012, 08:19:50 am by RIDDICK »
|
Logged
|
-Arne
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 99
|
 |
« Reply #6 on: July 15, 2012, 04:50:46 am » |
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. 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. i still think that the arduino pin has something like a schmitt trigger builtin...
No idea myself. what does the scope say?
I will try tomorrow and post results here 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. 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
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 99
|
 |
« Reply #8 on: July 16, 2012, 03:45:57 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 9
Posts: 1000
|
 |
« Reply #9 on: July 16, 2012, 06:17:58 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #10 on: July 16, 2012, 08:19:35 am » |
i think it might be a good idea to pull down the other 5 inputs... because: a floating input wastes power...  good luck for ur test...
|
|
|
|
|
Logged
|
-Arne
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 99
|
 |
« Reply #11 on: July 20, 2012, 06:28:33 pm » |
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. Chris
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #12 on: July 22, 2012, 04:14:57 pm » |
i would connect it with very low resistance... is "pull down" wrong for that? i mean "short" to ground (but just the _inputs_)... 
|
|
|
|
|
Logged
|
-Arne
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #13 on: January 18, 2013, 05:18:00 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Finland
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #14 on: January 19, 2013, 06:42:25 pm » |
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: http://www.sensorbay.com/2012/11/project-1-home-energy-monitor-with.htmlSW: http://www.sensorbay.com/2012/12/project-1-home-energy-monitor-with.htmlData: http://www.sensorbay.com/2013/01/project-1-home-energy-monitor-with.html
|
|
|
|
|
Logged
|
|
|
|
|
|