Uncategorized

relay notes

« first day (1 day earlier)

 

3:41 AM

@tlfong01 Those relays have a control to toggle the NO/NC, but obviously the problem is the same. I have a basic understanding of AC, of course. The problem is that I don’t know how to make the pi to have by default an OUT pin set to LOW. I think that would solve the problem.
4:40 AM

@IonicăBizău Your Idea of “Toggling NO/NC” is PLAIN WRONG. Have a nice day. Cheers.

@Ionică Bizău, Your wiring is plain WRONG! [Bulb] should go to [NO], Not [NC]! This is the root cause of all your troubles: ) – tlfong01 yesterday

@tlfong01 Not really, I can reverse them by using the relay toggle. Basically it’s the same thing. – Ionică Bizău 8 hours ago

4:59 AM

Why?
1 hour later…
6:28 AM

@IonicăBizău I repeat: you MUST NOT USE NC.
1 hour later…
7:54 AM

@tlfong01 Checking now using NO

Yes, that worked! ❤ Thank you very much. You can post an answer.

Thank you so much.
8:15 AM

@IonicăBizău Thank you for your kindness. However, I must decline your nice offer, because I find it difficult to give a satisfactory answer. I usually recommend the OP himself to give the answer, because he knows why he has the problem, and how he arrives at the answer, and perhaps any lessons learned, and because that would be most helpful to other newbie visitors.

 

=============================================================================

Feeds

Feeds
Fri 21:19
0

Q: How to turn off relay when RPi shuts down

Ionică BizăuI have connected a relay to BCM 14 and by setting its output to HIGH I can turn it on, making a 220V bulb to turn on. I use for that the following python instructions: GPIO.setmode(GPIO.BCM) GPIO.setup(14, GPIO.OUT) GPIO.output(14, GPIO.HIGH) However, if I power off the pi, the bulb remains …

tlfong01

tlfong01
3114
Hi @Ionică Bizău, your problem is interesting. There are a couple of possibilities, most likely one is explained below: (1) The wiring is simply wrong. The relay module has two parts (a) the control part which inputs a control signal from a Rpi GPIO pin. (b) The relay switch part which is the little blue thing with a switch inside which switches on off current. This current switch has three terminals (i) COM (Common), (ii) NO (Normally Open, not connected to COM), (iii) NC (Normally Closed, connected to COM). / to continue, …
You miay like to look at the real thing’s picture of my other answer below: raspberrypi.stackexchange.com/questions/113268/….

Ionică Bizău

Ionică Bizău
112k
@tlfong01 I think the issue is that even after I shut down the pi, the relay still gets current from the pins. I tried using BCM 8, which has OUT 1 by default and use LOW to turn on the bulb, and it works in the sense that after the pi is restarted the bulb turns off, but after turning off the pi, the relay is still in the same position.
@tlfong01 That is an amazing answer, but my case is a little bit different. Is it possible to change the default state of the pins? I think an OUT 0 would help, meaning, that mode is set by default to OUT, but current is LOW.

tlfong01

tlfong01
3114
Let us first make sure that you have wired the light bulb and relay correctly, before we move on to the Rpi GPIO. The correct wiring should be like this: (1) Mains Live goes to COM, (2) NO goes the one contact of light bulb, (3) Another contact of bulb goes to Neutral. Now let us consider following cases: (a) No 5V power to relay module case: relay switch is open, COM is not connected to NO (This is the spec of the relay module), therefore electrical current cannot go from COM to NO to bulb.
OK, if now you understand and agree on my correct method of wiring mains to relay switch and light bulb, we can move on to the Rpi GPIO stuff. First we need to make sure what type of relays is yours. You might like to give us a link to your relay. We need to know this, because there are two basic types of relays, (1) LOW level triggered, (2) High level triggered. For a Low level triggered module, if Rpi GPIO pin signal is Low, then module is triggered, switch is on (COM connected to NO), and if GPIO pin is High, then switch is off (COM not connected to NO). Vice versa for High trig module.

