Detecting/Counting LED Pulses on a Wattmeter

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guyzz i have a Wattmeter with 2 yellow leds on it.

The Meter is in a cupboard that is normally closed , meaning darkness is in there.

The Top led gives 10000 pulses / KWH (Kilo Watt Hour), the bottom led gives 500 pulses / KWH.

I would like to mount a phototransistor on the meter , and count the 500 pulses LED , with an AVR (prob a M168 5-volt).

I have bought 2 different Phototransistors
1: BP103B
http://www.ortodoxism.ro/datashe...

2: BPX81
http://www.ortodoxism.ro/datashe...

This is my first experience with a Phototransistor , so i would like some guidance (mounting hints and schematic). I would suppose that the Powercompany would NOT like for me to drill a hole in their meter , and not to destroy or make any marks on their meters plastic surface.

My idea is to connect the Phototransistor to an external interrupt on the AVR , and increment the KWH counter on each 500 pulses.

I have two potential problems ... maybe more :-)

1: The topled also pulses 10000/KWH, and might give false lght to the Phototransisor mounted at the bottom LED.

2: When i open the cupboard door there will come daylight in (quite a bit) , and that might give trouble with the readings. But the door would not normally be open , and it takes some time (hopefully to make 500 pulses , or my Power Bill will be $$$$$) , so maybe i would be able to live with that misreading/miscounting. Maybe i could wrap the meter in a "Black plastic bag".

How do i adjust the sensitivity on the Phototransistor , to get a "clean" interrupt.

Edit: It seems like yellow LED is around 590nm wavelength , and that is not the most sensitive area , for the phototransistor. But it is approx 45% of max sensitivity.

The BP103B has a daylightfilter , would that do any good , if the door is open ??

/Bingo

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tip 1: use a lense to focus on the led ; CD-rom drives have nice lenses in the focus-range of 8 to 10 mm, so find yourself a scrapped one ....
Tip 2: The duration of a "blip" of the led will probably be constant; measuring both edges will give you the possibility to do extra filtering in software (i.e. the pulse must be xx ms long)
Tip 3: use a differentiator between photo-transistor and AVR; constant daylight will have hardly any influence. But if you make pictures (with flash) in the cupboard .... you count an extra 2 WH :wink:

Plons

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Plons wrote:
Tip 1: use a lense to focus on the led ; CD-rom drives have nice lenses in the focus-range of 8 to 10 mm, so find yourself a scrapped one ....
Tip 2: The duration of a "blip" of the led will probably be constant; measuring both edges will give you the possibility to do extra filtering in software (i.e. the pulse must be xx ms long)
Tip 3: use a differentiator between photo-transistor and AVR; constant daylight will have hardly any influence. But if you make pictures (with flash) in the cupboard .... you count an extra 2 WH :wink:

Plons

@Plons

Thanx for tip 1 & 2 , seems like a good idea.
I have written the meter company to ask if the pulses are cinstant , and have found out that on the newer versions the "Blip" is 32 ms. But i cant find anything on the old "Enermet K420iNN"

Re. Tip 3.

What is a diferentiator ???

I have seen some constructions where they actually uses an extra IR led in the RX circuit (IR detection) near by the Phototransistor , and they says it increases the sensitivity (they uses word bias)

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What is a diferentiator ???
A differentiator outputs a signal proportional to the CHANGE of the input-signal. Sketch 1 shows a basic setup.

Quote:
I have seen some constructions where they actually uses an extra IR led in the RX circuit (IR detection) near by the Phototransistor , and they says it increases the sensitivity (they uses word bias)

That is a good suggestion ...

Sketch 2 gives an idea of an implementation with standard stuff. Here we use ambient, temperature etc as bias. Note that both PhotoTransistors are the same.

But we are AVRfreaks ... and AVR's have a very nice analog comparator. Sketch 3 gives an AVR-implementation I would start with.
For the value of R1 and R2: you need to do some experiments there .. it depends on how much light comes from the blip-led, and the amount of ambient-light you'll have to cope with. Start with 10 - 100 k .... gut-feeling

Have fun

Plons

Attachment(s): 

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If your only concern regarding false pulses is opening and closing of the door, and thereby exposure to daylight - does it really matter if the LED pulse is 10, 50 or 100 ms? In any case, the "daylight pulse" will be so much longer that it shouldn't be hard to eliminate. Unless of course the daylight is so intense that the photodetector saturates, in which case the LED won't be detected in any case. Some degree of shielding from ambient light is probably a good idea anyway.

By detecing the edges of the pulse - instead of level - a bit of constant daylight won't matter. If you intend to measure the pulse width that's probably what you'll have to do in any case.

The phototransistor with a daylight filter (the BF version?) seems to designed for IR operation - hence the filter to remove all visible light.

Interesting project by the way. We have an old fashioned kWh meter with a rotating disc and a mechanical counter, so counting kWh is already taken care of. We don't however have a meter showing the actual power consumption (in kW)... If I can measure the rotating speed of the disc (the disc is behind a glass window, and has a black mark on it), calculating the kilowatts would be very simple - the meter is calibrated in number of revolutions per kWh. Thanks for the inspiration!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just tried the BPX81 with a 10K on collector to VCC , and Emitter to GND , and a scope on the Collector.

