Connecting arduino to existing house wiring

Hi
I would like to use the house's existing wiring and light switch as input to an arduino.
The wire is pretty thick (I think 4mm) so I assume the loss will be fairly low.
Question: Is it okay to have about 10m of wire (total) with a switch, one end +5v, the other end to an input?

The thickness is not the problem (although I think it's 1,5 or 2,5 mm2 instead of 4).
From my own experience I know picking up spikes is the major problem, spikes will arbitrary switch your lights on and off :astonished:
Two ways to handle spikes:
1 (best): use shielded wires.
2: use a spike killer.

A spike killer works fine for me (and my Arduino, who's still working after 2 years of home automation).

There's a third option: a long delay (e.g. 300msec) to avoid switching by spikes, but it has two disadvantages
1- you'll notice the delay.
2- there still is a possibility that a nasty spike will kill your Arduino.

Unlicensed people connecting unapproved devices to fixed wiring is illegal in most jurisdictions and will invalidate your house insurance. Are you a licensed electrician? Does your circuit have regulatory approval? Will your device catch fire or pose an electrical hazard if accidentally connected to mains, eg when someone puts a nail through a cable? Don't do it.

Ignoring the illegality, the issue is not resistive loss but the interference. A 10m open-circuit cable can pick up a lot of glitches and noise so you need to design careful analogue filtering to reject that safely, and opto-isolate it from the rest of your Arduino.

polyglot:
Unlicensed people connecting unapproved devices to fixed wiring is illegal in most jurisdictions and will invalidate your house insurance.

Maybe you're right, but isn't this whole forum all about connecting unapproved devices to our home installation?
Connecting 5 Volts to an ordinary switch will not cause any fire, but noise may ruin your Arduino indeed.
To let your Arduino switch any light, you'll need automatically opto-isolation like relay or solid state relay.

I don't think this forum needs to be all about illegal wiring as there are a lot of legal options involving non-fixed wiring, eg plug-in ZigBee switches, garage door openers, motorized roller shutters, window cranks, electric door strikes, etc, none of which are on the fixed AC wiring. DIY versions of the commercial plug-in automation products you can buy, eg from z-wave vendors.

See also my replies to the HA architecture thread, where I propose that unlicensed people could build what is effectively a custom PLC and have it wired to the mains via approved relays by a licensed electrician.

Thanks very much for your help.
I will make a plan to use my own switches, so that I do not have to tamper with house wiring.
I will also look at protecting against surges in the wiring. The first thing that comes to mind is using zeners.

Yep. I've been pondering the ESD protection thing for a bit, and how far you go depends on how safe you want to be. Being safe against mains injection requires a lot more hardware and analysis than just being EMI-tolerant.

Zeners are a good start, as are approaches that will lower your input impedance. Consider also RC filtering (switches are slow!) and/or treating your switch line as a current loop. Putting an opto-isolator between the switch-sense circuitry and the arduino pin can only be a good idea, though it doesn't give you mains-safety without an isolated supply supplying the switch-sense power.

Don't forget that a really long cable with a switch at the end is quite inductive, and that you can get significant voltage spikes or ringing when the switch opens and closes, especially if you have significant capacitance at your input. Do some transient analysis in spice maybe...

The problem that's vexing me at the moment (because safely detecting switch-state at long distance with existing house wiring is something I'm working on) is that there appears to be an inherent tradeoff between noise-resilience (low input impedance) and low power consumption. If you build a more noise-immune circuit, it will use more power and of course I don't want to waste a bunch of power just knowing whether my switches are on or off.

Thanks polygot.
The opto isolator is a good idea. I have none in my goodie-box right now, will have to order.
To protect against mains injection, a fuse is probably a good idea.

If I am to use a new switch instead of using the house wiring, I would probably go with a push button rather than the on/off traditional switch.
That way there is no power use except when the user is pressing the button, and will overcome ringing with filtering in software.
I was also eyeing out the alarm wiring. That looks similar to normal cat4 and probably uses 12v. Worth looking into their specs.

A fuse in your device won't save you from mains; what matters most is grounding. Say you have a floating power supply for the arduino and something bad happens to your switch wire: you could well have your arduino "ground" at the live voltage (it will continue to run fine!) and not know it until someone touched something connected to it.

Put the arduino inside a metal case connected to safety ground, and attach your arduino's ground to the metal case. Make sure you have a GFI* in your switchboard.

Definitely a pushbutton helps with the power consumption issue. Fix the ringing properly by not making your input look like an LC tank - a resistor in series with each leg of the switch line should be fine, and they can also act as the current-limit resistors to your optoisolator's diode.

  • ground fault interrupter - it kills the power if a difference between A and N currents of more than a couple mA is detected, implying a leak to ground. Also known as ELCB (earth leakage circuit breaker) or just "safety switch" depending on where you live.

I know Polyglot doesn't like the idea, but depending on where you live, wiring is not a big issue.
If we forget all the legal stuff, this is my setup (all credits for the schematic to Vincent Himpe, alias free_electron):

This is working for quite a while at my home, no failure at all.
All with ordinary wires, though I admit that shielded wires would be preferrable. Total current consumption with closed switch is aprox. 2 mA.

This is the input, so I have no legal problem with it at all! It's not mains-safe of course, but achieving true galvanic isolation is expensive and power hungry.

I like the fact that your circuit clamps the voltage to about +5 using the GND line instead of using a diode to VCC, which would induce noise into VCC and cause stability issues. It does pull 0.7mA through R1/D3 with the switch open though, and you have no capacitance visible to the input until it rises to +5Vish, so I suspect it doesn't have as much noise immunity as you might want.

Given that you're using the arduino input which has very high impedance, I reckon you could rearrange it to have less static current consumption and less sensitivity to things being induced into the switch cable. Say remove R1 and D2, remove (short) D1, change D3 to 5.1V so it never conducts except induced spikes over 5V or below -0.7V. Change R2 to 4k7 and put another 4k7 in series with the switch at the end of the other wire, plus maybe another 5.1V zener to clamp your VCC against spikes on the other wire. That way with the switch closed it should draw only 90uA (5V/56k) and R2/C1 will still provide some good noise immunity with their corner frequency at 1kHz. Switch rise-time will be 2ms and fall time 10ms - plenty fast enough for a user interface. You could even increase C1 to make it slower and more noise-immune.

There might be some feature of that schematic I'm missing though...

This schematic is not made by me, but by someone designing harddisk controllers (a professional).
The idea is:
D2 is for negative spikes.
R2 and R3 are for power absorbing of high energy spikes.
R4 is for pull down.
R1 is 'opening' D3. Zeners are very slow, they could be damaged by a high energy spike.
D1 is for positive spikes, this spike is grounded via D3. Because of the slowness of D3, C1 is for capturing the first 'start of the spike'.

Maybe it's a bit overdone for home-purposes, but I've had some troubles with spikes conducted by switching power supplies and TL lighting, which was all gone with this solution.
With this, the voltage to the Arduino input will never be over 5V, although I don't know what the maximum input voltage is?
Otherwise it might be indeed an idea for a higher D3 for less power consumption.

Thanks so much for your input.
Now my biggest headache is finding a nice looking switch!