Good morning everyone,
I am very new to Arduino, and have been given a project that, from what I see, requires years of experience. Basically I need to calculate how much water is flowing through a pipe. I am using a _______ Flow meter, that produces pulses from what I understand. I have done the wiring from an outlet to a converter, which drops the voltage down from 110 volts to 24 volts. I than wired the PulseOut wire to drop to 5 volts to be plugged into the arduino Leonardo that I am using.
I guess my question is how can I write a program to "count" the pulses per sometime? I did a lot of reading on the forum the last couple of days and still cannot piece together a code that will allow me to count the pulses, which I can than convert to gallons per minute. I am assuming I will have to use some interrupts, or pulseIn functions, and use the PWM ports. I just do not understand how they piece together.
And maybe I am having troubles connecting to the correct ports to read pulses. Do I use PWM ports or serial data ports or another? I am very confused.
Here is a small code I pieced together, that I thought might work, but turned out it did not.
/*
* HardwareCounting sketch
*
* uses pin 5 on 168/328
*/
const int hardwareCounterPin = 5; // input pin fixed to internal Timer
const int ledPin = 13;
const int samplePeriod = 5000; // the sample period in milliseconds
unsigned int count;
int calc;
#include <LiquidCrystal.h>
#include <Wire.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
// hardware counter setup (see ATmega data sheet for details)
TCCR1A=0; // reset timer/counter control register A
lcd.begin(16, 2);
// Print a message to the LCD.
}
void loop()
{
digitalWrite(ledPin, LOW);
delay(1000);
digitalWrite(ledPin, HIGH);
// start the counting
bitSet(TCCR1B ,CS12); // Counter Clock source is external pin
bitSet(TCCR1B ,CS11); // Clock on rising edge
delay(samplePeriod);
// stop the counting
TCCR1B = 0;
count = TCNT1;
TCNT1 = 0; // reset the hardware counter
if(count >= 0)
calc= (count);
Serial.print (calc, DEC);
Serial.println(" Pulse\r\n");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(calc, DEC);
lcd.println(" Pulse\r\n");
}
Thank you guys/girls for any help!
Zack