My friend and I, are trying to figure out a way to use two flow sensor to read a fuel consumption. The first one is for main fuel flow into a pump. The other one is for return fuel from the injector and back to the fuel tank. So, if we call the main fuel sensor for sens1 and the return for sens2 the mathematics will be like this: sens1-sens2=actually fuel consumption.

How do we program two sensors together. How can we get one of the sensor values to be subtracted from the other sensor value?

fiddled a bit with your code:+ use #define for those vars that are not changeable+ made 2 different IRQ's one for counting the IN pulses and one for counting the out pulses+ changed some var names to reflect what they meant like litersperminute+ use a copy of millis() in the if block as millis() might change during the block (accuracy)+ probably screwed up the math but you should be able to fix that relative easily+ made some vars local instead of global (reduce scope)

have a look and give it a try (not tested as I don't have an I2CLCD nearby

void loop(){ // use a var for value of millis, as it might change in the if .... block // due to slow serial prints unsigned long now = millis(); if((now - oldTime > 1000)) { unsigned long duration = now - oldTime; oldTime = now;

Hi Rob and thanks for your help with this!! This looks very good, but this sketch did not work as I hoped it would, but I think you are into something good there. I will try to understand more of it tomorrow. I dont either have the LCD, but my companion will test it when he finnishes his work in the North Sea

This is my last version of the sketch, and now it works! Thanks so much for your help I will keep developing this sketch to work more properly. I added two more volatile bytes, because the first sketch did not work.

float litersPerMinute = (1000.0 * liters)/duration; makes explicit that the math is done in float (it is, as liters is already float, but just looking at the original line it could have been integer math)

for the readability I would group the math and the display statements in the loop, something like

Thanks. I have cleaned up a bit more here, but its not perfect yet. The whole system is not accurate enough. I need the sensors to be very accurate for this project, and I think it is something inside here who makes the difference:

When I connect the hoses and sensors to the water faucet, the sensors gives me this: resultsLiter per time: 23.4000Liter per time: 24.1200Liter per time: 24.8400Liter per time: 25.2000Liter per time: 25.5600Liter per time: 24.8400

...and that is not what I had expected. The engines I develop this flow meter to, uses between 3 and 50 liters per hour.