Jump to content

How to count light flashes?


Recommended Posts

I'm building a water, gas and electricity monitor. It uses a Hall effect bricklet to monitor the gas meter and a line bricklet for the water meter. I was originally planning to use the Hall effect bricklet to monitor the electricity too, but that doesn't work.

The electricity meter does have a little light that flashes once every consumed Wh. Which bricklet can I use to count these flashes?

Link to comment
Share on other sites

Maybe if you put the ambient light bricklet in a small box in front of the light without light influences from outside (in a dark cellar it wouldn't be a to big problem) you would be able to measure the change. This depends from the brightness of the light.


Another way would be the line bricklet. I think there is some disk that spins around with a mark. The line bricklet might be able to detect this mark and this way you could count. Maybe an image of the electricity meter would help.

Link to comment
Share on other sites

Thank your for the suggestion. I have ordered the ambient light bricklet and I hope it works.


Ok, so in the interest of full disclosure I took a picture of all the meters.

First of all the gas meter. It has a little magnet at the least significant digit. Every revolution (10 liters of gas) it passes the Hall effect bricklet which measures it perfectly. This is accurate enough for me.



Second, the water meter. I cannot measure it with a Hall effect bricklet. I have tried it at every possible angle, at the sides, at several places directly at the display, but nothing works. Either the meter lacks a magnet, it is shielded too well, or the magnet is so weak that it does not trigger the bricklet.


However, as you can see in the lower left hand side there is an orange and reflective circle. This rotates when water is used and can be accurately measured with the line bricklet.


Finally, the electricity meter.


The Hall effect bricklet does not pick up any magnets. I think it is shielded pretty well anyway to avoid someone stopping it with very strong magnets which (I'm told) you could do with old meters. Ironically, it uses the Hall effect internally to measure the kWh.

To the right of the counter there are two small slits where you can see an indicator for each 100 Wh. However, it is so small and it moves so slowly that I doubt that line bricklet can reliably measure anything. Also, I would need two bricklets.

The green light below the 'II' indicates that we currently use electricity in the cheaper night tariff. The light below the 'I' will be on during the day when electricity is more expensive. In between these is a red light that flashes every time 1 Wh is used.

So, I have ordered the ambient light sensor. I hope that the light is bright enough and that the bricklet is sensitive enough and has a good enough time resolution to measure the very short flashes. It is pretty dark in the closet, so I think it is doable.

Link to comment
Share on other sites

  • 2 weeks later...

So, I got the ambient light bricklet in the mail today. I've installed it and it works!

It detects the light flashes perfectly. The only problem I ran into while testing is that the brickv application doesn't show all the peaks in the graph. Every fourth peak (on average) was not shown. This was caused by the coarseness of the graph, but it took me some time before I figured that out.

I created a small Python program to circumvent it and this gives excellent results.

Some sample output:

2014-04-09 21:19:15.255840 606
2014-04-09 21:19:34.097004 605
2014-04-09 21:19:52.836242 86
2014-04-09 21:19:52.902993 524
2014-04-09 21:20:11.370262 589
2014-04-09 21:20:11.370496 22
2014-04-09 21:20:29.802077 605
2014-04-09 21:20:48.748790 342
2014-04-09 21:20:48.806679 265
2014-04-09 21:21:07.022236 187
2014-04-09 21:21:07.122781 425
2014-04-09 21:21:25.609240 597


So, I still got some work to do in filtering the output but I'm pretty confident that I can get it done.

Link to comment
Share on other sites

  • 1 month later...

Hi guys,


I also played with the idea of tracking electricity usage with a Line Bricklet. I bought the bricklet, hooked it up, and gazed at the nice pulse every time the wheel went round..


But if you have limited leisure time, there's also the YouLess (Google). I bought it, and 30 minutes later I had my solution.


This doesn't work for gas/water, so I'm still planning to spend the days getting those meters tracked with a Tinkerforge solution. But in the mean time, that YouLess solution is hitting a very sweet spot.

Link to comment
Share on other sites

  • 2 weeks later...

Hi all,


This weekend, I managed to work a little on measuring gas, electricity and water usage. Based on the rugged example from Tinkerforge I wrote a little explorative python script. It is on Github. It is not well documented or properly written, but it works.


The setup is pretty simple. I have a master brick with a connected Ethernet brick and three sensors (line, hall and ambient light). The line bricklet is used for measuring water consumption, the hall for gas and the ambient light for electricity.

The hall bricklet was the easiest. Every time it sees a magnet pass by, it does a callback to the computer running the python scrip. I know that every rotation corresponds to 10 liters of gas (or 0.01m3).

The ambient light bricklet was a little more difficult. As I said in an earlier post which matthiku also referred to, just getting a callback when the ambient light crosses some threshold won't work. I won't get into too much detail, but you will either get multiple callbacks due to the duration of the light flash or when you set the threshold too high, you will miss some flashes.

I solved this by assuming that two separate flashes will be at least 400 ms apart (the debounce period). This solves the problem as you can see in the table below.

2014-06-01 12:52:00.114766 - 1 Wh
2014-06-01 12:52:09.664464 - 1 Wh
2014-06-01 12:52:19.216056 - 1 Wh
2014-06-01 12:52:28.765721 - 1 Wh
2014-06-01 12:52:38.366049 - 1 Wh
2014-06-01 12:52:47.916696 - 1 Wh
2014-06-01 12:52:57.467214 - 1 Wh
2014-06-01 12:53:07.117634 - 1 Wh


The line bricklet was more complicated. If you look at the graph of the reflectivity, you can see that there are two different minimums.


What happens in the code is that we wait until we reach a maximum or minimum. Then we change the callback for the opposite. If the callback for the maximum is followed by the callback for the minimum, then we know that 100-mL (0.0001m3) is used (we wait for the falling flank).

def cb_line(self, *args, **kwargs):
    state = self.line.get_reflectivity_callback_threshold()
    if state[0] == Line.THRESHOLD_OPTION_SMALLER:
        print('{} - 0.0001m3 water'.format(datetime.now()))
        self.line.set_reflectivity_callback_threshold('>', 3900, 0)
    elif state[0] == Line.THRESHOLD_OPTION_GREATER:
        self.line.set_reflectivity_callback_threshold('<', 3880, 0)


When I turn on the hot water, then I get something like this:

2014-06-01 13:08:06.897621 - 0.0001m3 water
2014-06-01 13:08:10.665532 - 1 Wh
2014-06-01 13:08:15.774149 - 0,01m3 gas
2014-06-01 13:08:18.315497 - 1 Wh
2014-06-01 13:08:18.429275 - 0,01m3 gas
2014-06-01 13:08:21.208779 - 0.0001m3 water
2014-06-01 13:08:25.915624 - 1 Wh
2014-06-01 13:08:28.496903 - 0,01m3 gas
2014-06-01 13:08:31.145113 - 0,01m3 gas
2014-06-01 13:08:33.566193 - 1 Wh
2014-06-01 13:08:35.652654 - 0.0001m3

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...