5V signal is sufficient to make travel till the end of 50 m but you cannot connect that directly to your micro controller.
Best thing is to isolate the noisy weak digital signal from the MCU port. One way is to use optocoupler as mentioned by Michael.
You can use say from example below circuit.
- Replace 3.3 V (only the one connected to R1) with your 5 V supply and a series switch at the entrance.
- Choose a optocoupler with good CTR (current transfer ratio, higher is better)
- The optocoupler will turn on(the internal LED) when you close the switch
- It will in turn, turn on the transistor.
- Microcontroller will sense it because now the output is shorted to ground via transistor in the optocoupler.
- Microcontroller can run with independent supply. (3.3 V) for example.
- You have isolation between signal and MCU.. Hence there will never be pseudo triggering of the signals due to voltage coupling because of a generator close by or some power spikes..
- When switch is closed a finite current will flow through the series resistor and the LED in the opto coupler. Choose R according to optocoupler data sheet.
You can also use higher voltage (instead of 5 V) there by reducing ohmic losses in the cables.
This idea is feasible with just a battery for 5V side. Because the current will flow only when the user activates the switch.