I have a contact (pushbutton) that's about 10 metres away of a Raspberry Pi.
However; it behaves quite erratic and would trigger when for example an exhaust fan is started in proximity of the wire. I believe the AC electromagnetic interference causes it to trigger.
What I've tried:
Software fix #1 Whenever an active signal is received; I wait 100ms and check again. If it's active twice; it's verified. This actually 'fixes' the problem; though I would like to know how to make the hardware layer more resistant against emi.
Soft/hardware fix #2 Enabled internal pull-up of the Raspberry Pi. In this way it has a predefined state and thus has less interference (though still notable amounts).
Hardware fix #1 Use an external pull-up resistor. I've tried 5K (not quite good enough) and 1K (seems about right), though various sources discourage low resistance as obviously causes higher current.
Hardware fix #2 use an cat5e foiled network cable instead of regular power cable. This didn't quite seem to work (its foil wasn't really connected to anything), should it be connected to GND? (or is shield not GND?). The resistance of the network cable could be higher as electical cable; since it has less copper?
What I'm searching for:
- Actual proper ways of implementing such systems; possibly for up to 50m.
I'm thinking of putting 24V on the wire with the button and a opto-isolator or relay on the Raspberry Pi's side. Though this would require quite some extra components and I don't understand why it would be required at ~10m.
- Theory and best practices?
How can we calculate the required amount of voltage? Should I use a shielded cable (how to connect the shield?) or a cable with low resistance?