Most modern energy meter have one or more LEDs which blink at a rate directly related to the energy used. The one above has two of them : one pulses at 1000 pulses per active kWh, the other one pulses at 1000 pulses per reactive kWh. I dealed with the active power only, event though I’m billed partially for reactive power also.
The idea is to collect the blinks of the LEDs in 5 minutes blocks. Twelve groups of 5 minutes-worth counts give an hour, then data are collected around 24 hours.
I used Processing to read to read the LED through a webcam and detect and collect the blinks.
Processing and its video library is the most obvious choice to me as I’m not much of a high-level programmer. Processing is well supported and gives instant gratification. It also runs on a variety of platforms, including my little Acer Aspire One where I managed to have processing run some time ago.
Grabbing the camera image is straighforward with processing : had to install vdig (vs 1.0.1) as instructed in the processing support forum and Apple’s Quicktime 7 which is the essential part to grab the video Everything went smooth, on my desktop at least. I couldn’t have it running on my Aspire One as vdig of course doesn’t run on it, and would have had to use a different library.
That said, I wrote a quick ’sketch’ in Processing to grab the camera, select with the mouse the “hot spot” of the meter (the LED) to minimize interference from the reactive power LED and ambient lights reflection. The code also represents visually the energy used in 5-minutes chucks over the 24 hours.
This is what is seen in Processing through the web cam. The image is upside-down because the camera is. But of course it doesn’t matter.
The LED area is selected clicking and dragging with the mouse. Some sort of dark cloth sleeve is necessary to pretect the camera from glare and reflection which might cause false or missed reading.
The camera view is activated pressing the “v” key on the keyboard. Click and drag a square around the LED. When done press any other key to turn on the count reading window, the one below :
The bars represent the total reading for a 5 minutes slot starting from 0:00 to 23:55 hours. The height of the bar is the reading (in my case 1Wh per pixel) and is incrmented every blink of the LED (1 Wh gone). Hovering the mouse on window (do not click on the window) returns on the top left the reading (kWh) for the time slot on the extreme left. Click on the image above to go to the flickr’s noted version for what the peaks are due to.
On the right of the string is the total reading over the last 24 hours.
A reasonably fast PC is necessary though to catch the quick blinks and evaluate the very frequent counts during peek energy requirements. And I didn’t want to dedicate my main dual core desktop PC to the purpose.
For now I did not design any mean to read remotely the data. Of course it is probably nonsense to keep continuously a fast-power hungry PC for the purpose. The Tweet-a-watt is a better option, with remote reading option also.
But I wanted to try this.
Version 2 !
It would be faster and less processor intensive to use an external event derived from the blinks and input it somewhere into the PC and log it with Processing.
I went for the “recycle way” and took apart an old mouse (well, no so old) and hooked the following circuit to the left mouse button : the light of the LED makes the TIL78-like phototransistor go into conduction which triggers an ever green NE555 (in the shape of a CMOS TLC555). The monostable in turn makes the NPN transistor close the relay which close the left mouse button of the mouse. Simple yet effective.
Side effect : the mouse can’t be used for anything else during count accumulation, otherwise the counts are affected, obvious. A dedicated external USB I/O device would solve the problem but this cost zero.
The purple wires are hooked to the coil of the relay inside the mouse.
The sketch for Processing for photo transistor version is here.
The sketch for Processing for the web cam version is here.
Have fun.
Alessandro
Update (21/03/09) : now this thing runs on Arduino also, read at bottom.
This is a simple project of a sundial wherein the pinion is replaced by a line LASER I took from a LASER level. The LASER is mounted on a RC servo which in turn is driven by a micro controller. The micro controller keeps the time and turns the RC servo accordingly.
Very basic in design it does exactly what I wanted and has as few parts as I could.
The micro controller is an Atmel Attiny24 with crystal for better accuracy. The internal RC oscillator could be calibrated but in the end the precision can be achieved from a crystal quartz only.
The schematic is very simple, just the micro with crystal and capacitors, the LASER and the transistor necessary to drive it, the servo. The power supply comes from a 5Volt wall adapter.
The micro controller runs a real time clock. Time is converted into minutes from 1:00 hours and converted in PWM pulse which is suitable to drive an RC servo. The source code is well commented, I’d say, and can be easily followed to understand how it works. In case, just comment and ask.
J4 is necessary to program the micro with the In Circuit Serial Programming faciliy like the one provided by the AVR Dragon debugger. If you have the micro already programmed (by a friend, say) you don’t need to mount that. Just be careful not to leave unconnected the R2, J2 and Pin 7 node also…
Upon power on the servo swings from about mid position of the sundial to 1:00 hours. Short pins 5-6 of J1 to make the sundial advance 1 hour at a time. Let it go a few times from 1:00 to 12:00 to see the rotation span. Then remove the short when the LASER points to the right hour.
To set the minutes it might be easier to set the time at the exact hours as the minutes are set to 0 whenever hours are set. Otherwise just short pins 3-4 of J1 counting 2 every second and remove the short when at the correct minute.
Shorting pins 1-2 adds some life to the sundial and makes it count just the seconds. Hypnotic initially, then pointless.
Shorting pins 7-8 makes the LASER on continuously, otherwise it blinks every second, like in the video below.
The circuit and software can be modified to display different things like a voltage at an analog input of the micro making a LASER analog meter. Or to make something like a LASER chronulator.
More of these circuits can be superimposed to display different values on the dial.
This is a picture of the thing.
The servo I used is a Hitec HS-300BB, a pretty good one I happened to have in a drawer. Any other servo would do, the rotation span being probably a little bit different. It can be adjusted with the SERVO_MIN and SERVO_MAX defines but recompiling would be necessary.
I did not use a PCB, I actually built an UV bed to make PCBs but I never get to the point of actually making one…in case : http://www.instructables.com/id/The-return-of-the-dead-flatbed-scanner/
The pictures show how I attached the LASER to the RC servo : an L-shaped piece of Aluminum, a few tiny screws and a teflon fastener did the job easily. The tricky part is to make the lower end of the LASER line aligned with the center of the rotation of the servo. Anyways, misalignment might give some interesting visual effects when the LASER line does not rotate along one of its end but around a point somewhere in between like the hand of a speedometer. Just experiment.
The software.
It is written in C and compiled and debugged in AVR Studio. I debugged the code with the AVR Dragon which uses the In-circuit debugging capabilities of the ATTiny24.
The code is commented and should be readable and modifiable as desired in any case a few comments follow.
#define F_CPU 2457600UL // crystal frequency
#define PWM_TOP F_CPU/60 // == 40960 is TOP count for timer 0 (goes into OCR0A)
These pre-compiler instructions define the frequency of the crystal and the value to the placed in the OCR1A register which is going to be the maximum count for timer1 before resetting to zero. We want the PWM frequency to be 60Hz. We are using these 60Hz pulses as the time base for the real time clock also.
The following lines set up Timer1 with fast PWM, no prescaler (that is, the crystal frequency goes straight into Timer1), and PWM compare output is on OC1B pin (read on)
TCCR1A = _BV(WGM11) | _BV(WGM10) | _BV(COM1B1);
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);
OCR1A = PWM_TOP; // PWM freq = 60Hz
Timer1 now runs from 0 to PWM_TOP which happens 60 times every second (2457600/40960)
The instructions above also make the output pin OC1B high when the counter is below OCR1A and zero otherwise (PWM compare). This is PWM : changing the value in OCR1B from 0 to PWM_TOP makes the duty cycle output from 0% to 100% at the PWM frequency which do not change : 60 pulses every second, the pulses are simply thinner or larger.
The exact meaning will more clear when checked with the datasheet of the ATTiny24.
The following instruction places the servo at OCR1B output halfway between the maximum and minimum position of the servo.
OCR1B = (SERVO_MAX + SERVO_MIN) / 2;
This is not 50% PWM duty cycle, as the servo does rotate from min to max with pulses smaller than 50%, that’s why I defined SERVO_MAX and SERVO_MIN based on the the length of the pulses that place the servo at maximum or minimum:
#define SERVO_MAX PWM_TOP*1.65/(1000/60) // max rotation is at 2.35ms pulse
#define SERVO_MIN PWM_TOP*0.75/(1000/60) // min rotation is at 0.70ms pulse
Now I want the timer overflow to be used also as the timebase for the real time clock :
TIMSK1 = _BV(TOIE1); // enable timer overflow (for real time clock)
sei(); // enable global interrupts
Now every 1/60th of a second the following routine is called :
ISR(TIM1_OVF_vect) { … }
This routine does a number of things :
It counts the real time, 60 times1/60th of a second makes one full second elapsed, so the counter of seconds is incremented together with minutes and hours if required.
It also blinks the LASER for 1/10th of a second every second unless the relevant pin short strips shorted,in which case the LASER is always on.
This routine evaluates also the position to be given to the servo to make it rotate as needed. To do so the time is converted into total minutes elapsed from time 1:00 and the result scaled into the range SERVO_MIN to SERVO_MAX.
servo_pos = servo_min + ((hour-1)*60+min)*((servo_max-servo_min)/(11*60+59));
Shorting JUMP_0 makes the servo display the seconds only (9 to 59) thus the calculation as of above is made on current seconds only and minutes/hours disregarded :
servo_pos = servo_min + sec*((servo_max-servo_min)/59);
The following places the servo in the mirror position to make the LASER rotate clockwise :
OCR1B = servo_min+servo_max-servo_pos; // clockwise
// OCR1B = servo_pos; // counter clockwise (commented out)
If needed the first line can be commented out and the double ‘//’ removed from the second line : this would make (after compiling and downloading to the micro) the servo run counter clockwise.
Finally the routine also checks pin short strips for time set and sets hours and minutes if required. Minutes advance 1 every half a second while hours once per second. Removing the shorts resume regular clock display.
If you are going to modify the and recompile with AVR Studio with AVRGCC, the C compiler, don’t forget to set the fuses to External Crystal mode 0.9 to 3MHz, no watchdog, x8 clock divider disabled. All other fuses should be default.
You can see a video of the sundial below. Please trust me when I say that the light pulses much better than in the video : the bad flicker or disappearing light is just caused by low frame rate, poor camera ( and poor operator ? ). I should have shot the video with the LASER always on. Now I removed the roman lettering from my living room as my sweet half was showing some impatience.
Finally, this is a picture of a real sundial built around 1930 at Tripoli, Libya, I saw recently. Far better than the ones I used to improvise on summertime when I was a kid and didn’t mind melting under the Summer sun.
For questions or comments or anything else, just write, If you build your own, send pictures.
The hex file ready to be burnt into the microcontroller is here, the C source code is here.
The schematic for Arduino is herebelow, click for a larger view (on Flickr) :
The sketch needs the MsTimer2 library you can download from Arduino playground.
…and this one is the sketch to be loaded on Arduino.
Ciao
Alessandro
This a simple circuit I designed and built to convert light variations into sound. It is fun to listen to the weird sound emitted by the light of remote controls, light bulbs, TV screens and any light source.
The circuit is very simple and is based and pretty well known building blocks : a pin photodiode amplifier (U1A) converts current variations in the photodiode into voltage variations at the output of U1A. R1 is a small potentiometer used to set the gain of the current to voltage converter. Too high the gain and the amp saturates with no output, too low and no output will be heard.
The amplifier is based on a common LM358 but any other device suitable for single supply with same pinout should do.
R2 sets the volume while U2 is the amplifier based on the well know LM386 : I actually used a different amplifier, a TDA2822 which happens to be a stereo amplifier found in PC speakers. I decided to put the LM386 in the schematic because it is probably easier to find.
This is the schematic.
I tried a few photodiode I took from various devices. A few are mostly sensitive to infrared, but I ended using a visible light PIN photodiode, the BPW34 which is pretty common and cheap.
The cathode of the PIN diode is marked by a small tab on one of the two diode’s leads.
The whole device can be built on a small piece of perfboard and the output can feed a pair of head phones or a small speaker. PC speakers could replace the amplifier stage but at the cost of portability. The circuit would easily fit into an Altoids tin box.
The use is immediate, just put the battery on and play with the gain and volume while pointing not directly to a light bulb : you should hear a strong buzzing noise (the 50/60 Hz mains), then try any TV (CRT or LCD), any remote control or flame.
The photodiode amplifier was not originally designed for this gadget but is intended to be part of a supercool circuit I’m working on and that hopefully will end one of these days centuries.
And this is a video. sorry for the dim light but it is evening now and I wanted to do it NOW !
I could not use regular AC (110/220Vac) light as it would have caused a strong hum.
UPDATE : Derek of Umatic/Tonewheels designed a PCB for the circuit. See his site for details.
Thank you, Derek, for sharing.
For now, have fun.
Alex.
















