For a particular sketch I have a simple pushbutton which is connected via a push-up (pull-down?) resistor to an input. The connection is as follows: 5V - pushbutton - bifurcation to input - resistor - GND. By momentarily pushing the button I change the input from low to high and can react on this in the sketch. The other way round also works: If the push button is permanently pushed and then opened, my input changes from high to low and I can again react in the sketch. Basically, this is a simple external cable loop, which by opening or closing triggers an event in my sketch.
My question now ist, how can I just replace the pushbutton by any other device like a light barrier, a microphone, ... which would open or close the loop in just the same way. I think I will have to replace the button by a transistor which will be activated by the device and which will then open or close the loop. Only I do not know how to realize this exactly. If anybody could show or point me to an example circuit to realize this for a light barrier and a microphone (including required connections to power supply for the device), I would appreciate very much.
Thank you very much.