Ir ao conteúdo
  • Cadastre-se

Programação Sensor de Fluxo Arduição


rafaelcruz50

Posts recomendados

Olá

Estou desenvolvendo meu TCC com a ajuda do arduino, no mesmo existe um processo de controle de água a partir de um sensor de fluxo de água próprio para o arduino.

a intenção com o projeto é fazer um hidrometro digital que calcule o volume de agua que a residência consome.

O sensor já vem com o seguinte programa:

[COLOR="Blue"]volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2; //The pin location of the sensor

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 * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate

in L/hour
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
}[/COLOR]

Alguém poderia me ajudar explicando como ele acha a formula:Calc = (NbTopsFan * 60 / 7.5)

e se é possivel com este programa calcular apenas o volume já que o que ele está calculando é o valor do fluxo.

Muito obrigado!

Link para o comentário
Compartilhar em outros sites

bom vou tentar ajudar... pelo o que li em outros foruns a formula é a frequencia contabilizada em minutos * 60 minutos de 1 hr / 7.5 esse 7.5 pelo o que eu entendi é a variável dada para calibragem da resposta creio que depende do equipamento e tenha haver com as pás e a distancia de leitura, algo assim.

segue outro codigo pra ti dar um olhada... esse é de um sensor que eu comprei não testei ele ainda...ele utiliza LCD creio que vai te ajudar


* Water Flow Gauge
*
* Uses a hall-effect flow sensor to measure the rate of water flow and
* output it via the serial connection once per second. The hall-effect
* sensor connects to pin 2 and uses interrupt 0, and an LED on pin 13
* pulses with each interrupt. Two volume counters and current flow rate
* are also displayed on a 2-line by 16-character LCD module, and the
* accumulated totals are stored in non-volatile memory to allow them to
* continue incrementing after the device is reset or is power-cycled.
*
* Two counter-reset buttons are provided to reset the two accumulating
* counters. This allows one counter to be left accumulating indefinitely
* as a "total" flow volume, while the other can be reset regularly to
* provide a counter for specific events such as having a shower, running
* an irrigation system, or filling a washing machine.
*
* Copyright 2009 Jonathan Oxer <[email protected]>
* Copyright 2009 Hugh Blemings <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. [url]http://www.gnu.org/licenses/[/url]
*
* [url]www.practicalarduino.com/projects/water-flow-gauge[/url]
123456789abcdef
1239.4L 8073.4L
*/

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);

// Specify the pins for the two counter reset buttons and indicator LED
byte resetButtonA = 11;
byte resetButtonB = 12;
byte statusLed = 13;

byte sensorInterrupt = 0; // 0 = pin 2; 1 = pin 3
byte sensorPin = 2;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;

volatile byte pulseCount;

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitresA;
unsigned long totalMilliLitresB;

unsigned long oldTime;

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");

// Initialize a serial connection for reporting values to the host
Serial.begin(38400);

// Set up the status LED line as an output
pinMode(statusLed, OUTPUT);
digitalWrite(statusLed, HIGH); // We have an active-low LED attached

// Set up the pair of counter reset buttons and activate internal pull-up resistors
pinMode(resetButtonA, INPUT);
digitalWrite(resetButtonA, HIGH);
pinMode(resetButtonB, INPUT);
digitalWrite(resetButtonB, HIGH);

pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);

pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitresA = 0;
totalMilliLitresB = 0;
oldTime = 0;

// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

