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.
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.