Jaromanda X

Jaromanda X
use a DIFFERENT GPIO PIN whose default state is LOW rather than HIGH – e.g. BCM 18 – two pins down – if you use LOW for on for this pin, then it’s probable that when you disconnect the power from the pi, the light will go on … you’re better off using HIGH = ON, and use a PIN other than any of those you see as V = 1 in your chart

tlfong01

tlfong01
3114
Now let us consider the Rpi’s GPIO’s default condition. Almost always, (1) Whenever you power up an Rpi, all GPIO pins are set to INPUT mode, (2) Even after powering up, say you have set any GPIO pin to OUTPUT mode, so to control things, and as soon as you CLEAN UP GPIO. ALL GPIO pins no matter previously set to output or input mode, will be AUTOMATICALLY set back to the initial default mode, ie INPUT mode.
Now the fun part: if a GPIO pin is in Input mode (for whatever reason/cause), then the relay module just don’t care and “blindly” sees it as an “EQUIVALENT OUTPUT MODE GPIO PIN SET to HIGH LEVEL OUTPUT”. This nonsense is one of the many sorrows of Rpi newbies weeping in the dark. Anyway, time for me to jog and supper. See you late this evening or tomorrow.
Ionică Bizău
Ionică Bizău
Fri 21:19
@tlfong01 Sorry, from the last comment I understand that IN and OUT 1 are going to turn on the bulb. So, is it possible to configure an OUT 0 by default?

tlfong01

tlfong01
3114
Ah, there seems some misunderstanding somewhere. Let us start from the sentence in you question, before the chart: “After restarting the Rpi, the command gpio readall shows the following chart… Now suppose we use BCM4, GPIO7 pin’s signal to control the relay module. At power up, this GPIO7 pin is in input mode, and voltage level is High. Now if your relay module is low trig, as in my answer, the relay switch is off, and light bulb is off. If you understand and agree what I have said so far, you can carry on my story, or you can comment or make counter suggestions.
Or if you like, you can use BCM8, CE0 to control the relay. Now at power up, CE0 is output mode, voltage High. So at power up, both relay and bulb are off. I know you might find it not reasonable or feel uncomfortable to let High signal to turn off something, and Low signal to turn on something. But that is what the EE guys like: Low to activate or trigger something. For the EE guys, turning on something using a High signal is bad manners (actually electrically inefficient, because of the nature of the optimally designed circuit).

Ionică Bizău

Ionică Bizău
@tlfong01 Well, that is my question about: if I use BCM8, unless the pi is running and output is HIGH, the bulb will be on. The problem here is that if the pi is disconnected, the bulb will turn on. If I use BCM4, the bulb will turn on when pi is restarted and will remain on until I set the mode to OUT.

tlfong01

tlfong01
3114
But in case you insist the “natural” way to use a High signal to turn on the relay and light bulb, and an Low signal to turn off relay and bulb. Then you can use a High trig relay KY019, shown in Appendix B of my answer. Now let us use GPIO7 as the control pin. At powering up, GPIO7 is input mode, voltage is High. But this High is a fake High, or “input mode High”, and is not an output logical signal to drive current into the base of the PNP BJT SS8050 to turn on the Songle switch. So again, all is well during start up.
For this High Trig KY019, if Rpi is disconnected, no source of current flows/drives SS8050, so switch is off. All is well.
In case you have not yet lost completely, let us go back to the the first relay, the Low Trig Opto JDVcc guy. Now if Rpi is disconnected, the relay’s IN terminal is dangling, or floating in the air. In other words, now the floating IN terminal can be in random, High state or Low state. Case 1: If High, then of course relay is off. Case 2: If Low, no problem either, because this is a “fake” Low, no current can be /sink pull out from optoisolator’s D1 LED. In other words, no problem both cases and you can sleep well. Ah, bed time! Call it a day. See you tomorrow. Cheers..
Ionică Bizău
Ionică Bizău
@tlfong01 Thank you very much for this information. What I still don’t understand is what I am trying to do is possible or I need more hardware to get this done.

