Flow Sensor Pulse Reading

Hello,

I am working on a project that calculates consumtion of an outboard engine for my boat using a flow sensor. It is this sensor and the OF05ZAT-AO in paricular.

I have a sketch that is used to calibrate the sensor. I pass one liter of water through it and see how many pulses it registers using interrupts.

However, although the datasheet mentions that the pulse rate is 0,46mL/P which means 2174 Pulses per Liter, when I run the sketch I only register 180 every time. x12 times less than normal.

I am unsing an old Arduino Duemilanove with a ATMega 328.

Here is the code, can you see something wrong with it?

//******************************************************
//     BT Fuel Manager Sensor Calibration Arduino 
//               sketch by MaleBuffy
//                21/6/2014
//******************************************************
//
//     Pin D4 for +5V for the Sensor 1
//     Pin D6 for GND for the Sensor 1
//     Pin D2 for Sensor 1 cable

#include <SoftwareSerial.h>// import the Arduino serial library 

volatile float PulseSensor=0; // Measuring the pulse from the sensor 1
int hall = 2;    // Sensor 1 Pin should be connected to Pin 2 of the Arduino
void incementpulse ()     //This is the function that incements the pulse counter. PulseSensor 1 
{ 
  PulseSensor++;  // Equals PulseSensor = PulseSensor + 1
} 

// Begin of Code. Setting pins up.

void setup() 
{ 
  pinMode(hall, INPUT); // Init Pin 2 to receive data from the Sensor
  digitalWrite(hall, HIGH); // Using Internal Pull up resistor to pin 2
  pinMode(4, OUTPUT); // Initializes digital pin 4 as an OUTPUT 
  digitalWrite(4, HIGH); // 5V to pin 4 (Flow Sensor)
  pinMode(6, OUTPUT); // Initializes digital pin 6 as an OUTPUT 
  digitalWrite(6, LOW); // GND to pin 6 (Flow Sensor)

  attachInterrupt(0, incementpulse, RISING); // attaching the interupt

  sei();      // Enabling interrupts
  
  Serial.begin(9600);
} 


// Loop measuring pulses from Sensor

void loop ()    
{
  Serial.print("PulseSensor: ");
  Serial.println(PulseSensor);
}
//cli();      // Disabling interrupts

Pulses are better counted as unsigned integers or longs, that makes interrupt based counting much faster

so change this line to

volatile unsigned long PulseSensor=0;

and give it a try

Maybe you should not serial print during measure

mgth:
Maybe you should not serial print during measure

The real trouble there might be that the counter is updated in the middle of a print statement, resulting in a strange value. This risk is a bit higher because the speed is only 9600 baud and the printing takes dozens of micro seconds.

volatile uint32_t  PulseCount = 0; 
uint32_t copyPulseCount;  // work copy

uint32_t lastDisplay = 0;

int hall = 2;

void processPulse() 
{ 
  PulseCount++;
} 


void setup() 
{ 
  pinMode(hall, INPUT);
  digitalWrite(hall, HIGH); 
  pinMode(4, OUTPUT); 
  digitalWrite(4, HIGH);
  pinMode(6, OUTPUT); 
  digitalWrite(6, LOW); 

  attachInterrupt(0, processPulse, RISING);

  sei();    
  
  Serial.begin(115200);
} 



void loop ()    
{
  // display counter once per second.
  if (millis() - lastDisplay >= 1000) 
  {
    lastDisplay += 1000;

    // disable interrupts to make a copy of the counter to prevent updates during processing.
    cli();
    copyPulseCount  = PulseCount;
    sei();

    // display data
    Serial.print("Pulses:\t");
    Serial.println(copyPulseCount);

    // calc to liters
    float liters = copyPulseCount  * 4.6E-4; // = * 0.00046
    Serial.print("Liters:\t");
    Serial.println(liters, 3);

  }

   // other code can be inserted here

}

give it a try

Hello,

Interesting code, however I tried it and it still gives me 180 Pulses. I also tried to Serial Print only when I input "1" in the Serial Monitor window, but its still 180.

So I am starting to think that its not a problem with speed that my code reads Pulses, but something else I cannot explain.

I contacted the company 3 times to ensure the Info in the datasheet is correct. They confirmed that the number 2174 corresponds to 1 Liter and the the Pulse rate is 0,46uL/P.

The sensor cannot be defect, since I am getting 180 Pulses every time...

