Pulse counter module giving weird results?

This is the counter in question: https://robu.in/product/correlation-photoelectric-infrared-count-sensor-module/ (it's an Indian website since I'm Indian) and in the attachments section, the datasheet is attached.

Context: I am using this module as an encoder to measure the speed of a BO Motor. The motor has a disc attached to it, and the module detects whether the disc has slots in it or not. It's supposed to output a high or low value when detects an object and when it doesn't respectively. The problem is that the module just outputs a value of around 255 regardless of whether there is any object. I should either be getting a 0 or 255. I am using an Arduino Mega 2560. The sensor has three pins (VCC to 5v, GND to GND and OUT to pin 0). Code is here below:

void setup() {
  // put your setup code here, to run once:
  pinMode(0, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int c = digitalRead(0);
  Serial.println(c);
}

I don't really see what the issue is with the code or connections because its fairly straightforward but I'm still getting rubbish in the output.

Digital pins 0 and 1 are the Serial pins. Use pin 3.

I'm still getting the same result :frowning:

Okay for curiosities sake, I change serial print to print 5 and I still get 255 in the output. What is going on?

digitalRead returns HIGH or LOW.

void loop() {
  if( digitalRead(3) == HIGH) {
   Serial.println("HIGH");
  } else {
   Serial.println("LOW");
  }
}
1 Like

Hi, @jermito2456
Welcome to the forum.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you post some images of your project?
So we can see your component layout.

The sensor has a LM393 comparator in it.
This has an open collector output.

Try.

 pinMode(3, INPUT_PULLUP);

This will provide the output bias needed if the sensor does not have a built in collector resistor.

Do you have a DMM? (Digital MultiMeter)

Tom.. :smiley: :+1: :coffee: :australia:

Hi Tom!

I can attach a diagram but the connection is pretty straight forward. I connected GND to GND, VCC to 5v and OUT to pin 3.

I tried INPUT_PULLUP but the result is still the same.

And yes, i do have a digital multimeter.

Hi,
Okay, now with power applied and sensor connected to the Mega.

DMM set for DC Volts.

  1. Measure between gnd and Vcc on the sensor.
    Then;
  2. Measure between gnd and output with nothing in the slot.
  3. Measure between gnd and output with something in the slot.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi,
I presume you have one of these;
image

Tom... :smiley: :+1: :coffee: :australia:

Is the green or red LED or both on the module lit?

That is possible but does not help in debugging your problem

Yes.

But the pulse counter looks like this
images

it is this*

Yes it is. When I put my pen in the slot, the led lights up and when I remove it, it goes away.

Tom... :smiley: :+1: :coffee: :australia:

...and when you run the loop code I suggested in post #5, it displays what on the serial monitor?

That is if you moved the data pin to D3.

The green LED should be lit when nothing is in the slot and go out when something is in the slot.

Your board seems to be backwards.

From the website:

Note: The sensitivity is not adjustable & Product may be different in terms of design .

So you may have a board that does just the oppsite, HIGH when no object and LOW when there is an object

this correctly prints the result