// 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
// Modificado por Jose David López A, Juan David López H, Alejandra Osorio O.
volatile int Contpulsos; //measuring the rising edges of the signal
float Q; // Caudal en lritos / seg
int hallsensor = 2; //The pin location of the sensor
float v; //Volumen en litros
float Sv; //Sumatoria de volumen en litros
int t = 1*1000; //Tiempo 1 seg (delay=1000)
void rpm () //This is the function that the interupt calls
{
Contpulsos++; //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 ()
{
Contpulsos = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (t); //Wait 1 second
cli(); //Disable interrupts
Q = (Contpulsos / (7.5*60)); //(Pulse frequency ) / 7.5Q, = flow rate in L/segundo
if (Q > 0)
{
v = (Q*t)/1000; // se divide en 1000 para pasar el tiempo de milisegundos a segundos
Sv = Sv+v;
Serial.print (Sv, DEC); //Prints the number calculated above
Serial.print (" litros\r\n"); //imprime volumen en litros (consumo de agua)
}
else
{
Sv = 0;
}
}
{
Contpulsos = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (t); //Wait 1 second
cli(); //Disable interrupts
Q = (Contpulsos / (7.5*60)); //(Pulse frequency ) / 7.5Q, = flow rate in L/segundo
if (Q > 0)
{
v = (Q*t)/1000; // se divide en 1000 para pasar el tiempo de milisegundos a segundos
Sv = Sv+v;
Serial.print (Sv, DEC); //Prints the number calculated above
Serial.print (" litros\r\n"); //imprime volumen en litros (consumo de agua)
}
else
{
Sv = 0;
}
}
No hay comentarios:
Publicar un comentario