Flow sensor for shower on R4 board

Hi there,
I wish to make a display showing the volume of a shower taken (as a private project to save water). I have a Arduino Uno R4 (led matrix) board and a pulse sensor model YF-87. I tried to read a lot about how to work with the sensor and the programming, but somehow I do not seem to manage to pick up any pulse. I checked the flow sensor with a multimeter and it does seem to give the normal pulses. Can anybody help me?
Waldemar`

#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"

ArduinoLEDMatrix matrix;

const byte    sensorInterrupt = 0;  // 0 = digital pin 2
const byte    sensorPin       = 2;
float         addLitres;
float         Litres;

volatile byte pulseCount; 

void setup() {
  Serial.begin(115200);
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 5;     // just to have a value for testing
  addLitres         = 0.0;
  Litres            = 0.0;

  attachInterrupt(digitalPinToInterrupt(sensorInterrupt), pulseCounter, FALLING);

  matrix.begin();

  matrix.beginDraw();
  matrix.stroke(0xFFFFFFFF);
  // will only show "H2O"
  const char text[] = "H2O";
   
  matrix.textFont(Font_4x6);
  matrix.beginText(0, 1, 0xFFFFFF);
  matrix.println(text);
  matrix.endText();

  matrix.endDraw();

  delay(2000);
}

void loop() 
{

  detachInterrupt(digitalPinToInterrupt(sensorInterrupt));
  addLitres = pulseCount / 450.0;
  Litres += addLitres;

  // Reset the pulse counter so we can start incrementing again
  pulseCount = 0;
  delay(100);
  // Enable the interrupt again now that we've finished sending output
  attachInterrupt(digitalPinToInterrupt(sensorInterrupt), pulseCounter, FALLING);

  // Make it scroll!
  matrix.beginDraw();
  matrix.stroke(0xFFFFFFFF);
  matrix.textScrollSpeed(50);
  matrix.textFont(Font_5x7);
  matrix.beginText(0, 1, 0xFFFFFF);
  matrix.println(Litres,3);
  matrix.endText(SCROLL_LEFT);
  matrix.endDraw();

}

/* Interrupt Service Routine */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

`

Welcome to the forum!

Please post a link to the actual one you are using.

Please also post your schematic, and some good clear photos of your setup.

See: 'How to get the best out of this forum'

Thank you for the welcome.
This is the sensor I am using:

The set up is still really basic. I am in the testing phase. First see if I get it working, then I will start building it in. Here a foto of the set-up.

Please also post a schematic.

A schematic is key to describing any electronic circuit - even a simple one.

See: ' Schematics or circuit diagrams'

Do you have a link to specifications for the sensor?

How are you testing it - how do you get it to generate pulses?

Thank you. I am familiar with electronic circuits and diagrams. Just forgot to make one because this is so simple, straighforward. Will send you Sketch now.

The sensor is tested by simply blowing air through it. If you attacht a voltmeter measuring the tension between the yellow and the black wire, shows almost 5 V when not in use and it will drop to values around 2 V when blowing through it.

Still need to see specifications for the sensor - what are the 3 wires?

What is the other connector that you're not using?

Black and red are the power (resp minus and plus). The yellow gives the output. The other cable is not connected and is just a separate temperature sensor.

I can´t find more specifications on the sensor. On the label it reads:

working range: 1 - 25 l/min
water pressure: <= 1.75 mpa
model: YF-87
water flow sensor

So how did you determine what the red, yellow, and black wires do? And that it is supposed to work on 5V?

I bought the sensor with Amazon. They gave the following specs.

Features:

Can be used for water heaters, credit card machines, water vending machines, flow measuring device.
Lightweight, small size, easy to install.
Durable, long-lasting, can be used at high and low temperatures.
Sealing ring with upper and lower force structure never clamp.

Specifications:

Thread: BSP 3/4", 1/2", 1" (optional).
Operating flow: 1 to 50 l/min.
Water pressure resistance: > 1.75 MPa.
Operating voltage range: DC5-15V.
Insulation resistance: > 100 MΩ.
High pulse output: > DC 4.7 V (DC input voltage 5V).
Material: copper.
Color: gold.

Does that help?

Please provide a link to that.

This is the Amazon link

It is all I have, I'm afraid.

LOL - this review:

:sweat_smile:
Happily I was not looking for a switch.
It should give pulses though...

Have you tried simplifying your code to just do the pulse counting - nothing else?

Does it work if you supply a pulse from a switch?

The sensor is not a switch - it generates a pulse - so it doesn't need a pullup.

I did try to leave out the digitalWrite(sensorPin, HIGH); part. No effect.

I will have to leave now, sorry. Will try to come back to it later in the afternoon.

Thank you!

You need to make the sensor pin:
pinMode(pin, INPUT_PULLUP);
Or connect a 10k pullup resistor between input pin and VCC

It generates a voltage pulse - so doesn't need a pullup.

How did you power the sensor when using your DMM to check for pulses?

The Arduino is not intended to be used as a power supply, so it may be problematic if your sensor draws much current.