I got only flow meter printings, but my temperatures are not printing together. the temperature only works when I put “*/” to isolate flow code.
int analogPin0 = 0; // lm35 está ligado a entrada analogica 0
int analogPin1 = 1;
int analogPin2 = 2;
int analogPin3 = 3;
int valAnalog0, valAnalog1, valAnalog2, valAnalog3 ; // variavel para armazenar o valor analogico lido
float T0, T1, T2, T3;
int tmp0, tmp1, tmp2, tmp3;
volatile int frequencia1;
volatile int frequencia2; //measuring the rising edges of the signal
float Q1, Q2;
int fluxo1 = 2; //The pin location of the sensor
int fluxo2 = 3;
void Hz1 () //This is the function that the interupt calls
{
frequencia1++; //This function measures the rising and falling edge of the hall effect sensors signal
}
void Hz2 ()
{
frequencia2++; //This function measures the rising and falling edge of the hall effect sensors signal
}
void setup()
{
Serial.begin(9600); // programa a serial para comunicação em 9600 bps
analogReference(INTERNAL); // passando de 5,0V para1 1,1V o sistema pra aumentar a resolução
pinMode(fluxo1, INPUT); //initializes digital pin 2 as an input
pinMode(fluxo2, INPUT);
attachInterrupt(0, Hz1, RISING); //and the interrupt is attached
attachInterrupt(1, Hz2, RISING);
}
void loop()
{
tmp0 = 0;
for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
valAnalog0 = analogRead(analogPin0); // Le o pino de entrada analogica 0
tmp0 = tmp0 + valAnalog0;
}
tmp1=0;
for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
valAnalog1 = analogRead(analogPin1); // Le o pino de entrada analogica 0
tmp1 = tmp1 + valAnalog1;
}
tmp2=0;
for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
valAnalog2 = analogRead(analogPin2); // Le o pino de entrada analogica 0
tmp2 = tmp2 + valAnalog2;
}
tmp3=0;
for(int x = 0; x <10; x++){ // o loop faz 100 leituras para diminuir os erros
valAnalog3 = analogRead(analogPin3); // Le o pino de entrada analogica 0
tmp3 = tmp3 + valAnalog3;
}
T0= (( 1.1 * tmp0 * 100.00) / 1024) / 10 ; // better to change readings to 2, 3, 5, 10, 15..
T1= (( 1.1 * tmp1 * 100.00) / 1024) / 10;
T2= (( 1.1 * tmp2 * 100.00) / 1024) / 10;
T3= (( 1.1 * tmp3 * 100.00) / 1024) / 10;
frequencia1 = 0; //Set frequencia1 to 0 ready for calculations
EIMSK = 3; //Enables interrupts
delay (3000); //Wait 3 seconds
EIMSK = 0; //Disable interrupts
Q1 = -7.0295319E-03 + 3.92917841E-02*frequencia1; // this equation have been linearized on that conditions: 3000ms acquisition time, (0,4 - 12,0)L/min. range, horizontal position sensor. fluid water. temp. 21C.
if (Q1<0) {
Q1=0;
}
frequencia2 = 0; //Set frequencia2 to 0 ready for calculations
EIMSK = 3; //Enables interrupts
delay (3000); //Wait 3 seconds
EIMSK = 0; //Disable interrupts
Q2 = -7.02295319E-03 + 3.92917841E-02*frequencia2;
if (Q2<0){
Q2=0;
}
Serial.print ("Qh= ");
Serial.print (Q1, 3); //Prints the number calculated above
Serial.print (" [L/min.] "); //Prints "L/min."
Serial.print ("Qc= ");
Serial.print (Q2, 3); //Prints the number calculated above
Serial.print (" [L/min.] ");
Serial.print("Thi= ");
Serial.print(T0,3); // Envia os dados pela porta serial
Serial.print(" [C] ");
Serial.print("Tho= ");
Serial.print(T2,3); // Envia os dados pela porta serial
Serial.print(" [C] ");
Serial.print("Tci= ");
Serial.print(T3,3);
Serial.print(" [C] ");
Serial.print("Tco= ");
Serial.print(T1,3);
Serial.println(" [C] ");
delay(500);
}