tlfong01

tlfong01
3114
But I have no idea at all what actually is your hardware. I vaguely remember that I did ask for a link of your relay. But have you given me already? I am hopping among a couple of forums, entertaining different questions at the same time, so I might have missed or forgot something critical. My apologies. Anyway, see you tomorrow.
It is OK if you bought your toy from eBay and could no longer find the link. I can go through various types one by one, if you find your toy matches a certain type, then you know how to set up or do any modification if necessary. Now next type is the High/Low Trig Select Jumper Type, as shown in Appendix C. If you find the H/L jumper in your module, congratulation! No hardware change is necessary, just select the High option to make your toy High Level Triggered, and Day is Done: youtube.com/watch?v=Y2jxjv0HkwM.
Now let me introduce the first type of relay which needs hardware modification to make it Rpi compatible. Please read Appendix D for the details.
Appendix D has a complimentary workaround for the Rpi High is not high enough problem, for a Low triggered buzzer/relay circuit. The workaround this time is to add an resistor in series (last time is in parallel), to increase resistance, therefore smaller current to deactivate/untrigger the relay/buzzer. To summarize, the general trick is to add a 4k7 resistor in series or in parallel, to the input resistor. I know it is complicated. So if you can give the link or show me a photo of your toy, I can specifically explain how to solve your problem. No hurry at all. Cheers.
Ionică Bizău
Ionică Bizău
Fri 21:19
@tlfong01 I added details about the circuit and relay.
tlfong01
tlfong01
Thank you for the link. Please see Appendix C and D for newbie’s guidance. Good Luck. Cheers.
Ionică Bizău
Ionică Bizău

Milliways

Milliways
53.7k
You appear to be another victim of the shoddy products for sale on the web. The relay is UNSUITABLE for the Pi. They can be only be used with additional circuitry, or modifying the module. See raspberrypi.stackexchange.com/a/100014/8697 The particular model you linked would not meet the standards for mains isolation.
Ionică Bizău
Ionică Bizău
@Milliways What should I use instead of a relay to get this done (turn on a light bulb programatically, but making sure it stays turned off if my program does not run)?

Milliways

Milliways
@IonicăBizău there is nothing wrong with using a relay – indeed this is one of the recommended methods. The problem is the poorly designed relay module which is unsuitable for the Pi – there are modules designed to be controlled by 3.3V logic levels, although they are swamped by the thousands of dodgy modules on ebay.
The last message was posted 2 days ago.

Feeds

Feeds
Fri 21:19
0

Q: How to turn off relay when RPi shuts down

Ionică BizăuI have connected a relay to BCM 14 and by setting its output to HIGH I can turn it on, making a 220V bulb to turn on. I use for that the following python instructions: GPIO.setmode(GPIO.BCM) GPIO.setup(14, GPIO.OUT) GPIO.output(14, GPIO.HIGH) However, if I power off the pi, the bulb remains …

tlfong01

tlfong01
3114
Hi @Ionică Bizău, your problem is interesting. There are a couple of possibilities, most likely one is explained below: (1) The wiring is simply wrong. The relay module has two parts (a) the control part which inputs a control signal from a Rpi GPIO pin. (b) The relay switch part which is the little blue thing with a switch inside which switches on off current. This current switch has three terminals (i) COM (Common), (ii) NO (Normally Open, not connected to COM), (iii) NC (Normally Closed, connected to COM). / to continue, …
You miay like to look at the real thing’s picture of my other answer below: raspberrypi.stackexchange.com/questions/113268/….

Ionică Bizău

