Fluctuating digital input on arduino uno r3 when connected to Photocoupler
Typical wiring for a on/off digital signal from an optocoupler is this:







simulate this circuit &ndash; Schematic created using CircuitLab

Pull-up to VCC, most likely 5V for most Uno R3. The pull-up gives it a known state of HIGH when the optocoupler's LED isn't on. When the LED is on, the optocoupler's transistor turns on, pulling the collector towards ground, giving a LOW signal.

Alternatively, wire the collector to the GPIO with the pinMode(x,INPUT_PULLUP) mode enable, using the internal ~47kΩ pull-up resistor. Essentially the same thing.

This is a typical open-collector setup for digital logic.

The Way you had it connected, with the emitter to the GPIO, is a emitter follower, and will show either 5V when the LED is ON or FLOATING when the LED is OFF. A Floating input will not have a fixed state, and will float between states, like an antenna. Use the wiring above instead.