emal011
Posts: 3
Joined: Mon Feb 18, 2019 12:36 pm

Problem with Relay and GPIO

Mon Feb 18, 2019 12:59 pm

Hi,

I bought a 4 relay board for some test purpouse, before I was using a single relay board wich was working fine. I was trying to use the same code in order to don't change to much, but I found some probllems, and I don't know if it is the code or the board itself.
The Problem with the new board is, even if I write that just port 1 should be on and the rest off, two of them turn on.

The code:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
RELAIS_LIST = [11,13,15]
GPIO.setup(RELAIS_LIST, GPIO.OUT)

print("Relay 1")
GPIO.output(RELAIS_LIST,(GPIO.HIGH, GPIO.LOW, GPIO.LOW))
time.sleep(5)
GPIO.output(RELAIS_LIST, GPIO.LOW)

print("Relay 2")
GPIO.output(RELAIS_LIST, (GPIO.LOW, GPIO.HIGH, GPIO.LOW))
time.sleep(5)
GPIO.output(RELAIS_LIST, GPIO.LOW)

print("Relay 3")
GPIO.output(RELAIS_LIST, (GPIO.LOW, GPIO.LOW, GPIO.HIGH))
time.sleep(5)
GPIO.output(RELAIS_LIST, GPIO.LOW)

print("Exit application")
time.sleep(5)
GPIO.cleanup()

And the Result:

Relay 1 : IN2 and IN3
Relay 2 : IN1 and IN3
Relay 3 : IN1 and IN3

The Board:

Pi ~ Relay:

DC Power 5v Pin 04 ~ VCC
Ground : Pin 06 ~ GND
GPIO17 Pin 11 ~ IN1
GPIO27 Pin 13 ~ IN2
GPIO22 Pin 15 ~ IN3

As I said, I don't know if it is the code, or the board. Have someone an Idea? why it doesn't work at it should be?

Thanks in advance for the replies.

ML

User avatar
MrYsLab
Posts: 331
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Problem with Relay and GPIO

Mon Feb 18, 2019 1:29 pm

Perhaps the "on" is a low and off is a "high". Try reversing the sense of the outputs.

pcmanbob
Posts: 6180
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with Relay and GPIO

Mon Feb 18, 2019 1:44 pm

Hi.

It might help if you post a link to the relay board you purchased so we know what you are trying to connect to your pi.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

emal011
Posts: 3
Joined: Mon Feb 18, 2019 12:36 pm

Re: Problem with Relay and GPIO

Mon Feb 18, 2019 1:47 pm

pcmanbob wrote:
Mon Feb 18, 2019 1:44 pm
Hi.

It might help if you post a link to the relay board you purchased so we know what you are trying to connect to your pi.
yes of course.

Image

emal011
Posts: 3
Joined: Mon Feb 18, 2019 12:36 pm

Re: Problem with Relay and GPIO

Mon Feb 18, 2019 1:55 pm

MrYsLab wrote:
Mon Feb 18, 2019 1:29 pm
Perhaps the "on" is a low and off is a "high". Try reversing the sense of the outputs.
Excellent Theory, and well, you are right.. Just I can't explain myself why this is happend. Now everything works as it should!

User avatar
MrYsLab
Posts: 331
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Problem with Relay and GPIO

Mon Feb 18, 2019 2:35 pm

Looking at the info about your board:
"Standard interface that can be controlled directly by microcontroller (Arduino , 8051, AVR, PIC, DSP, ARM, ARM, MSP430, TTL logic active low)"

The relays are active low .

Return to “Python”