Im new here and hope to get my solution for my Rc Turbine fuel meter project here.
I’m flying Rc turbine jets and until now I meaussure my flight time to determine when to land the plane. For my electric jets I have a datalogger that sends data from my battery down to see what’s happening in the sky. On my monitor I can readout voltage, mA used etc.
What I’m planning to do is to get me another transmitter and modify it by removing the current sensor. I then want to use an arduino and a flow sensor to measure/count the fuel used by the turbine. Then I want to sent a signal to the datalogger transmitter that correspond whit the used fuel (mA). The current sensor emits a voltage/Amps.
A sketch for counting the pulses is easy found on the net but the code needs to be altered to let the arduino send out a voltage to the datalogger.
Anyone that can help me to modify the code.
I found this code on the net and think this will be a good start:
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
}
I supose when I want to show mL/min I need to change the formula: Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
in L/hour
Ben
Moderator edit: </mark> <mark>[code]</mark> <mark>
You need to know what the output of the current sensor is in electrical terms. If it's outputting a voltage proportional to the current (that would be my guess) they you need the Arduino to output a variable voltage. Some of the more recent Arduinos have a DAC which enables them to output an analog voltage. The older ones can be modified to generate an analog output by connecting a low pass filter circuit to an analog (pwm) output. Depending how much resolution you need, you can also make a crude DAC by connecting multiple digital outputs to a resistor ladder. If you're lookig for something more precise and don't want to make your own filter circuit or use an Arduino with a DAC then you also have the option of using an external DAC or digital potentiometer.
Normally the ACS754 sensor sends out a voltage of 20mA/amp. So I need to get the arduino do the same thing.
Can I do something by adding analogWrite in the code.
Yes the Arduino can do that. However, depending what the output of the flow meter is you may have easier options available. If it's producing a variable frequency output where the frequency is proportional to flow then what you are trying to create is essential a frequency-to-voltage converter, and those already exist as discrete components.
The sensor that I am going to use is the FCH-m-POM-LC from Biotech; it outputs a square wave signal. Here’s the datasheet. So I assume that the amplitude of the signal stays the same and the period changes if the flow increases or decreases. When I want to use a Frequency to voltage converter will it be possible to get the output voltage as low as 10mV. I want a resolution of 20mV/10ml. then my datalogger will show 1A for 10ml and 30A for a 300ml fuel consumption.
And what about using DigitalRead to measure the output from the flowmeter. If the fuel flows faster the amplitude rests the same and the period will be shorter and vice versa. Or am I wrong on this?
Yes an Arduino-based solution is possible. With this approach you would connect the sensor output to a digital input and write some code to measure the frequency, work out the corresponding output voltage, and then generate that output voltage using whichever of the DAC options you wanted.
However, in effect you will have created your own frequency-to-volts converter. Research the commercially available products to do that before you decide, because they're probably rather cheaper, simpler and more reliable than a DIY version built using a microcontroller.
I still have some Arduino Pro Mini’s laying around so that’s no problem. I thought it would be simpler to change the Calc part if the resolution is off then changing resistors and capacitors.
I got my flow sensor yesterday, hooked it up to the Arduino and ran it for a test on my fuel station to fill my plane. The counter part works but now I’m stuck with the output from the Arduino. How do I get the Arduino output a signal that I can use in my project.
volatile
int NbTopsFan; //measuring the rising edges of the signal
int voltmeter = 9;
int Calc;
int hallsensor = 2; //The pin location of the sensor
//int val=0;
void rpm () //This is the function that the interupt calls
{
pinMode (voltmeter, OUTPUT);
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 /16.67 ); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
analogWrite (voltmeter,Calc);
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" mL/min\r\n"); //Prints "L/hour" and returns a new line
}
Let us start with the most simple, the low pass filter to convert the PWM output from the Arduino to a DC voltage. So I want the Arduino to output a PWM signal linear to my input.
When I measure between the Vcc and Vout from the current sensor I read 2.5V when the current = 0V. When the current trough the sensor rises the voltage on Vout rises to.
So can we let the Arduino put out a PWM that varies between 2.5V and 5V. I suppose that when we map this would be 0 for 2.5V and 255 for 5V.
benovitch:
So can we let the Arduino put out a PWM that varies between 2.5V and 5V. I suppose that when we map this would be 0 for 2.5V and 255 for 5V.
If you want to output a value between 2.5V and 5V then you need to output an analogWrite() value between 128 and 255. You will need to convert the input flow rate (however that is going to be represented) to a value in the range 128 .. 255. If the flow sensor gives you a linear signal then you could use the map() function to do that conversion.
I assume that this was mistyped as it makes no sense.
can we let the Arduino put out a PWM that varies between 2.5V and 5V
No. The output voltage will always be 0V or 5V but it will be alternating between the 2 very quickly. However, as Peter suggested there are methods to convert the output to a voltage but you will need to use external hardware.
Well this evening I’ve been playing around with the Arduino and flowmeter. I don’t know how I did it but I got my arduino to put out a signal when fuel is passing true the flowmeter.
Here is the code I wrote:
volatile
int NbTopsFan; //measuring the rising edges of the signal
int voltmeter = 9;
int Calc;
int hallsensor = 2; //The pin location of the sensor
//int val=0;
void rpm () //This is the function that the interupt calls
{
pinMode (voltmeter, OUTPUT);
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 /16.67 ); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
analogWrite (voltmeter, map(Calc, 0, 1023, 140,255));
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" mL/min\r\n"); //Prints "L/hour" and returns a new line
}
The values of the calc part aren’t right but I still needs to figure out how many pulses per L the flowmeter counts. Is there a simple code to use that counts the pulses and addition the pulses to give me after 1L of fuel the total amount of pulses?
If the resolution of the flowmeter isn’t high enough I can add a nozzle to let the fuel pass quicker. But that I rather won’t do because I’m afraid that the turbine engine won’t get enough fuel to run properly.
Now to make the PWM output into a DC voltage what are good values for a simple low pass filter. I also saw on the datalogger print that right after the Vout from the current sensor already a low pass filter is. Should I risk connecting the PWM output directly on the datalogger and see what happens or make a new low pass filter. Or are there other suggestions?
benovitch:
Is there a simple code to use that counts the pulses
PulseCount++;
Put this in a place in your code that executes when each new pulse is detected. If you need to zero the count when a start condition occurs and stop the counter when a stop condition occurs then it is easy enough to do that too.
At the moment you have code in loop() which zeroes NbTopsFan. If you want it to keep accumulating, don't zero it.
Currently the code disables and enables interrupts for quite a long time in loop(). This is not sensible. You do need to disable interrupts briefly while you access NbTopsFan, but you should keep interrupts disabled for as short a time as possible because otherwise you may miss interrupts.
To minimise the time that interrupts are disabled, put some code at the start of loop() to disable interrupts, copy NbTopsFan to a local temporary variable and enable interrupts, then use the local temporary variable for anything else you want to do with that value in loop().
Yesterday I played around with my fuel meter to get my sensor calibrated. The flow senor is calibrated. I adapted my code to get I right. From the specs from the datasheet the flow meter gives me 2500 pulses/liter. This equals 0.4 ml/pulse. Since the frequency is measured I need to multiply it by 60 to go too ml/min.
Then by controlling the speed of the pump I filled up a bottle with markings on to see if my calculations are right during 1 minute.
In this part of the code:
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
The delay function is set to 1 sec. I assume that this is the time the pulses are measured before disabling again. If I change the value to let’s say 500. What effect will this have on my calculations?
If I crank up the pulses for the same amount of fuel, would this improve my precission?
How can I get my output PWM signal to be less nervous? During flight the fuel flow to the turbine will change, is there a possibility to smooth them out or something like that?
volatile
int NbTopsFan; //measuring the rising edges of the signal
int voltmeter = 9;
int Calc;
int hallsensor = 2; //The pin location of the sensor
//int val=0;
void rpm () //This is the function that the interupt calls
{
pinMode (voltmeter, OUTPUT);
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 * 0.4)*60); //(pulses from flowmeter x 0.4 mL/pulse) x 60 gives me flowrate/min
analogWrite (voltmeter, map(Calc, 0, 1023, 128,0));
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" mL/min\r\n"); //Prints "L/hour" and returns a new line
}
benovitch:
I assume that this is the time the pulses are measured before disabling again. If I change the value to let’s say 500. What effect will this have on my calculations?
Yes - because you're disabling interrupts for quite long periods, your measurements will be inaccurate. You can alter the amount of inaccuracy by changing the duration, but you can't eliminate it. That whole approach of only having interrupts enabled some of the time is basically wrong. You should aim to leave interrupts enabled all the time, except for a very brief moment when you need to access the volatile counters within loop(). Then the count will reflect the actual number of pulses from the sensor, which corresponds to the amount transferred which you are trying to measure.
This week I finally got my fuel meter to work. Below is the code I used for it. Due to the Low Pass filter setup I don’t get a stable voltage that goes to the data logger. But I’m satisfied with it. When using the “prime pump” function from the turbine fuel pump I get a flow of 120ml/min which give me after 1L of pumping fuel in a measuring cup a readout of 1050mA used. So the data logger gives 50mA more than used, which is better than giving 50 mA less.
One more test to do is to let the turbine run on different speeds and use a premeasured amount fuel to let I run to see if the counter does the job right. I’m planning to fill up the measuring cup with 1L of fuel and let the turbine run until that 1L off fuel is used and then compare with the data logger display if it displays 1050mA used.
volatile
int NbTopsFan; //measuring the rising edges of the signal
int voltmeter = 9;
int Calc;
int hallsensor = 2; //The pin location of the sensor
//int val=0;
void rpm () //This is the function that the interupt calls
{
pinMode (voltmeter, OUTPUT);
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 * 0.182)*60); //(Pulse frequency x ml/pulse)x 60, = flow rate in ml/min
analogWrite (voltmeter, map(((Calc/1.6275)*0.955), 0, 1023, 128,0));
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" mL/min\r\n"); //Prints "L/hour" and returns a new line
}