Ideas anyone? Although I am in the working range of the Sensor, I only power it with 5V. The Pulse the Sesor sends is 10V...might this has to do anything with it?

Any other ideas?

Do you have a schematic for how you've connected this to your board. Doing a search I find that in the datasheet, this device only gives a 1v pulse. You should really up the voltage a bit to get your arduino to see it reliably. Maybe a simple transistor would do the job.

http://download.sechang.com/pds/inventory_group/171/171_8198a.pdf

Hmm from what I can see in the Data sheet, 1V is Low and 10V is High. Doesn't it mean the Pulse is actually 10V?

MaleBuffy:
Hmm from what I can see in the Data sheet, 1V is Low and 10V is High. Doesn't it mean the Pulse is actually 10V?

WOW You're right. But it does specify the supply voltage of 12V and an input that goes upto 10v should certainly never be directly connected to an arduino.

So perhaps giving it a supply of 12v and a voltage divider on the output could sort it out.

Edit. No it's only in THAT diagram that the supply is 12v. So scrap this.

Two suggestions.

I would power the flow meter from the 5v and ground pins instead of pins 4 and 6, and I think this will raise the supply voltage a bit.

I would also try changing from input pullup to an external pull down and see if the sensor can drive the pin high. I'm not sure you are getting reliable pull down when the hall sensor goes open given that there is a base level on one volt.

cattledog:
Two suggestions.

I would power the flow meter from the 5v and ground pins instead of pins 4 and 6, and I think this will raise the supply voltage a bit.

I would also try changing from input pullup to an external pull down and see if the sensor can drive the pin high. I'm not sure you are getting reliable pull down when the hall sensor goes open given that there is a base level on one volt.

Thanks

I will try to power the sensor from a 9V battery.

Will try the pulldown resistor as well.

Hope I get luckier this time.

I will try to power the sensor from a 9V battery.

Be careful with this. I think that the ouput voltage level is a function of the power levels to the sensor, and with 9V you may be giving more than 5v to the Arduino pin.

cattledog:

I will try to power the sensor from a 9V battery.

Be careful with this. I think that the ouput voltage level is a function of the power levels to the sensor, and with 9V you may be giving more than 5v to the Arduino pin.

Good point. I will measure the voltage before I connect it.

I tried another Sensor, this time the FS300AH, and I have to say that the Pulse count was about 1905 Pulses for a Liter, which is very close to what the datasheet says.

It is a smaller sensor, so it took x10 times longer for the water to pass through it. My guess is that it has a higher resolution, because it has a smaller nozzle.

Comparing the two, although they measure flow in different ways (the first being a Positive Displacement flow sensor and the second one a Turbine flow sensor), it actually make sense that the first sensor has a smaller Pulse/Liter count, since it has a larger nozzle thus smaller resolution!?

Can you guys see something in the datasheets that I am missing?

Although I am in the working range of the Sensor, I only power it with 5V. The Pulse the Sesor sends is 10V...might this has to do anything with it?

Any other ideas?

Definitely the output will need to be limited to 5V to prevent any damage to the Arduino's input. If available, an oscilloscope will give a true picture.

Comparing the two, although they measure flow in different ways (the first being a Positive Displacement flow sensor and the second one a Turbine flow sensor), it actually make sense that the first sensor has a smaller Pulse/Liter count, since it has a larger nozzle thus smaller resolution!?

Resolution: This is mostly determined from the sensor's electrical/electronic design.

Accuracy: Huge differences here.

For the FS-3400AH (2-30L/h), accuracy is stated to be ±10%. This is not specific enough.
If it's ±10% FS (full scale), then it will measure the flow rate to an accuracy of ±3 L/h.
Notice the big change in specified L/pulse at 2L/h flowrate. The true range of this device is really 4-30L/h, ±10% (not 2-30L/h, ±10%).

For the OF05ZAT-AO (5-50L/h), accuracy is stated to be ±2% RS (percentage of reading). Therefore this device will measure the flow rate to an accuracy of ±0.1 L/h at the low end of it's range and ±1.0 L/h at full scale.

http://www.alicat.com/technical-information/understanding-specifications/

However, although the datasheet mentions that the pulse rate is 0,46mL/P which means 2174 Pulses per Liter, when I run the sketch I only register 180 every time. x12 times less than normal.

Nowhere in the discussion or code could I find anything that deals with time measurement. This is critical in order to determine flow rate and its critical to monitor elapsed time in your calibration sketch. It might be perfectly normal to get 180 pulses for every test, especially if the test flowrate is out of range of the sensor's specified range. However, I do suspect that incorrect voltage levels (interfacing) was the main problem.

