Newbie: using photo diode on GPIO for power meter reading


13 posts
by andig2 » Wed Oct 31, 2012 9:51 pm
Hi all,

I'm new to the Pi and have only limited soldering and electronics experience from the ancient past- but know how to use google :mrgreen:

I'm planning to use my Pi for reading several power meters at my home- either older Ferraris types or ones with blinking LEDs (1000 impulse per kWh).

For the latter I'm thinking of hooking up a simple photo diode plus pullup resistor to an GPIO input. Is that all it takes or do I need an op amp? Or would a photo transistor be better suited (thinking about the transistor for the Ferraris type meter anyway...)

Best,
Andi
Posts: 24
Joined: Wed Oct 31, 2012 9:34 pm
by andig2 » Sat Nov 03, 2012 2:47 pm
I've found a solution! :D
Using an inverting op amp with offset voltage provided by mini trimmer I'm able to adjust working point of the photo diode. 100nF capacitor between output and inverting input further increases stability.
For control purposes I've also added LED to the breadboard, however driven by 2nd op amp as the LM358 looses output voltage when current is drawn.
Posts: 24
Joined: Wed Oct 31, 2012 9:34 pm
by bgirardot » Sat Nov 03, 2012 3:01 pm
I'd love to see any more details on your set up if it is convenient to provide, a few pics or circuit diagram, hand drawn is fine. It sounds like a cool project, over my head at the moment, but I'm learning thanks to folks like you sharing how you accomplish things.
Posts: 517
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland
by andig2 » Sat Nov 03, 2012 3:55 pm
Glad to, please find the diagram attached:

Unbenannt.png
Unbenannt.png (12.36 KiB) Viewed 2861 times
Posts: 24
Joined: Wed Oct 31, 2012 9:34 pm
by andig2 » Sat Nov 03, 2012 3:57 pm
RE1 and Pot1 are used to adjust the working point of the photo diode, RE2 and 3 are there to setup minimum input voltage for second amplifier to avoid it opening on floating input.
Posts: 24
Joined: Wed Oct 31, 2012 9:34 pm
by bgirardot » Sat Nov 03, 2012 4:24 pm
Cool! Thank you very much.
Posts: 517
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland
by Yfory » Sat Nov 03, 2012 4:31 pm
Hi,

My solution to blinking LED meter readings is at: http://github.com/yfory/power

Released under MIT license. :)
Posts: 96
Joined: Thu Apr 19, 2012 10:29 am
by andig2 » Sun Nov 04, 2012 2:11 pm
Yfory,
this is _really_ simple :roll:
I wouldn't have thought that resistor/capacitor could be fast and sensitive enough. Are there any special requirements regarding your meter?
kind regards,
Andreas
Posts: 24
Joined: Wed Oct 31, 2012 9:34 pm
by Yfory » Sun Nov 04, 2012 3:05 pm
No special requirements; everything listed is what was used and is working for me.

I am sure there are far more complex and interesting ways to do this, but I like building things that are simple enough for everyone to reproduce. I am using 10m of 4-core (3 wires, 1 spare) telephone cable to an external meter without any fault.

The only "issue" to watch out for is the 90,000 number, which is bound to be more or less on your set up, so add some print commands to the .py code to figure out a reasonable number before you leave it running 24/7. I believe I added a note about that to the documentation.
Posts: 96
Joined: Thu Apr 19, 2012 10:29 am
by twem » Mon Nov 12, 2012 12:26 pm
Yfory,

I have read through your information on Git Hub.

What value LDR did you use in your setup?

I have tried to create my own but the value going to the GPIO is not changing from enough when I cover or uncover the LDR.
Posts: 3
Joined: Sun Jul 08, 2012 12:04 pm
by MattHawkinsUK » Mon Nov 12, 2012 5:03 pm
An LDR is probably too slow. A photo-transistor is the way to go.

A friend got this working on his meter by connecting the Emitter to ground. The collector to 3.3V (via a 100K trimming potentiometer) and the collector to a GPIO input (via a 2K resistor). Adjusting the potentiometer adjusted the point at which the GPIO would go High/Low on a flash.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)
User avatar
Posts: 491
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
by andig2 » Mon Nov 12, 2012 5:36 pm
Good idea- the transistor may also be sufficient to drive an LED as well as then Input?
Posts: 24
Joined: Wed Oct 31, 2012 9:34 pm
by mahjongg » Mon Nov 12, 2012 5:53 pm
Unless I'm very mistaken, an LDR would also be fast enough, and much simpler, in principle just the LDR connected to a GPIO with a pullup resistor.
Yes, an LDR might need several seconds to regain its full "dark resistance" of several Meg Ohm, but generally its response time (between say 1K and 50K) is a few dozen milliseconds, for a slow blinking LED it should be fast enough. In any case its worth trying if it works.
User avatar
Forum Moderator
Forum Moderator
Posts: 6042
Joined: Sun Mar 11, 2012 12:19 am