/**
* Main program loop
*/
void loop()
{
if(digitalRead(resetButtonA) == LOW)
{
totalMilliLitresA = 0;
lcd.setCursor(0, 1);
lcd.print("0L ");
}
if(digitalRead(resetButtonB) == LOW)
{
totalMilliLitresB = 0;
lcd.setCursor(8, 1);
lcd.print("0L ");
}

if( (digitalRead(resetButtonA) == LOW) || (digitalRead(resetButtonB) == LOW) )
{
digitalWrite(statusLed, LOW);
} else {
digitalWrite(statusLed, HIGH);
}

if((millis() - oldTime) > 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(sensorInterrupt);
//lcd.setCursor(15, 0);
//lcd.print("*");

// Because this loop may not complete in exactly 1 second intervals we calculate
// the number of milliseconds that have passed since the last execution and use
// that to scale the output. We also apply the calibrationFactor to scale the output
// based on the number of pulses per second per units of measure (litres/minute in
// this case) coming from the sensor.
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

// Note the time this processing pass was executed. Note that because we've
// disabled interrupts the millis() function won't actually be incrementing right
// at this point, but it will still return the value it was set to just before
// interrupts went away.
oldTime = millis();

// Divide the flow rate in litres/minute by 60 to determine how many litres have
// passed through the sensor in this 1 second interval, then multiply by 1000 to
// convert to millilitres.
flowMilliLitres = (flowRate / 60) * 1000;

// Add the millilitres passed in this second to the cumulative total
totalMilliLitresA += flowMilliLitres;
totalMilliLitresB += flowMilliLitres;

// During testing it can be useful to output the literal pulse count value so you
// can compare that and the calculated flow rate against the data sheets for the
// flow sensor. Uncomment the following two lines to display the count value.
//Serial.print(pulseCount, DEC);
//Serial.print(" ");

// Write the calculated value to the serial port. Because we want to output a
// floating point value and print() can't handle floats we have to do some trickery
// to output the whole number part, then a decimal point, then the fractional part.
unsigned int frac;

// Print the flow rate for this second in litres / minute
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("."); // Print the decimal point
// Determine the fractional part. The 10 multiplier gives us 1 decimal place.
frac = (flowRate - int(flowRate)) * 10;
Serial.print(frac, DEC) ; // Print the fractional part of the variable

// Print the number of litres flowed in this second
Serial.print(" "); // Output separator
Serial.print(flowMilliLitres);

// Print the cumulative total of litres flowed since starting
Serial.print(" "); // Output separator
Serial.print(totalMilliLitresA);
Serial.print(" "); // Output separator
Serial.println(totalMilliLitresB);

lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Flow: ");
if(int(flowRate) < 10)
{
lcd.print(" ");
}
lcd.print((int)flowRate); // Print the integer part of the variable
lcd.print('.'); // Print the decimal point
lcd.print(frac, DEC) ; // Print the fractional part of the variable
lcd.print(" L");
lcd.print("/min");

lcd.setCursor(0, 1);
lcd.print(int(totalMilliLitresA / 1000));
lcd.print("L");
lcd.setCursor(8, 1);
lcd.print(int(totalMilliLitresB / 1000));
lcd.print("L");

// Reset the pulse counter so we can start incrementing again
pulseCount = 0;

// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
}

/**
* Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
* handlers should be kept as small as possible so they return quickly.
*/
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}
 /**

*

water-flow-gauge-schematic.jpg

E quanto ao volume você tem a resposta em h então divide por 3600 vai dar a resposta em segundos que pelo o que entendi é o tempo da varedura ali... crie uma variavél e fique adicionando esse valor nela a cada segundo Volume = volume + volumesegundos porém precisa resetar essa variável volume quando for medir outra coisa através de um botão ou por mesmo mesmo ou quantidade de leitura.. ou desliga tudo e liga de novo rsrsrsrs

Link para o comentário
Compartilhar em outros sites

Então..

Eu tentei fazer isso que você falou, de dividir o valor do fluxo que o programa retorna por 3600, já que ele faz a leitura do sensor a cada um segundo, então eu acharia o volume por cada segundo.

Porém, quando faco isso, sempre obtenho a resposta "0.00", que não varia de jeito nenhum. Mesmo criando uma variável que vá somando os valores encontrados para acumular esse volume.

Como o valor é dado em litros, e o que eu estava medindo era bem pequeno, tentei também multiplicar por 1000, para ter o valor em ML, e evitar um erro de leitura em funcão da quantidade de casas decimais que ele mostra. Mas também não deu certo.

Quanto ao programa que você enviou, por algum motivo não consigo rodá-lo. Adaptei algumas coisas dele para o programa que veio no meu sensor de fluxo, que eu postei anteriormente, mas mesmo assim só consegui um valor aproximado do que eu estava, de fato, medindo, quando alterei a calibracão dele (o valor 7.5).

Acredito que isso esteja ocorrendo devido à velocidade do fluxo que está passando pelo sensor, que não é constante.

Mas, ainda assim, queria muito entender porquê a primeira opcão, de dividir o valor do fluxo por 3600 não está dando resultado nenhum. Pois, na minha concepcão, era para dar certo! Rs.

Muito obrigada pela resposta e pelas ideias!!!

Link para o comentário
Compartilhar em outros sites

Tente rodar ele com o programa original mostrando a vazao, o sensor que eu tenho é de 1/2" com leitura de 1a30 L/m, então o que te indico fazer é comprar essas bombinha de aquario (porém nao sei a vazao) para testar e assim depois implementar o outro programa pra ver como ele responde sabendo que esteja passando uma vazão dentro da leitura do sensor...

por que teoricamente o que eu falei ali era para ter funcionado hehehe eu não consegui mexer no meu ainda, e acho que vou ligar ele em um pic pois senao mato meu arduino para fazer apenas a leitura de fluxo e soar alarme...

Link para o comentário
Compartilhar em outros sites

Pois é, eu preciso que a minha fonte de água para o sensor seja contínua, para eu ter maior precisão na medida.

Eu adaptei o programa original que veio no meu sensor, modificando algumas coisas que achei relevante no programa que você enviou. Só estou com uma dúvida:

flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

oldTime = millis();

flowMilliLitres = (flowRate / 60) * 1000;

Na primeira linha de comando ele faz a diferenca de tempo contado até o momento em relacão à última medida que o sensor fez ( millis() - oldTime ) e depois vai atualizando sempre oldTime com este valor.

O que eu não entendo é porque ele faz 1000 dividido por esta diferenca, pois na terceira linha de comando que eu coloquei ali, ele já multiplica por 1000 para passar de litros para mililitros, e já divide por 60 para passar de minutos para segundos.

Então para que serve aquele 1000 ali na primeira linha de comando? Você sabe dizer?

Link para o comentário
Compartilhar em outros sites

ai tu complica... eu não fiz o programa e nem li ele direito... kkkkkk

mas enfim eu acho que ele ta referenciando esses 1000 com volume de 1 litro...

milisegundos com mililitros... que dai creio que a resposta vai ser dada em mililitros que seria mais precisa.... (que pelo meu sensor seria de 1000 a 30000.. 1 a 30L/min)

a primeira ele calcula e te dá a vazão, tanto que pede o tal de fator de calibração que deve ser aquele 7.5 lá da outra fórmula.

a segunda grava o tempo...

e a terceira te dá o volume..

mas como te disse para tirar a prova real e ver se tudo isso ai funciona era bom ter uma vazão constante e que tu pudesse medir visualmente.

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!