Page 1 of 1

HELP! , Relay module always on

Posted: Wed Jan 10, 2018 5:35 pm
by joseplaselva
To test a Relay Module SRD-5VDC -SL-C with my Raspberry Pi3 , I run this litte script just to test, but from the beginning the relay stay activated and do not stop until I clean the GPIO.. Can someone give me a solution to this , My goal is to us a relay to run a heater when a temperature sensor give a determinate reading, so I need to put On and OFF the relay in function of the remperature read.
VCC pin in conected to GPIO 5v (4 on board)
Gnd to GROUND (9 on board
and In1 to pin 17 (11 on board)
Thanks in advance.

Code: Select all

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

RelayPin = 17    


GPIO.setmode(GPIO.BCM)       
GPIO.setup(RelayPin, GPIO.OUT)
GPIO.output(RelayPin, GPIO.HIGH)

print " starting on 5 seconds"
time.sleep(5)

print '...relay on'
GPIO.output(RelayPin, GPIO.LOW)
time.sleep(10)
	

print '...relay off'
GPIO.output(RelayPin, GPIO.HIGH)
time.sleep(10)
GPIO.cleanup()  

Re: HELP! , Relay module always on

Posted: Wed Jan 10, 2018 5:43 pm
by Mortimer
The product code you gave us relates to just the relay. What board is the relay on? Where does the board come from? Did any instruction or diagrams come with the board?

Re: HELP! , Relay module always on

Posted: Wed Jan 10, 2018 9:31 pm
by joseplaselva
Sorry, the board is a HL-51 V1.0

Re: HELP! , Relay module always on

Posted: Wed Jan 10, 2018 10:26 pm
by pcmanbob
That relay board looks like it is ment to work with the Arduino which has a 5V gpio were as the pi has a 3.3V gpio this type of board can be made to work if you use a transistor between the pi gpio and the relay board.
A 2N2222 with a 470 ohm resistor on connected between the base and the gpio pin on the pi
Then connect the collector leg to the relay board and the emitter leg to ground. Should be all you need.

Re: HELP! , Relay module always on

Posted: Thu Jan 11, 2018 3:38 pm
by joseplaselva
Hi,thanks for your fast reply, I gonna try this circuit with transistor and resistor.
I have tested putting the power to the GPIO1 with 3 volts and now is working... feels less strong when relay is activated but it respond to the GPIO low and high... I gonna test more times to check if it is stable.
Thanks again for your kind help.
Best redgards