Page 1 of 1
Gasmeter (Battery powered) sketch needed
Posted: Monday 07 December 2015 22:05
by macieiks
Hi guys,
I am trying to find working gasmeter sketch for Arduino MySensors.org project. To be honest I do not have any option to provide constant power to the location where my gas meter is installed, so I need to stick with battery solution. I would like to ask if there is anyone who has the sketch for gas counting purposes? I would be very grateful for sharing
Cheers,
Maciek
Re: Gasmeter (Battery powered) sketch needed
Posted: Tuesday 08 December 2015 17:23
by alexsh1
Do you need the real time consumption? If yes, you'd better buy two battery 18650 banks (or make them) as your arduino (or atmega) has to stay awake to count time - this is about 40mA. I have currently a similar problem waiting for a PCB 240V PSU from China, while providing power to arduino nano with two 18650 (3.7V x 2, 3400mAh). I have to change batteries every 3-4 days. This is OK for the time being, but this is not a long term scenario.
You may want to stick to some ready made products like z-wave NorthQ (
http://northq.com).
Re: Gasmeter (Battery powered) sketch needed
Posted: Tuesday 08 December 2015 19:08
by macieiks
I will use big powerbanks. Right now I just need to obtain sketch for GasMeter. Do you have any test one?

Re: Gasmeter (Battery powered) sketch needed
Posted: Wednesday 09 December 2015 11:59
by alexsh1
macieiks wrote:I will use big powerbanks. Right now I just need to obtain sketch for GasMeter. Do you have any test one?

No, I do not have a gas meter. However, if you have a modern gas meter, you should take a pulse count sketch from MySensors. This would be your starting point.
Please see also
viewtopic.php?f=14&t=4724
viewtopic.php?f=14&t=1641
and
http://openenergymonitor.org/emon/build ... monitoring
Please see the following device monitoring gas in Domoticz, but it is not based on MySensors lib
https://github.com/equinoxefr/gasMonitor
Re: Gasmeter (Battery powered) sketch needed
Posted: Wednesday 09 December 2015 12:08
by alexsh1
Just found this sketch on my hard drive, which is based on emontx (openenergymonitor). It is based on RFM12B though
I hope if helps
Code: Select all
/* Gas pulse count - low power
Gas (kWh) - take the number of gas units used (nb meter readings ignore last 2 dials so 100 pulses)
For imperial meter:
X by 2.83
X by calorific value for the period
gasCalVal for Aug-Dec 2013 = 38.88
X correction factor (1.022640)
Divide by 3.6.
100 pulses = (2.83 * 38.88 * 1.022640) / 3.6 = 31 KWh
0.31 pulses = 1KWh
Pulses per watt hour = 0.31/1000 = 0.00031
*/
#include <avr/power.h>
#include <avr/sleep.h>
#include <JeeLib.h>
#include <avr/wdt.h>
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
#define frequency RF12_433MHZ // RF12_433MHZ, RF12_868MHZ or RF12_915MHZ
#define node 7 // RFM12B node ID - gas is on 7 - 4 for testing
#define group 210 // RFM12B wireless network group 210 usual (212 weather)
const int UNO = 1; // Set to 0 if your not using the UNO bootloader (i.e using Duemilanove) - All Atmega's shipped from OpenEnergyMonitor come with Arduino Uno bootloader
typedef struct {
int16_t power;
int16_t pulse;
int16_t battery;
} PayloadTX;
PayloadTX rf_data;
// Set up bits
const byte LEDpin = 9;
const byte debug = 0; // set to 1 for debug info
const long time_between_readings = 100000; // 100K is about 120secs in low-power mode
// Pulse counting settings
long pulseCount = 0; // Number of pulses, used to measure energy.
unsigned long pulseTime; // Current pulse time
unsigned long lastTime; // Last pulse time
double elapsedWh;
double power;
const double ppwh = 0.00031;
void setup()
{
Serial.begin(9600);
if (debug ==1)
{
Serial.println("Gas pulse imperial meter - 1 cubic foot per pulse");
}
delay(100);
rf12_initialize(node, frequency, group); // initialize RF
rf12_sleep(RF12_SLEEP);
pinMode(LEDpin, OUTPUT); // Setup indicator LED
//digitalWrite(LEDpin, HIGH);
//digitalWrite(3, HIGH); // Set pull up resistor on
attachInterrupt(1, onPulse, FALLING); // IRQ 1 = D3
flashLED(50);
delay(100);
flashLED(50);
power_twi_disable();
power_adc_disable();
//power_spi_disable();
}
unsigned long last_rf;
//Main Program Loop.
void loop()
{
unsigned long time_since_last_rf = millis()-last_rf;
if (debug ==1)
{
Serial.print("Time since last TX "); Serial.println(time_since_last_rf); Serial.println();
delay(50);
}
if (time_since_last_rf >= time_between_readings) // If equal or greater than time between readings since the last tx then send the current values over RF.
{
rf_data.pulse = pulseCount; pulseCount=0;
rf_data.battery = readVcc();
send_rf_data(); // SEND RF DATA
last_rf = millis();
time_since_last_rf = 0;
if (debug == 1)
{
Serial.println("Data just sent was:");
Serial.print("Power: "); Serial.print(rf_data.power); Serial.println("W");
Serial.print("Number of pulses: "); Serial.println(rf_data.pulse);
Serial.print("Battery: "); Serial.print(rf_data.battery); Serial.println("mV");
Serial.println();
flashLED(10);
}
}
unsigned long backtosleep = (time_between_readings-time_since_last_rf); // Calculate the time the MCU needs to go back to sleep for
if (debug == 1)
{
Serial.print("Going to sleep for "); Serial.println(backtosleep);
delay(50);
}
Sleepy::loseSomeTime(backtosleep); // Put the MCU into low power mode.
}
// The interrupt routine - runs each time a falling edge of a pulse is detected
void onPulse()
{
lastTime = pulseTime; // Time between pulses.
pulseTime = micros();
pulseCount++; // Pulse counter
rf_data.power = double((3600000000 / (pulseTime - lastTime))/ppwh); // Calculate power electricity
}
// Calculate MCU Voltage (mV).
long readVcc() {
power_adc_enable();
long result;
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result;
power_adc_disable();
return result;
}
void send_rf_data()
{
//power_spi_enable();
rf12_sleep(RF12_WAKEUP);
rf12_sendNow(0, &rf_data, sizeof rf_data); //send gas data via RFM12B using new rf12_sendNow wrapper
rf12_sendWait(2);
rf12_sleep(RF12_SLEEP);
//power_spi_disable();
}
void emontx_sleep(int seconds) {
for (int i=0; i<seconds; i++) {
delay(1000);
if (UNO) wdt_reset();
}
}
// LED flash
void flashLED(int msec)
{
digitalWrite(LEDpin, HIGH);
delay(msec);
digitalWrite(LEDpin, LOW);
}
Re: Gasmeter (Battery powered) sketch needed
Posted: Tuesday 15 December 2015 20:52
by macieiks
I just updated my Ethernet W5100 Gateway to beta 1.6.0 and I modified "WaterPulseSensor" to support V_GAS - present(CHILD_ID, S_GAS) and it is working...

Right now I am testing it on my desk but I will try this weekend to attach magnet sensor to my gas meter
Cheers
Re: Gasmeter (Battery powered) sketch needed
Posted: Wednesday 16 December 2015 10:30
by D'rMorris
Moved the topic to Mysensors subforum to keep Mysensors related topics together.
Re: Gasmeter (Battery powered) sketch needed
Posted: Monday 22 August 2016 17:44
by markk
Hi I didn't want to start a new thread as I'm in need of a sketch to measure gas too. I'm using the watermeter sketch which is collecting data but the values are incorrect. I have an old schlumberger gas meter which measures gas usage in one pulse per cubic foot foot gas and I don't know how to amend the sketch to show this in cubic meters of KWh. I've asked on the my sensors forum but now had a reply. I'd be grateful for a nudge in the right direction please.