Hi everybody.
I am a newbie to Arduino.
I am trying to get flow rate from the GEMS 173939-C flow sensor with my Arduino Uno board. (flow sensor datasheet: https://docs.rs-online.com/7c18/0900766b8023e8dd.pdf)
Some key facts about the sensor:
5-24VDC supply @ 8mA, frequency output max. 50mA (1k-2.2k pull-up resistor required)
flow range 1-15 L/min, 2200 pulses/L, frequency output 37-550Hz
I have connected the supply (red) and output (brown) cables with a 2.2k ohm resistor. (it was the only fitting resistor I had). The rest of the pin connections can be seen in the image "connections.jpg".
The input pin of the flow sensor is 3 and I have enabled the internal pull up. I am not sure whether this actually a) makes a difference because my serial output stays the same b) can replace the hardware pull up resistor from the datasheet?
The frequency I read with interrupts for falling edge (since pull-up). I then calculate the flow rate with following formula: flow rate [L/min] = (frequency [1/s] * 60) / 2200 [pulses/L]
I output the flow rate on the serial monitor. Currently, I am getting 0 the whole time. I do not know if this is because of a wrong hardware connection or a problem in my code. Perhaps, the 2.2k ohm is too high? The current of the output signal is 5V / 2200 ohm = 2mA... Any help appreciated!!
My whole code is below:
const int LED = 13;
const int interruptpin = 3;
volatile int count;
volatile int copy_count;
float flowrate;
unsigned long oldtime;
void flow()
{
count++;
}
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(interruptpin, INPUT);
digitalWrite(interruptpin, HIGH); // internal pull-up
count = 0;
flowrate = 0;
oldtime = 0;
attachInterrupt(digitalPinToInterrupt(interruptpin), flow, FALLING);
}
void loop()
{
if((millis() - oldtime) > 1000)
{
// detachInterrupt(digitalPinToInterrupt(interruptpin));
noInterrupts();
copy_count = count;
count = 0;
interrupts();
flowrate = copy_count * 60 / 2200; // flowrate in L/min
oldtime = millis();
Serial.print("Flowrate : ");
Serial.print(flowrate);
Serial.print(" \r\n");
}
}