switch with long wires not working

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
jlra2fael
New user
Posts: 1
Joined: 15 Mar 2017, 02:20

switch with long wires not working

#1 Post by jlra2fael » 15 Mar 2017, 12:44

Hello,

I’m trying to use a door magnetic switch wired between a GPIO pin and the ground but it’s not working.
I tried to connect the 2 wires connected to the pins near the switch but it doesn’t work.
If I connect the 2 pins on the board it works successfully.

I tried with and without pull-up activated.

I’m using phone twisted pairs wire of around 10m, I checked the continuity of the wires and also tried another pair of wires.
Could it a problem of length or because the wires are running along the house 230V wiring and may catch some noise from it.
What could be the solution to fix this as I can't move closer the box containing the board?
Thanks

bobbybeans
Normal user
Posts: 119
Joined: 26 Feb 2017, 17:30

Re: switch with long wires not working

#2 Post by bobbybeans » 15 Mar 2017, 12:58

most likely the cable is too long you would have to much voltage drop to do anything
2 things you could try just for diagnosing
if you have a multimeter measure the voltage at the source then again at the destination. the difference is the voltage drop. if you have crappy cable the resistance is high causing more of a drop and the longer it is the more v drop there is
if you don't have a multimeter just try it with a short cable , try it with a 5 cm cable if that works try it with 2 meter then 5 etc, then you can figure out the max length

a solution is either shorter cable most likely
or a booster so it takes the input voltage stores it then amplifies it to go farther not sure how that would interact negatively or positively with a switch

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: switch with long wires not working

#3 Post by toffel969 » 16 Mar 2017, 23:03

You could try to use a level shifter to 5v. That voltage might suffice as logic level should be high down to 2v on both 3,3 or 5v afaik
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: switch with long wires not working

#4 Post by Shardan » 17 Mar 2017, 00:12

Hello,

A somewhat simple solution might be an opto coupler.
The 817 (EL-817, KB 817, LTV 817 or similiar) is cheap, just some cents.
opto.jpg
opto.jpg (61.46 KiB) Viewed 2860 times
It might be possible that the 680 Ohm resistor is a bit too much, depends on your cabling.
The current through the opto coupler LED should be 5..6 mA, check with a standard digital meter.

If you want to use 3,3 V for the LED the resistor should start with 360 Ohms, maybe less but i'd advise to use 5V if possible.
Higher voltages up to 12 V (on the LED side ONLY!) are possible. Calculate the resistor with (voltage -1,4) / 0,005 = resistor value (Ohm)

This keeps disturbances from the 230V mains out of your GPIO circuit, a "current loop" is more reliable then simply voltage high or low.
On top the opto coupler is less sensitive then a level shifter so spikes from the line won't damage anything.

Anyways, for better reliability you should put a double capacitor between 3,3V and ground, an electrolytic cap of about 220...470 µF
and a ceramic type of about 100... 470 nF.

The internal pull up should be deactivated with this circuit, or you may ommit the 4K7 resistor.

Regards
Shardan
Regards
Shardan

Post Reply

Who is online

Users browsing this forum: No registered users and 64 guests