I have a Python script which should read if a switch is pressed (a normal light switch).
This switch I've connected to GPIO pin 40 and GND
I read the state of GPIO:
GPIO_startprog1=20
GPIO.setFunction(GPIO_startprog1, GPIO.IN)
if (GPIO.digitalRead(GPIO_startprog1) == GPIO.HIGH):
print ("Prog 1 Start by press button")
Prog1()
def Prog1():
...............
The moment I connect a wire to pin 38 (GPIO20) my readings are randomly flipping between high and low. Touching the wire with your fingers causes more GPIO.HIGH
s (I can monitor the state of the GPIO pins with a tool named WebIOPi).
What is the proper method to detect if a physical switch is on/off? I just need a clear and simple GPIO.HIGH
or GPIO.LOW
.