Josvds
Posts: 18
Joined: Thu Oct 29, 2015 9:04 pm

GPIO Switch not working

Wed Jan 18, 2017 8:24 pm

I want to create a managed light switch in my garage.
I have one pipe where i have put the electricity cable and also a 2mm cable for the switch.
The switch is connected with to wires directly to the raspberry.

When i tested it on my desktop it worked file.
After conencting the switch in my garage the item returns the message 'Button Pressed' without stopping when switching...

What can i do?

See the attachment for how i connected it in test.
A drawing of how i connected it in the garage.

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    input_state = GPIO.input(18)
    if input_state == False:
        print('Button Pressed')
        time.sleep(0.2)
Attachments
Tekening.fw.png
Tekening.fw.png (60.99 KiB) Viewed 1372 times

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: GPIO Switch not working

Wed Jan 18, 2017 11:45 pm

Looks like it's dropping voltage. How long is the cable? Can you measure the voltage at the switch?
Submarine communication systems engineer and amateur robot enthusiast.

Josvds
Posts: 18
Joined: Thu Oct 29, 2015 9:04 pm

Re: GPIO Switch not working

Thu Jan 19, 2017 7:49 am

Details from the project:
* The wire is about 10 meter near the 230v cable.
* The 230v cable is three wires of 2.5mm.
* The switch is connected by two 0.5mm wires.
* Both are in the same pipe
* Switch wire 1 is connected to pin 18, switch wire 2 is connected to GRND.

This is how i connected it in test.
The attachment Photo.jpg is no longer available
The attachment Photo.jpg is no longer available
Attachments
Photo2.jpg
Photo2.jpg (63.19 KiB) Viewed 1252 times
Photo.jpg
Photo.jpg (38.29 KiB) Viewed 1259 times

drgeoff
Posts: 10765
Joined: Wed Jan 25, 2012 6:39 pm

Re: GPIO Switch not working

Thu Jan 19, 2017 10:51 am

The GPIO wires will be picking up a substantial AC voltage from the mains cable.

You can try adding an external pull up resistor, say 330 ohms, at the RPi.

Josvds
Posts: 18
Joined: Thu Oct 29, 2015 9:04 pm

Re: GPIO Switch not working

Thu Jan 19, 2017 2:48 pm

Ok, thanks i will try this tonight..

Josvds
Posts: 18
Joined: Thu Oct 29, 2015 9:04 pm

Re: GPIO Switch not working

Thu Jan 19, 2017 10:18 pm

I was able to fix it by using a 10k resistor.. But after a while the button flipped without using the switch..
I did change my connection to this https://www.raspberrypi.org/learning/ph ... l_up_down/

3v > switch > (300 resistor > Pin 18) AND (10k resistor > Grnd)

Thanks for your help..

drgeoff
Posts: 10765
Joined: Wed Jan 25, 2012 6:39 pm

Re: GPIO Switch not working

Thu Jan 19, 2017 11:50 pm

If the switch cable is a flat twin eg bell-wire, that is much more susceptible to pickup than a twisted pair.

Return to “Beginners”