Quantcast
Channel: ThingSpeak IoT Community - All Forums
Viewing all articles
Browse latest Browse all 1833

wheato22 on My Water Meter Reading App Communication with ThingSpeak

$
0
0

I've about given up trying to get my water meter reader app to upload data to my ThingSpeak channel using Arudino and a wired Ethernet shield. Being a non-programmer I have tried to use published examples designed for analog inputs to work with my interrupt driven app. I have tried co cobble my app into both the HTTP POST and and ThingSpeak.write Voltage Examples. In both cases compile errors have dogged me to submission. If anyone can suggest some upload code that will play nicely with my interrupt driven counter code (below) and pave the way to upload my serial.print output to channel 1 I'd appreciate the help . ThingSpeak seems like a perfect way to visualize water use in real time... Particularly here in the western US, water use allocations are in effect .
/* Water Meter Flow Application---- authored by L. Wheaton, 2015
* Sub-meter outputs a pulse every gallon of flow
* Hall device connected to digital pin 2 creates interrupt
* Interrupt handler increments gallon counter
* accumulated gallon count print and uploads every 20 seconds
*/
byte sensorInterrupt = 0;
byte sensorPin = 2;
volatile byte pulseCount;
unsigned int gallons;
unsigned long oldTime;

void setup(){
Serial.begin(9600);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
void loop()
{
// Sets xmit every 20 seconds
if((millis() - oldTime) > 20000)
{
// Disable interrupts while calculating
detachInterrupt(sensorInterrupt);
oldTime = millis();
gallons = (gallons + pulseCount);
// Prints gallon flow and Total
Serial.print("Pulse: ");
Serial.print(pulseCount);
Serial.print(" Gallons: ");
Serial.println(gallons);
pulseCount = 0;
// Enable interrupts again
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
}
// interrupt handler
void pulseCounter()
{ pulseCount++;
}


Viewing all articles
Browse latest Browse all 1833

Trending Articles