Yf-s021 & htcc-ab01

Good morning everyone. I am trying to read the data from this flow sensor indicated in the subject, but the interrupts on the board do not work for me. The same code on an arduino uno works without problems. I have tried the example that brings gpiointerrupt but it does not read anything either, only when I remove or put back the cable that comes from the flow sensor to the pin it shows some value, but passing water through it does not show anything at all. I have used these two codes to test:

#include “Arduino.h”

uint32_t cnt = 0;

void cntIncrease()
{
cnt++;
Serial.println(cnt);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
PINMODE_INPUT_PULLDOWN(GPIO3);
attachInterrupt(GPIO3,cntIncrease,RISING);
}

void loop() {
// put your main code here, to run repeatedly:

}


OTHER CODE TESTED

#include “Arduino.h”
const int sensorPin = GPIO3;
const int measureInterval = 2500;
volatile int pulseConter;

// YF-S201
const float factorK = 7.5;

// FS300A
//const float factorK = 5.5;

// FS400A
//const float factorK = 3.5;

void ISRCountPulse()
{
pulseConter++;
}

float GetFrequency()
{
pulseConter = 0;

interrupts();
delay(measureInterval);
noInterrupts();

return (float)pulseConter * 1000 / measureInterval;
}

void setup()
{
Serial.begin(9600);
PINMODE_INPUT_PULLDOWN(GPIO3);
attachInterrupt(digitalPinToInterrupt(sensorPin), ISRCountPulse, RISING);
}

void loop()
{
// obtener frecuencia en Hz
float frequency = GetFrequency();

// calcular caudal L/min
float flow_Lmin = frequency / factorK;

Serial.print(“Frecuencia: “);
Serial.print(frequency, 0);
Serial.print(” (Hz)\tCaudal: “);
Serial.print(flow_Lmin, 3);
Serial.println(” (L/min)”);
}

The error was in this line that should be like this:

pinMode(sensorPin, OUTPUT_PULLUP);

Looking at the sensor and your code Multiple issues rise:

  1. Sensor is rated for 5v, the pins are 3.3v , so you will need to find a sensor that is rated for 3.3v and not 5v like Arduino u
  2. You are declaring the pins as output where they should be input. I suggest you Read more about the difference between output and input pins !

I hope this helps!