Schnell
Posts: 19
Joined: Sat Jun 21, 2014 4:02 am

Rebooting R-Pi causes relay to click on.

Wed Sep 16, 2015 11:26 pm

I have a raspberry pi that I've been using to turn on a AC Solid state relay for my desktop light. It was all working fine with no issues until I replaced it with a DC SSR. Now when I reset the raspberry pi, the relay will click on which causes the light to turn on any time the power is cut to the pi. I've read about this happening but I can't find where I read it anyway and was wondering if anyone had any input on this. The pins I'm using to output a signal to the relay are the 5v for power and pin 7(on the board, not BCM). Here is the code that gets executed to turn the light on:

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.output(7, not GPIO.input(7))

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 12:04 am

If that's your code then it is non-deterministic. You are setting the output based on the inverse of its current state, but that could be high or low. You should explicitly set the output high or low when you initialise everything. After that you can use the not operator to invert the state.

Another thing you can do is add a pull-up or pull-down resistor to your GPIO pin to set the 'default' state of the pin when it is not being driven. Obviously you would choose the pull-up or pull-down to keep the relay turned off.

Schnell
Posts: 19
Joined: Sat Jun 21, 2014 4:02 am

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 12:11 am

Are there any tutorials for this or is it simple enough for you or someone to explain? Most of what I've been doing on the rpi in terms of using Python I've followed tutorials. Any help right now would be very good as I'm pretty green when it comes to this, as you can tell. :D

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 12:22 am

There are tons of tutorials, but the best thing to do is read the RPi.GPIO documention and try various things.

This code will set the output high:

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.output(7, True)
This code will set the output low:

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.output(7, False)
In both cases the output pin is being set to an explicit state (either True, which is High or 3.3V, or False, which is Low or 0V).

But, if your relay is clicking on when the Pi is rebooted then it's not under the control of your program. That's where applying a pull-up or pull-down would come into play.

Can you send a link to the relay module you are using, and describe how it is connected to your Pi?

Schnell
Posts: 19
Joined: Sat Jun 21, 2014 4:02 am

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 12:25 am

Here is the relay I was using: http://www.amazon.com/gp/product/B0079W ... ge_o03_s00

And here is the one that I'm using now: http://www.amazon.com/gp/product/B00IZ3 ... ge_o00_s00

Oops sorry, I forgot to explain how it's connected.
The channel 1 connection is connected to the pi via pin 7. I use the 5v pin to power the relay itself with a ground 2 pins below the 5v.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 12:46 am

Schnell wrote:Here is the relay I was using: http://www.amazon.com/gp/product/B0079W ... ge_o03_s00

And here is the one that I'm using now: http://www.amazon.com/gp/product/B00IZ3 ... ge_o00_s00

Oops sorry, I forgot to explain how it's connected.
The channel 1 connection is connected to the pi via pin 7. I use the 5v pin to power the relay itself with a ground 2 pins below the 5v.
I'm not sure I found the exact schematic on the Sain Smart site, but I think you should be using 3.3V for VCC. Also, the board has a pull-down resistor built-in, so that ought to prevent unwanted triggering.

Schnell
Posts: 19
Joined: Sat Jun 21, 2014 4:02 am

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 1:06 am

Alright. I switched it over to the 3.3v pin and the same thing happens. Something to note, the relay turns on as soon as the raspberry pi turns on. If I turn the pi off with the surge protector, as soon as I click it back on the relay turns on. Could Pin7 for some reason be automatically defaulting to high when the pi turns on?

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 1:11 am

Schnell wrote:Alright. I switched it over to the 3.3v pin and the same thing happens. Something to note, the relay turns on as soon as the raspberry pi turns on. If I turn the pi off with the surge protector, as soon as I click it back on the relay turns on. Could Pin7 for some reason be automatically defaulting to high when the pi turns on?
Yes. It's possible that your Pi happens to have something driving that pin. Try another pin, but not pin 3 or 5 as they have pull-ups fitted, and not pins 8 or 10 as they are for serial IO and may be driven by random serial data during startup.

Schnell
Posts: 19
Joined: Sat Jun 21, 2014 4:02 am

Re: Rebooting R-Pi causes relay to click on.

Thu Sep 17, 2015 1:23 am

Well, switching it to pin 13 seemed to have fixed it. Thank you for your help. :D Have a good day/noon/night!

Return to “Troubleshooting”