Can't use "pulseIn" on Nano 33 IOT?

Hi all,
I am working with my son to use a hall effect water flow sensor, measure the frequency, convert the results to gallons per minute, and post the results on the cloud. I cannot get the Arduino Nano 33 IoT to use the pulseIn function to measure frequency.

I have flashed the following code on the Uno and on the Nano 33. On the Uno, I get realistic and non-zero results. When I flash the Nano 33, I get zeros.

  • Can someone help resolve this issue?
  • Is there another way to measure pulses for a frequency measurement?

Thanks!

#define FlowpinA 4

void setup() {
  Serial.begin(9600);
  delay(1500); 
  pinMode(FlowpinA, INPUT);
}

void loop() {
 
  unsigned long ontimeA = pulseIn(FlowpinA, HIGH);
  unsigned long offtimeA = pulseIn(FlowpinA, LOW);
  
  Serial.print(ontimeA);
  Serial.print(",");
  Serial.println(offtimeA);
  
  delay(100);
}

Is the Nano a 3.3 volt controller?
Can You post a link to the sensor datasheet?

I bought the water for sensors from Amazon, link below. I have it plugged into 5v

GREDIA 3/4" Water Flow Sensor Food-Grade Switch Hall Effect Flowmeter Fluid Meter Counter 1-60L/min (Pack of 2) https://a.co/d/5yfwOwI

You're leaping ahead too fast. You can never troubleshoot the whole thing, it's like trying to fix a car engine by feeling the hood.

Find ways to test each individual function separately, then put them together.

Right now, you should just be trying to confirm that pulses are present on the input pin. Write some simple test sketches that do only that. For example you could just turn on the onboard LED whenever the input is high.

2 Likes

Thanks. You tried but as so often it's a sales site, not a technical document. I don't find what type of output it is. It's a minimum 5 volt device and it outputs 5 volt pulses. Fine, but what is the voltage level between the pulses. Is an oscilloscope available to check the pulses?
Again, if the controller is a 3.3 volt logic controller it can be damaged by 5 volt pulses.

1 Like

Well, this is the "Project Guidance" category. So probably, yes.

Is there another way to measure pulses for a frequency measurement?

Yes. You can count pulses during a longer fixed interval. It's sort of the "Pulse counting for Dummies" method (when used with relatively slow pulses).

You should find this obvious. If the measurement is "pulses per minute", when you count all the pulses that you receive for one minute, there it is, you have it.

Arduino Nano 33 IoT only supports 3.3V I/Os and is not 5V tolerant.

1 Like

The sensor works up to 24V, it might have an open collector output. Does the OP have a pull up resistor on the input pin? Try

  pinMode(FlowpinA, INPUT_PULLUP);

The pin might be 5V and damaged the Nano, but if so it's too late anyway...

Alright, so with your inputs, I was able to figure it out.

Starting with the UNO, I retested and got things working (data out). I measured the sensor inputs with my DMM and was getting something (assuming it was digital out) when investigating the sensor out. (one step at a time per @anon57585045 )

Moving over to the Nano 33 IOT, I measured the same and noticed that the sensor input 5V was not working. It turns out that although the breakout board has 5V, it is not actually connected to the Nano 33... which aligns with @cattledog comments (Nano 33 does not support 5V).

Fortunately, the sensors appear to work with 3.3V despite the amazon 'data sheet'. After plugging it in there, I'm getting the expected output.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.