almost got the water meter now... <br><br>just need to figure how many pulses pr liter water and how to make it reset to 0 after each time it has reported in a value... <br><br>complete sketch in case attachments are not allowed:<br>
<br><br><br>/*<br>  emonTX water meter Example <br> <br>  Part of the <a href="http://openenergymonitor.org">openenergymonitor.org</a> project<br>  Licence: GNU GPL V3<br> <br>  Authors: Glyn Hudson, Trystan Lea<br>  Builds upon JeeLabs RF12 library and Arduino<br>
<br>  THIS SKETCH REQUIRES:<br><br>  Libraries in the standard arduino libraries folder:<br>    - JeeLib        <a href="https://github.com/jcw/jeelib">https://github.com/jcw/jeelib</a><br>     <br>*/<br><br>#define freq RF12_868MHZ                                                // Frequency of RF12B module can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have.<br>
const int nodeID = 2;                                                  // emonTx temperature RFM12B node ID - should be unique on network<br>const int networkGroup = 210;                                           // emonTx RFM12B wireless network group - needs to be same as emonBase and emonGLCD<br>
<br>const int time_between_readings= 5000;<br><br>#include <JeeLib.h>                                                     // Download JeeLib: <a href="http://github.com/jcw/jeelib">http://github.com/jcw/jeelib</a><br>
#include <avr/sleep.h><br>ISR(WDT_vect) { Sleepy::watchdogEvent(); }                              // Attached JeeLib sleep function to Atmega328 watchdog -enables MCU to be put into sleep mode inbetween readings to reduce power consumption <br>
<br>typedef struct { int water; int battery; } Payload;<br>Payload emontx;<br><br>long pulseCount = 0;<br>unsigned long pulseTime,lastTime; // Used to measure time between pulses<br>double water;<br>int ppl = 1;                     // pulses per liter - figured by filling a 10 liter bucket and divide by 10.<br>
<br><br>void setup() {<br>  Serial.begin(9600);<br>  Serial.println("emonTX water meter example"); <br>  Serial.println("OpenEnergyMonitor.org");<br>  Serial.print("Node: "); <br>  Serial.print(nodeID); <br>
  Serial.print(" Freq: "); <br>  if (freq == RF12_433MHZ) Serial.print("433Mhz");<br>  if (freq == RF12_868MHZ) Serial.print("868Mhz");<br>  if (freq == RF12_915MHZ) Serial.print("915Mhz"); <br>
  Serial.print(" Network: "); <br>  Serial.println(networkGroup);<br>  <br>  // pulse detection interrupt (emontx pulse channel - IRQ0 D3)<br>  attachInterrupt(1, onPulse, FALLING);<br> <br>  rf12_initialize(nodeID, freq, networkGroup);                          // initialize RFM12B<br>
  rf12_control(0xC040);                                                 // set low-battery level to 2.2V i.s.o. 3.1V<br>  delay(10);<br>  rf12_sleep(RF12_SLEEP);<br><br>}<br><br>void loop() <br>{ <br>  emontx.water=water;<br>
  emontx.battery=readVcc();<br>  rf12_sleep(RF12_WAKEUP);<br>  // if ready to send + exit loop if it gets stuck as it seems too<br>  int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}<br>  rf12_sendStart(0, &emontx, sizeof emontx);<br>
  // set the sync mode to 2 if the fuses are still the Arduino default<br>  // mode 3 (full powerdown) can only be used with 258 CK startup fuses<br>  rf12_sendWait(2);<br>  rf12_sleep(RF12_SLEEP);  <br>  Sleepy::loseSomeTime(time_between_readings);<br>
  <br>  <br>  Serial.println(pulseCount * ppl);  // watt hour elapsed<br>  <br>  <br>}<br><br>long readVcc() {<br>  long result;<br>  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);<br>  delay(2);<br>  ADCSRA |= _BV(ADSC);<br>
  while (bit_is_set(ADCSRA,ADSC));<br>  result = ADCL;<br>  result |= ADCH<<8;<br>  result = 1126400L / result;<br>  return result;<br>}<br><br>// The interrupt routine - runs each time a falling edge of a pulse is detected<br>
void onPulse()                  <br>{<br>  lastTime = pulseTime;<br>  pulseTime = micros();<br>  pulseCount++;                                               // count pulse               <br>  water = int((3600000000.0 / (pulseTime - lastTime))/ppl);  // calculate power<br>
}<br><br><br><br>