--- layout: post title: Gas meter update date: 2013-01-01 17:59:09.000000000 +01:00 type: post parent_id: '0' published: true password: '' status: publish categories: - Domotica tags: - arduino - gasmeter - IN-Z31 meta: _edit_last: '1' views: '8321' has_been_twittered: 'yes' author: login: admin email<EMAIL_ADDRESS>display_name: Mosibi first_name: Richard last_name: Arends ---
Yesterday I blogged about getting information from our gas meter with an Arduino that reads the reed switch. After using this setup for many hours, we noticed that our counter was not accurate. My first suspect was the IN-Z31 reed switch, it looked like the switch sometimes stayed closed for a very long time. To get more information, I changed the code so that when the sensor port changes to HIGH (1), I start an other function that checks for how long (in milliseconds) the switch stays closed.
Luckily, soon after changing the code and monitoring the serial (debugging) output, the gas meter stopped exactly at the digit 9 and the CountStateDuration() function showed me that the switch stayed closed. Yesterday we already noticed that we got a pulse every time when the digit 9 was shown, so that the switch stayed closed at 9, was not a very big surprise.
Now we learned that, I modified the code. In the loop() it calls the function CheckSwitch() which returns a 0 if the switch is open (not making contact). If the switch is closed, thus making contact, the function CountStateDuration() is called to check how long the switch is closed. This function returns when the switch is open again, resulting in a counter update.
The LCD screen now shows the real counter, but to get that right, you need to set the current reading before starting the Arduino. The new code can be downloaded here.


hello my name is allison vicenzi, also known as allievice. i am a curious generalist living and working between brooklyn and hong kong. if this website looks like it's from 1997, that's because i'm building it myself in due time. about.me