OMRON Photo Interrupter Not Working

Hello Everyone

I am using OMRON Photo Interrupter to calculate the number of drops from a dropper.

I am using the following code:

int val = 0; // variable to store the value coming from the sensor

void setup()
{
    Serial.begin(9600); // set up Serial library at 9600 bps
}

void loop()
{
    val = analogRead(A0); // read the value from the sensor
    Serial.println(val); // print the sensor value to the serial monitor
    
    delay(5000);
    
}

I want that when one drop passes from the Photo Interrupter, '1' should be sent to the serial monitor and '0' if otherwise. I am just having analog values which do not change when drop passes.

Can anyone help me in achieving my desired result?

Thank you all in advance.

Best Regards,
Rushan

Connect output to pin 2 (for UNO) and a resistor to 5V (range 1k..10k)

Use a simple interrupt to 'flag' a passing object. (a drop of water may not be suffisient)

seehttps://www.arduino.cc/en/Reference/AttachInterrupt

hello mate,

Thanks for your reply. Where should i connect the other part of the resistor?

Where should i connect the other part of the resistor?

One end to 5v, the other to the output line/arduino pin.

The photosensor has open collector output and the resistor is a pullup. The output will read low when the sensor is unobstructed and the output is switched to ground. It will read high when blocked and the pullup resistor is bringing the output line to 5v.

See the internal circuit diagram in the data sheet