Ionică Bizău
112k
@tlfong01 I think the issue is that even after I shut down the pi, the relay still gets current from the pins. I tried using BCM 8, which has OUT 1 by default and use LOW to turn on the bulb, and it works in the sense that after the pi is restarted the bulb turns off, but after turning off the pi, the relay is still in the same position.
@tlfong01 That is an amazing answer, but my case is a little bit different. Is it possible to change the default state of the pins? I think an OUT 0 would help, meaning, that mode is set by default to OUT, but current is LOW.

tlfong01

tlfong01
3114
Let us first make sure that you have wired the light bulb and relay correctly, before we move on to the Rpi GPIO. The correct wiring should be like this: (1) Mains Live goes to COM, (2) NO goes the one contact of light bulb, (3) Another contact of bulb goes to Neutral. Now let us consider following cases: (a) No 5V power to relay module case: relay switch is open, COM is not connected to NO (This is the spec of the relay module), therefore electrical current cannot go from COM to NO to bulb.
OK, if now you understand and agree on my correct method of wiring mains to relay switch and light bulb, we can move on to the Rpi GPIO stuff. First we need to make sure what type of relays is yours. You might like to give us a link to your relay. We need to know this, because there are two basic types of relays, (1) LOW level triggered, (2) High level triggered. For a Low level triggered module, if Rpi GPIO pin signal is Low, then module is triggered, switch is on (COM connected to NO), and if GPIO pin is High, then switch is off (COM not connected to NO). Vice versa for High trig module.

Jaromanda X

Jaromanda X
use a DIFFERENT GPIO PIN whose default state is LOW rather than HIGH – e.g. BCM 18 – two pins down – if you use LOW for on for this pin, then it’s probable that when you disconnect the power from the pi, the light will go on … you’re better off using HIGH = ON, and use a PIN other than any of those you see as V = 1 in your chart

tlfong01

tlfong01
3114
Now let us consider the Rpi’s GPIO’s default condition. Almost always, (1) Whenever you power up an Rpi, all GPIO pins are set to INPUT mode, (2) Even after powering up, say you have set any GPIO pin to OUTPUT mode, so to control things, and as soon as you CLEAN UP GPIO. ALL GPIO pins no matter previously set to output or input mode, will be AUTOMATICALLY set back to the initial default mode, ie INPUT mode.
Now the fun part: if a GPIO pin is in Input mode (for whatever reason/cause), then the relay module just don’t care and “blindly” sees it as an “EQUIVALENT OUTPUT MODE GPIO PIN SET to HIGH LEVEL OUTPUT”. This nonsense is one of the many sorrows of Rpi newbies weeping in the dark. Anyway, time for me to jog and supper. See you late this evening or tomorrow.
Ionică Bizău
Ionică Bizău
Fri 21:19
@tlfong01 Sorry, from the last comment I understand that IN and OUT 1 are going to turn on the bulb. So, is it possible to configure an OUT 0 by default?

tlfong01

tlfong01
3114
Ah, there seems some misunderstanding somewhere. Let us start from the sentence in you question, before the chart: “After restarting the Rpi, the command gpio readall shows the following chart… Now suppose we use BCM4, GPIO7 pin’s signal to control the relay module. At power up, this GPIO7 pin is in input mode, and voltage level is High. Now if your relay module is low trig, as in my answer, the relay switch is off, and light bulb is off. If you understand and agree what I have said so far, you can carry on my story, or you can comment or make counter suggestions.
Or if you like, you can use BCM8, CE0 to control the relay. Now at power up, CE0 is output mode, voltage High. So at power up, both relay and bulb are off. I know you might find it not reasonable or feel uncomfortable to let High signal to turn off something, and Low signal to turn on something. But that is what the EE guys like: Low to activate or trigger something. For the EE guys, turning on something using a High signal is bad manners (actually electrically inefficient, because of the nature of the optimally designed circuit).

Ionică Bizău

Ionică Bizău
@tlfong01 Well, that is my question about: if I use BCM8, unless the pi is running and output is HIGH, the bulb will be on. The problem here is that if the pi is disconnected, the bulb will turn on. If I use BCM4, the bulb will turn on when pi is restarted and will remain on until I set the mode to OUT.

