0

Upon running the following script my relay stays open when the GPIO pin is set to output. In all my attempts. there has not been any way for me to alter this behaviour.

The code I've ran:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

try:
    print('1: ')

    time.sleep(2)
    GPIO.output(17, False)
    print(GPIO.input(17))

    print('2: ')

    time.sleep(2)
    GPIO.output(17, True)
    print(GPIO.input(17))

    print('3: ')

    time.sleep(2)
    GPIO.output(17, False)
    print(GPIO.input(17))

    print('4: ')

finally:
    GPIO.cleanup()

The GPIO.input returns me changed values, output when code is ran:

1:
0
2:
1
3:
0
4:

This seems pretty odd to me, given that I am 100% sure I am powering on the right GPIO pin. The GPIO pin is High from the moment the pin is set as an output until when the GPIO gets cleaned.

1 Answer 1

1

The pin clearly not does stay high as the read back indicates the correct values (0 when you write False, and 1 when you write True).

There are a number of possibilities.

  • The likeliest is that the relay is not compatible with the Pi (i.e. it requires 5V control). Impossible to comment without having a link to the relay module you have bought.
  • You have not connected to the correct GPIO. See https://pinout.xyz/. Broadcom GPIO 17 is attached to pin 11. Impossible to comment without a photo of the connections.
3
  • I have a 5V relay. What confuses me is that the activation LED is lit while the pin is set as an output. Does this not mean that the relay is functioning? I can hear the click when I start the program. Commented Dec 14, 2018 at 9:04
  • I also doublechecked the gpio connection once again. The gpio pin used to connect to the "in" is pin 11/BCM17. Commented Dec 14, 2018 at 9:06
  • a click means nothing - if the relay requires more than 3v3 on in to switch then the LED may well "light up" but the relay may not actually switch at all - it's hard to say without knowing anything about the relay you are using Commented Dec 14, 2018 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.