1
\$\begingroup\$

I have connected a 2 channel 12 v relay like this to the GPIO of my Raspberry pi. The relay is used to switch on and off an AC lightbulb.

I am using this code to turn on/off the relay:

import RPi.GPIO as io
import time
io.setmode(io.BOARD)
io.setup(5,io.OUT)
io.output(5, not io.input(5))

Connected like this:

schematic

simulate this circuit – Schematic created using CircuitLab

The light instantly turns off when it is already on, but not the other way.

The problem: I have to tap the relay in order for the light to turn on after running the code. The amount of time after running the code does not matter.

asked Dec 11, 2017 at 14:50
\$\endgroup\$
7
  • 1
    \$\begingroup\$ What voltage are you supplying to it? \$\endgroup\$ Commented Dec 11, 2017 at 15:11
  • \$\begingroup\$ What do your connections look like? Can you post a schematic? \$\endgroup\$ Commented Dec 12, 2017 at 15:39
  • \$\begingroup\$ Supplying 5v from the Raspberry Pi @ignacio-vazquez-abrams \$\endgroup\$ Commented Dec 12, 2017 at 16:34
  • 1
    \$\begingroup\$ Updated now @evildemonic \$\endgroup\$ Commented Dec 12, 2017 at 16:34
  • 1
    \$\begingroup\$ The relays shown in your link require 12 Volts for proper operation. They are unlikely to operate with only 5 volts. \$\endgroup\$ Commented Dec 12, 2017 at 17:03

2 Answers 2

1
\$\begingroup\$

The board you are using is intended for 12V VCC, and has 12V relays. A typical relay may only trigger on 80% of its nominal coil voltage, but it will hold at 40% of the coil voltage. This means that when you power it at 5V, it's not enough to turn on, but once you physically force the relay to close, then the 5V is fine.

While there are ways to use the existing board, your best option is getting a 5V relay board.

answered Dec 12, 2017 at 17:21
\$\endgroup\$
0
\$\begingroup\$

You say it's a 12V relay, but you're only running the coil on 5V. Is the rated coil voltage compatible with a 5V drive?

You may also be hitting the GPIO maximum sink current connecting a relay directly to the GPIO pin, in which case, the relay may not even be getting the full 5V.

answered Dec 12, 2017 at 17:05
\$\endgroup\$
3
  • \$\begingroup\$ The board uses a opto isolator and a transistor driver for the relay, so the 3.3V gpio is not directly driving the relay. \$\endgroup\$ Commented Dec 12, 2017 at 17:22
  • \$\begingroup\$ @Passerby In that case, your diagram is wrong, as it shows 5V going to the relay coil. \$\endgroup\$ Commented Dec 12, 2017 at 17:33
  • \$\begingroup\$ Not my diagram, op has simplified the board. It's more of a block diagram. \$\endgroup\$ Commented Dec 12, 2017 at 17:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.