Hi All,
I am attempting to create a data logger that reports flow rate from a hall effect flow sensor to an online database using a GSM shield. I have gotten the flow sensor code to work and gotten the GSM code to work, but I have started to combine them and have run into the issue that both the GSM shield and the flow sensor need the interrupt function on pin 2. I went to go move the flow sensor to pin 20 on the mega, but now my flow sensor code won't even work.
If I plug the flow sensor into pin 2 and program the mega to read pin 20 for the flow sensor it works, but when I plug the flow sensor into pin 20 it does not work. The code I am using to read the flow sensor is attached.
Thanks so much for your help!
Ian
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com
volatile int NbTopsFan; //measuring the rising edges of the signal
float Calc;
int hallsensor = 20; //The pin location of the sensor
float d=0; //my summation variable
void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
// The setup() method runs once, when the sketch starts
void setup() //
{
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised,
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan/(5.5*60)); //(Pulse frequency x 60) / 5.5Q, = flow rate in L/hour
d=d+Calc;
Serial.print ("Flow Rate[L/hr]:");
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print ("\r\n");
Serial.print ("Total Flow[L]:");
Serial.print (d, DEC); //Prints the number calculated above
Serial.print ("\r\n");
}
Flow.ino (1.53 KB)