The best method for reading the signal would depend on your application and some specific details like:
What's the maximum rate the posts pass through the slot?
Are all the posts positioned the same way, same color, is it reflective, translucent, same size?
Can the posts completely block the LED and photo transistor?
Note there will be a time interval where the posts gradually block or unblock the LED. This is where the signal would be most susceptible to noise as it gradually transitions from low to high or high to low.
You could get a picture (capture) of what the signal looks like as the posts pass through the slot. Connect the signal to A0 and run this code. Open Serial Plotter. To stop the trace, just select an invalid baud rate. What does the signal look like?
OK, moving on from my earlier OMG post.
FFS! We are talking about what is effectively a switch on an input pin.
What's so hard?
Yes, you could use an analog input if you (really) need to, but in 99% of opto-interrupter applications, a digital (0/1) input state will be a far better approach.
There are optical conditions that need to met - the optical flag must completely occlude the light oath for reliable sensing. If you are sensing partial occlusion, the type of input is the least of your problems. Power supply stability will cause greater problems.
RANT:
Design your solution - if only in your mind - before stapling, twisting and taping wires and gizmos together.
Every complex project is a collection of simpler solutions.
You're stuck on the digital equivalent of a switch, bulb and battery.
/RANT
We've all offered various levels of help, you really need someone sitting beside you to demonstrate and explain what you're seeing.
Sorry for being harsh but this is part of learning.
[color=teal]Item Symbol Conditions Min Typ Max Unit
Output Light Current IL VCE=5V,IF=20mA 1 2.5 mA[/color]
This tells me that for 20mA through the LED, the minimum Current Transfer Ratio you can expect is 5% (1mA), the typical CTR would be 12.5% (2.5mA). The collector can control currents all the way down to the "Collector Dark Current", which is 100 nA maximum (0.1µA).
So, with 56K || 30K (INPUT_PULLUP), R2 = 19.5K
Minimum current through R2 is 0.1µA (worst case, transistor off) and maximum is about 2.5µA when the transistor is on. Should be no problem with the signal levels (just noise, rise time, fall time).
@SChiccarine, have you tried adding a 0.1µF capacitor (R2 to GND)?