The yellow led is connected to an AVR pin via 1K (might be a bit hich but there wasn't that much power on the "Powermeter Led".
The swing was lousy :-(

I did the same with a 100K to VCC , and the scope dropped to 0 , but only if i stuck the led and the BPX so close up that they almost touched

I would have expected that it could be done with a 10K ??? ... Am i doing anything wrong here ??

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is possible that you need to amplify the output of the phototransistor. Try using another transistor in a Darlington pair configuration. I had to do this to interface an IR phototransistor to an AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bingo said:

Quote:
The swing was lousy Sad

Did you expect a full swing ?
With 100k, the leakage-current of the PhotoTransistor will have too much influence. Adding a darlington will have a simular effect.
Why not use the analog comparator of the AVR ?
Can you quantify the swing you found in the 10k set-up ?

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The below is the Led connected to TXD on a M8 , and transmitting with 9600 BPS. The ScopeProbe of my TDS-320 is connected to the Collector of the BFX.
Due to the 100K pullup the curve is round at top.

/Bingo

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks quite good ....

A problem might occur when you put this in the cupboard where the meter is, and the door is opened ... the PT (PhotoTransistor) will then saturate

Attached a sketch of what you could do: use the analog comparator in the mega8, and compare the PT-collector-voltage (Vc+) with a 90%-value which is slow (time-wise). A blip from the LED will cause Vc+ to dip :wink: but the voltage Vc- will stay @ 90% of the original value. If you increase the 100k (f.i. to 220k or even 330k), the sensitivity will go up. The rest is only software.

Nard

Attachment(s): 

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, did you get the LED count thing working ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just tried the phototransistor on the powermeter , with a terrible result :(

I connected the phototransistor collector to vcc (5v) via a 270K resistor , and the base to gnd.

I fed the collector signal to a AHC14 , and then to the AVR INT0 pin.

It worked for a few minutes (nice 5ms pulses on INT0), and then all of a sudden the AHC14 output made the neat 5 ms pulse , but at the end it "bounced like a cracy around 3.5v , for maybe 10..25 ms. Before falling to GND level. This would happen at random , or so it seemed.

If i put my finger on the AHC14 GND then it behaved ok :?:

I have a 220uf cap and a 100nf cap on the AHC14 board , and approx 30 cm of ribbon wire to the avr.

Is this the "infamous latchup" ???

It is useless , as i count a zillion pulses when it happens.

Edit: I have to do some signal conditioning , either op-amp or comparator , before feeding it to the AVR i guess. I know i pushed it to the limit when using 270K , but i didnt have any else components with me in the summerhouse. I have some LM393 Comp's and some LM358 (i think) (8 pin opamps).

I tested at home with an avr (uart) , and a yellow led w. 39R , wo. probs. But in real life there is much less light intensity.

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The IR LED idea has merit. Some photo-transistors have a base lead available, some don't. The latter require a second light source to force the sensor into linear operation.

Here is what I would recommend. Use an op amp to drive the IR LED and sense the voltage at the photo-transistor's collector. Use a 10K pull-up on the transistor. Bias the op-amp's other input with a 10K/10K divider parallel with the transistor and its load resistor. The LED/Op-Amp will force the collector to VCC/2. Now you can amplify the pulse train and let the controller's comparator do its thing.

Cheers

"It's easier to ask forgiveness than it is to get permission" - Admiral "Amazing" Grace Hopper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to do some fairly standard debouncing, that's all. Hardware changes can accomplish this, but you can do it entirely in software. I assume your pulses are at least 50 mS apart (and nominally 5 mS in duration).

Hardware: Place a capacitor (I would try 10nF first) from the collector of the phototransistor to GND.

Software: When you get an interrupt, do your thing with it, and start a 50 mS timer. Disable the interrupt before reti. Leave the interrupt disabled until the timer finishes, then enable it again.

Be sure that the unused inputs on the AHC14 are tied to Vcc or GND.

Harware

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working on a project that uses a bunch of IR Phototransistors similar to what you're trying to do.

The 393 with a little hysteresis will work great, especially since you have some extras lying around.

my board:

I have too many hobbies.
s-conductor.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I finally got the pulsecount to work.

I used a BPX81 phototransistor w. 100K as pullup , and then a LM339 comparator set for 4.2 volts.
I got some neat 2ms pulses @ VCC , but also some spikes once in a while.

I finally abandoned the interrupt , due to the spikes. And decided to poll in a 250uS timer interrupt , if i got 5 positive readings , then i took that as a positive.

It has been running for 2 days now , and is still counting correctly.

Now i have a working prototype , and might replace it all with a small avr.

Thanx all :-)

/Bingo

Last Edited: Mon. Jan 1, 2007 - 03:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good to hear you got it working !

What I wonder : why not use the analog comparator of the AVR itself instead of a 339 ?

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@plons

I Will :-)

But on my protoboard the avr pins for the comparator was allready used :-)

I might dedicate either a Tiny13 or a M48 for just this task , in the final version.

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

id love to get the scematics and code for the final version once it's ready, i dont like standing outside whne i need do se the watt usage :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Plons wrote:
Looks quite good ....

A problem might occur when you put this in the cupboard where the meter is, and the door is opened ... the PT (PhotoTransistor) will then saturate

Attached a sketch of what you could do: use the analog comparator in the mega8, and compare the PT-collector-voltage (Vc+) with a 90%-value which is slow (time-wise). A blip from the LED will cause Vc+ to dip :wink: but the voltage Vc- will stay @ 90% of the original value. If you increase the 100k (f.i. to 220k or even 330k), the sensitivity will go up. The rest is only software.

Nard

@Plons

Got a new powermeter , and decided for this schematic.
https://www.avrfreaks.net/index.p...

It works excellent, and automaticly adjusts when the door is open.

Thanx :-)

I used a 10K resistor (vcc) & a 12K photoresistor (gnd) , in a voltage divider. The test (scope picts) is made with a LM393 comparator , but i'll prob use a Tiny13 for the signal conditioning , and the cpomparator in that one.

/Bingo

Attachment(s):