tlfong01

tlfong01
3114
But in case you insist the “natural” way to use a High signal to turn on the relay and light bulb, and an Low signal to turn off relay and bulb. Then you can use a High trig relay KY019, shown in Appendix B of my answer. Now let us use GPIO7 as the control pin. At powering up, GPIO7 is input mode, voltage is High. But this High is a fake High, or “input mode High”, and is not an output logical signal to drive current into the base of the PNP BJT SS8050 to turn on the Songle switch. So again, all is well during start up.
For this High Trig KY019, if Rpi is disconnected, no source of current flows/drives SS8050, so switch is off. All is well.
In case you have not yet lost completely, let us go back to the the first relay, the Low Trig Opto JDVcc guy. Now if Rpi is disconnected, the relay’s IN terminal is dangling, or floating in the air. In other words, now the floating IN terminal can be in random, High state or Low state. Case 1: If High, then of course relay is off. Case 2: If Low, no problem either, because this is a “fake” Low, no current can be /sink pull out from optoisolator’s D1 LED. In other words, no problem both cases and you can sleep well. Ah, bed time! Call it a day. See you tomorrow. Cheers..
Ionică Bizău
Ionică Bizău
@tlfong01 Thank you very much for this information. What I still don’t understand is what I am trying to do is possible or I need more hardware to get this done.

tlfong01

tlfong01
3114
But I have no idea at all what actually is your hardware. I vaguely remember that I did ask for a link of your relay. But have you given me already? I am hopping among a couple of forums, entertaining different questions at the same time, so I might have missed or forgot something critical. My apologies. Anyway, see you tomorrow.
It is OK if you bought your toy from eBay and could no longer find the link. I can go through various types one by one, if you find your toy matches a certain type, then you know how to set up or do any modification if necessary. Now next type is the High/Low Trig Select Jumper Type, as shown in Appendix C. If you find the H/L jumper in your module, congratulation! No hardware change is necessary, just select the High option to make your toy High Level Triggered, and Day is Done: youtube.com/watch?v=Y2jxjv0HkwM.
Now let me introduce the first type of relay which needs hardware modification to make it Rpi compatible. Please read Appendix D for the details.
Appendix D has a complimentary workaround for the Rpi High is not high enough problem, for a Low triggered buzzer/relay circuit. The workaround this time is to add an resistor in series (last time is in parallel), to increase resistance, therefore smaller current to deactivate/untrigger the relay/buzzer. To summarize, the general trick is to add a 4k7 resistor in series or in parallel, to the input resistor. I know it is complicated. So if you can give the link or show me a photo of your toy, I can specifically explain how to solve your problem. No hurry at all. Cheers.
Ionică Bizău
Ionică Bizău
Fri 21:19
@tlfong01 I added details about the circuit and relay.
tlfong01
tlfong01
Thank you for the link. Please see Appendix C and D for newbie’s guidance. Good Luck. Cheers.
Ionică Bizău
Ionică Bizău

Milliways

Milliways
53.7k
You appear to be another victim of the shoddy products for sale on the web. The relay is UNSUITABLE for the Pi. They can be only be used with additional circuitry, or modifying the module. See raspberrypi.stackexchange.com/a/100014/8697 The particular model you linked would not meet the standards for mains isolation.
Ionică Bizău
Ionică Bizău
@Milliways What should I use instead of a relay to get this done (turn on a light bulb programatically, but making sure it stays turned off if my program does not run)?

Milliways

Milliways
@IonicăBizău there is nothing wrong with using a relay – indeed this is one of the recommended methods. The problem is the poorly designed relay module which is unsuitable for the Pi – there are modules designed to be controlled by 3.3V logic levels, although they are swamped by the thousands of dodgy modules on ebay.
The last message was posted 2 days ago.
.END

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.