User avatar
joseplaselva
Posts: 94
Joined: Tue Oct 04, 2016 4:45 am
Location: Kvilla , Sweden

HELP! , Relay module always on

Wed Jan 10, 2018 5:35 pm

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()  

User avatar
Mortimer
Posts: 924
Joined: Sun Jun 10, 2012 3:57 pm

Re: HELP! , Relay module always on

Wed Jan 10, 2018 5:43 pm

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?
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
joseplaselva
Posts: 94
Joined: Tue Oct 04, 2016 4:45 am
Location: Kvilla , Sweden

Re: HELP! , Relay module always on

Wed Jan 10, 2018 9:31 pm

Sorry, the board is a HL-51 V1.0

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

Re: HELP! , Relay module always on

Wed Jan 10, 2018 10:26 pm

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.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
joseplaselva
Posts: 94
Joined: Tue Oct 04, 2016 4:45 am
Location: Kvilla , Sweden

Re: HELP! , Relay module always on

Thu Jan 11, 2018 3:38 pm

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

Return to “Python”