here a circuit for an opto coupler input to a RPI-GPIO
connect
GND --> ground on RPI
OUT1--> GPIO
the RPI has to be configured with the pull-up resistor you select in device edit
And the input side goes to a switch with supplied voltage Vin (switch open: Vin=0, closed Vin=X) . The LED needs ~5-20mA to switch on fast
Values for R for different voltages Vin (the internal LED has a voltage drop of ~ 2.5V itself ):
12V: ~2k -470 Ohm ((12-2.5)V/0.005 /0.02A)
5V: ~500-120 Ohm ((5-2.5)V/0.005 /0.02A)
3V: ~100-25 Ohm ((3-2.5)V/0.005 /0.02A )
Karl