There are different methods to determine accuracy for calibration of the sensor.

The method described here is to feed 1 liter of water and test the number of pulses. This is the least accurate method.

Another method would be to apply a continuous flow (at a constant rate) then count the number of pulses over a specific period of time. This is a more accurate method, however resolution becomes a problem at low pulse rates, so longer test times are required to compensate.

Another method would be to apply a continuous flow (at a constant rate) then count a specific number of pulses and measure the elapsed time. The first pulse will start the test, the last pulse will stop the test. This the quickest and most accurate method (independent of the flow rate for the test).

I'm no hardware expert, so I'm kind of winging it here, but here are my thoughts.

From what I saw in the data sheets, the second sensor output is "open collector" which works like a switch to ground.

You would connect this to the Arduino pin with input pullup or an external pullup resistor so it is not floating when open. There may be an internal pull up resistor built in to the flow sensor, in which case you would not need to supply the pull up. You appear to be able to get valid results from this sensor with what you are doing.

The first flow sensor you used, appears to have some sort of active output, switching between a high voltage dependent upon the supply voltage and 1v low, although from the data sheet it's not clear what the sensor levels are at other than 12v. The output may not be floating at any time and may not require pull up or down. Indeed, the high and low voltages of the output signal may behave differently when looking at a pull up or pull down resistor. They may require a really high impedance/resistance to maintain their levels and the pull up/pull downs are changing the signal levels.

Sensors like that often use open collector, PNP transistor outputs, in which case a resistor to GROUND is required to develop a signal. That would also agree with the data sheet posted by KenF. Try a 10K resistor to ground. If you want to power the sensor with a voltage higher than 5V, the "resistor" can be a voltage divider, to ensure that the input to the Arduino never exceeds 5V.

Thanx for all your input guys!

dlloyd in the sketch I have for calculating flow rate I use time. I just didn't think it was necessary for calibration, since I want to see how many pulses I get for every liter. I didn't thought that I could be outside the flow rate boundaries while testing. I see it can be a problem.

What I measured without is that when connected to the Arduino, the voltage the sensor gets is 5V. The Voltage at idle is 0.01V and goes to 2.4V when there I a pulse.
The strange thing is that after the sensors stops sending pulses, the voltage is sometimes 5V and sometimes 0.01V.

I will definitely try with a 10 pull down resistor connected to ground.

MaleBuffy:
Thanx for all your input guys!

dlloyd in the sketch I have for calculating flow rate I use time. I just didn't think it was necessary for calibration, since I want to see how many pulses I get for every liter. I didn't thought that I could be outside the flow rate boundaries while testing. I see it can be a problem.

What I measured without is that when connected to the Arduino, the voltage the sensor gets is 5V. The Voltage at idle is 0.01V and goes to 2.4V when there I a pulse.
The strange thing is that after the sensors stops sending pulses, the voltage is sometimes 5V and sometimes 0.01V.

I will definitely try with a 10 pull down resistor connected to ground.

Sorry for the words that make no sense. ..Android autocorrect!

dlloyd in the sketch I have for calculating flow rate I use time. I just didn't think it was necessary for calibration, since I want to see how many pulses I get for every liter. I didn't thought that I could be outside the flow rate boundaries while testing. I see it can be a problem.

Not only that, when you start the flow, the sensor will ramp up to a certain flow rate, then it will probably slowly ramp down and be out of range near the end of the test. So the middle part of your test might be within range, but the ramp-up and end-portion would introduce accuracy errors.

What I measured without is that when connected to the Arduino, the voltage the sensor gets is 5V. The Voltage at idle is 0.01V and goes to 2.4V when there I a pulse.
The strange thing is that after the sensors stops sending pulses, the voltage is sometimes 5V and sometimes 0.01V.

Everything here looks normal to me. If you're using a multimeter, it's probably giving you an averaged reading while there are pulses. If it has a peak hold, peak voltage or similar setting it might be able to catch the peak voltage of the pulse, but that depends on it's features and specifications.

I will definitely try with a 10 pull down resistor connected to ground.

You're already getting a 0-5V signal ... no pull down (or pull up) resistor required.

It turned out that the sensor was a fake one, a cheap copy of the original. I got hold of a genuine one and I got 2174 Pulses with the original code. Than you all for your input.