Detecting when switch is closed - Raspberry Pi Forums


hi all,

i'm new pi , electricals/electonics @ hobby level.
want use pi detect when contact closed. when motor engaged, circuit closed , existing circuit has lightbulb connected comes indicate motors engaged. connect pi contact can notified through pi when motors engaged.

have tried setup pictured on right, not sure if right way go it.
have connected inputs pi correctly (i.e. pin , gnd)?
design meaningful/appropriate?

have tried connect pi pictured bcm_gpio23 , gnd , enabled internal pullup resistor. when motor closed (contact opened) high when motor opened (contact closed) randomly both high , low until motor closed , constant high again. behavious makes plan unreliable cannot tell if motor closed or opened randomly checking pin input value.

please advise i've done wrong , better way. thanks
photoscan.jpg
photoscan.jpg (55.68 kib) viewed 727 times

i see no image
i'm not sure have done, if chucking if switch open/closed how did it
toggle switch used play/pause button (wire pin 11 switch more wire +3.3v pin)
not know powering motor , light bulb, assume not 120v ac stuff sound pi did not explode, unless used double poll switch 1 poll pi , 1 motor

code: select all

#!/usr/bin/python subprocess import call import rpi.gpio gpio import time  pin = 11 gpio.setmode(gpio.board) gpio.setup(pin, gpio.in, pull_up_down=gpio.pud_down)  try: 	while true: 		val = gpio.input(pin) 		if val == 1: 			call(["mpc","play"]) 		else: 			call(["mpc","pause"]) 		while gpio.input(pin) == val: 			time.sleep(0.75) except keyboardinterrupt: 	gpio.cleanup()


raspberrypi



Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support