Digital 5V signal through a long copper cable with EMI noise
It should be pretty easy to sense a switch being open or not; you'd just measure the current that goes through the switch instead of trying to measure an open-loop voltage.







simulate this circuit &ndash; Schematic created using CircuitLab

R1 is a so-called "pull-up" resistor here. When the switch is open, no current flows through it. And a resistor through which no current flows has no voltage drop, so the "to microcontroller" node is at 5 V-0 V = 5 V.

When the switch is closed, then the "to microcontroller" node is pulled to ground, 0V. Easy to sense!

In the above diagram, I simply connected the switch to ground at the place where the switch is; so, basically, connected one side of the switch to the "neutral" wire, and the other to the wire going to your microcontroller.

That is fine as long as "ground" is the same all over your house. It might not be!

In that case, things are quite a bit harder: you either need to run a second wire back from the switch to the microcontroller and connect to ground there (but that needs two wires per switch, instead of one), or you need to find a way of measuring without relying on common ground. 

One way to do that: 







simulate this circuit

With a bit of microcontroller firmware:


set the microcontroller pin to "output"
set the output to "high" for some time (100 ms, for example)


If the switch is closed, this charges the capacitor

set the microcontroller pin to "input"
measure how long it takes until the pin goes "low".