guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 7:50 am

Hi,
I'm using RPI + Relay to control a motorize window shade ( shades are motorized, just adding RPI to enable UP/Down using code ).
On the table - code works fine, relays toggle as needed for many days and operations ( very fast switching is tested as well ), using code and physical button.

The problem is : after connecting the hardware to window's motor ,switching causes ( by physical button or by code) RPI to freeze, only after plugging out and back in, restore it functionality.

ALL hardware was replace: new RPI, new relay, DC converter, USB cable, and still freezes happens when only switching with motor connected to relay.

Any Ideas ??

Guy

PiGraham
Posts: 3279
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 7:56 am

How are you powering the Pi, relay and motor?
What do you mean by "freeze"?

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 8:04 am

1. RPI was powered in two ways ( both failed ): power supply 5VDC connected to wall 220AC, external battery ( such as phone charger ).
2. relay is connected directly to RPI ( 5V to VCC, GND to GND, GPIO20, to relay signal )
3. freeze = code stop running, does not answer to ping, cant connect using ssh , green led in ON constantly

PiGraham
Posts: 3279
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 8:31 am

guyd wrote:
Wed Jul 11, 2018 8:04 am
1. RPI was powered in two ways ( both failed ): power supply 5VDC connected to wall 220AC, external battery ( such as phone charger ).
2. relay is connected directly to RPI ( 5V to VCC, GND to GND, GPIO20, to relay signal )
3. freeze = code stop running, does not answer to ping, cant connect using ssh , green led in ON constantly
One possibility is that the current taken by the relay coil disrupts the Pi 5V. Another possibility is that switching the motor causes a problem.How is the motor powered?
In general it's best to avoid inductive loads like relay coils or motor windings connected to logic supply rails.
Try connecting the relay VCC to a different supply than the Pi.

You mention 5V for the relay but the Pi GPIO is not 5V safe. Are you sure the relay input doesn't feed 5V into the GPIO?


Does the freexe occur every time the motor turns on, or turns off?

Can you make it freeze is you switch the input to the relay with a switch instead of a GPIO output?

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 9:14 am

Hi,

Motor is powered from wall (220VAC), 4 wires : 0, GND, Ph-UP, Ph-DOWN. . relay switch power to UP wire, or Down wire ( 2 different relays ).
my biggest confusion is what is the connection between switching power to the motor, can FREEZE the RPI.

a) i'll try later on to connect Relay to external power supply. thank you
b) realy's VCC is 5V- what do you mean it is not SAFE ? I'm using PI's 5V dedicated pin. is it not safe ?
c) the freeze does not happens every time but it can occur after few switches, mostly after 50 it occur. firstly i tought i was cause by physical button - but after I wrote a code to make fast switching ( on/off every 0.5 sec ) - and it always occur after 10-20 times.
d) please explain you last question

PiGraham
Posts: 3279
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 3:36 pm

guyd wrote:
Wed Jul 11, 2018 9:14 am
Hi,

Motor is powered from wall (220VAC), 4 wires : 0, GND, Ph-UP, Ph-DOWN. . relay switch power to UP wire, or Down wire ( 2 different relays ).
my biggest confusion is what is the connection between switching power to the motor, can FREEZE the RPI.

a) i'll try later on to connect Relay to external power supply. thank you
b) realy's VCC is 5V- what do you mean it is not SAFE ? I'm using PI's 5V dedicated pin. is it not safe ?
The Pi gpio work on 3.3V. connecting 5V to them can cause damage to the Pi.
guyd wrote:
Wed Jul 11, 2018 9:14 am
c) the freeze does not happens every time but it can occur after few switches, mostly after 50 it occur. firstly i tought i was cause by physical button - but after I wrote a code to make fast switching ( on/off every 0.5 sec ) - and it always occur after 10-20 times.
d) please explain you last question
You mean this: Can you make it freeze is you switch the input to the relay with a switch instead of a GPIO output?

You can use a switch to connect power to a load (relay board input in this case) intead of using transistors in the Pi gpio output. Don't connect switch and gpio output at the same time!
Test by operating the relay with the button. Does the Pi still freeze? If not the problem might be related to how you have connected the gpio output. If the freeze still happens it might be something to do with power to the relays or motors or interference from high voltagesas the coils turn on and off.

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Relay' connected to Rpi Zero W - causes it to freeze

Wed Jul 11, 2018 10:06 pm

guyd wrote:
Wed Jul 11, 2018 8:04 am
2. relay is connected directly to RPI ( 5V to VCC, GND to GND, GPIO20, to relay signal )
What? Is this just a relay, or does it have some electronics as well? How do you know the electronics is suitable for the RPi (relay modules designed for Arduino are not)?

I've only been on this forum for a few weeks, and every day somebody somewhere is making assumptions about connecting things without any real understanding of what they are doing and what it is very much best not to do. ELECTRONICS IS NOT SUCK-IT-AND-SEE LIKE SOFTWARE CAN BE - GET IT WRONG AND YOU DAMAGE YOUR RPi (OR WORSE).

Please, everybody: either buy and use ready made HATs designed specifically for RPi, or learn some basic electronics before fiddling.

Beginners Guide to Wiring Things to the GPIO
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Thu Jul 12, 2018 11:49 am

As suggested - I tried to power the relay ( instead of pi's 5V ), with external power supply:
Relay was powered correctly ( green led was ON )- but switching was not done ( voltage difference of 3.8 between trigger GPIO connected on relay to GND on relay ).

PiGraham
Posts: 3279
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Relay' connected to Rpi Zero W - causes it to freeze

Thu Jul 12, 2018 12:52 pm

guyd wrote:
Thu Jul 12, 2018 11:49 am
As suggested - I tried to power the relay ( instead of pi's 5V ), with external power supply:
Relay was powered correctly ( green led was ON )- but switching was not done ( voltage difference of 3.8 between trigger GPIO connected on relay to GND on relay ).
You should never get >3.3 Volts on a gpio. Allowing some inaccuracy in your meter 3.8 volts is not a good sign.

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Relay' connected to Rpi Zero W - causes it to freeze

Thu Jul 12, 2018 5:09 pm

guyd wrote:
Thu Jul 12, 2018 11:49 am
As suggested - I tried to power the relay ( instead of pi's 5V ), with external power supply:
Relay was powered correctly ( green led was ON )- but switching was not done ( voltage difference of 3.8 between trigger GPIO connected on relay to GND on relay ).
That very much suggests the relay module you are using is not RPi compatible.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

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

Re: Relay' connected to Rpi Zero W - causes it to freeze

Fri Jul 13, 2018 4:07 pm

Reading through this thread no one has asked the simple question of guyd .

guyd please post a link to the relay board you are using either from the seller or the maker, that way we can at least tell you if it will work correctly with the pi gpio or whether you need an interface between the gpio and the relay board.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sat Jul 14, 2018 12:19 pm

pcmanbob wrote: Reading through this thread no one has asked the simple question of guyd .

guyd please post a link to the relay board you are using either from the seller or the maker, that way we can at least tell you if it will work correctly with the pi gpio or whether you need an interface between the gpio and the relay board.
Well - you are right.
here is one of the items that acts as described :
https://www.aliexpress.com/item/One-1-C ... 80606.html

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

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sat Jul 14, 2018 2:56 pm

guyd wrote:
Sat Jul 14, 2018 12:19 pm
pcmanbob wrote: Reading through this thread no one has asked the simple question of guyd .

guyd please post a link to the relay board you are using either from the seller or the maker, that way we can at least tell you if it will work correctly with the pi gpio or whether you need an interface between the gpio and the relay board.
Well - you are right.
here is one of the items that acts as described :
https://www.aliexpress.com/item/One-1-C ... 80606.html
Well it clearly states for the Arduino and operating voltage of 5v .

so that means the opto isolator and all the rest of the electronics and the relay are working at 5v , which you are connecting to the pi gpio which is not 5v tolerant. also powering this directly from the pi is not recommended.

if it were me I would power the relay board from a separate 5v supply, and put another opto isolator between the pi gpio and the replay board.

Image
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
tlfong01
Posts: 152
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 12:23 am

guyd wrote:
Sat Jul 14, 2018 12:19 pm
here is one of the items that acts as described :
https://www.aliexpress.com/item/One-1-C ... 80606.html

I happened to experiment with a relay module similar to yours some weeks ago. My quick and dirty conclusion based on my results is the following.

  • 1. Select Low level trigger - NOT OK for Rpi.
  • 2. Select High level trigger - OK for Rpi.
You might like to read my old post below.

RE: RELAY MODULE KY-019 5V Post by tlfong01 2018-Jun-19 Tue 5:24 pm
viewtopic.php?f=63&t=77158&start=75#p1330108
I am an electronics hobbyist. I started playing with relays some weeks ago. Me finding things so confusing. Google is my friend and makes me great again!

User avatar
tlfong01
Posts: 152
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 12:30 am

tlfong01 wrote:
Sun Jul 15, 2018 12:23 am
guyd wrote:
Sat Jul 14, 2018 12:19 pm
here is one of the items that acts as described :
https://www.aliexpress.com/item/One-1-C ... 80606.html
  • 1. Select Low level trigger - NOT OK for Rpi.
  • 2. Select High level trigger - OK for Rpi.
Your might like to read my explanation below.

RE: RELAY MODULE KY-019 5V Post by tlfong01 » 2018-Jun-13 Wed 3:44 pm
viewtopic.php?f=63&t=77158&start=50#p1327656
I am an electronics hobbyist. I started playing with relays some weeks ago. Me finding things so confusing. Google is my friend and makes me great again!

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 1:26 am

Would everybody PLEASE stop buying Arduino boards thinking they will work with the RPi?!!!

Yes, they can probably be made to work, but may require modification or even additional adapter circuitry, and connecting just any Arduino board to an RPi without knowing what you are doing risks damage to the RPi.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

User avatar
DougieLawson
Posts: 33060
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 6:20 am

tlfong01 wrote:
Sun Jul 15, 2018 12:23 am
  1. Select Low level trigger - NOT OK for Rpi.
  2. Select High level trigger - OK for Rpi.
You might like to read my old post below.

RE: RELAY MODULE KY-019 5V Post by tlfong01 2018-Jun-19 Tue 5:24 pm
viewtopic.php?f=63&t=77158&start=75#p1330108
What are you talking about there's no problem with a LOW trigger. You just have to reverse the logic in your code and make it so the GPIO is normally high and goes low to switch the relay.

There's also no problem with Arduino 5V relays, just stick a 5V MCP23017 between it an your RPi. The I2C interface is safe to drive an MCP23017 running at 5V.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

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

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 8:49 am

tlfong01 wrote:
Sun Jul 15, 2018 12:23 am
guyd wrote:
Sat Jul 14, 2018 12:19 pm
here is one of the items that acts as described :
https://www.aliexpress.com/item/One-1-C ... 80606.html

I happened to experiment with a relay module similar to yours some weeks ago. My quick and dirty conclusion based on my results is the following.

  • 1. Select Low level trigger - NOT OK for Rpi.
  • 2. Select High level trigger - OK for Rpi.
You might like to read my old post below.

RE: RELAY MODULE KY-019 5V Post by tlfong01 2018-Jun-19 Tue 5:24 pm
viewtopic.php?f=63&t=77158&start=75#p1330108
The first thing is that many of these relay boards don't have an option to select high or low trigger and low trigger is not really a problem as Dougie said it only requires a change in the logic in your software.

the real problem is the fact that these boards use 5v for the control circuity, having 5v grounded via a gpio pin is not a good idea as the gpio pins are no 5v tolerant.

In most cases you can just use a transistor or a ULN2803A to interface between the pi gpio and relay board and everything will work just fine,

in this case I suggested the opto isolator and separate power supply so as to electrically isolate the pi and the relay board because guyd was have so many problems and his pi was locking up.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
tlfong01
Posts: 152
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 10:19 am

pcmanbob wrote:
Sun Jul 15, 2018 8:49 am
tlfong01 wrote:
Sun Jul 15, 2018 12:23 am
  • 1. Select Low level trigger - NOT OK for Rpi.
  • 2. Select High level trigger - OK for Rpi.
The first thing is that many of these relay boards don't have an option to select high or low trigger
and low trigger is not really a problem as Dougie said it only requires a change in the logic in your software.
the real problem is the fact that these boards use 5v for the control circuity, having 5v grounded via a gpio pin is not a good idea as the gpio pins are no 5v tolerant.
In most cases you can just use a transistor or a ULN2803A to interface between the pi gpio and relay board and everything will work just fine,
in this case I suggested the opto isolator and separate power supply so as to electrically isolate the pi and the relay board because guyd was have so many problems and his pi was locking up.


  • 1. The first thing is that many of these relay boards don't have an option to [jumper] select high or low trigger

Ah, I think this board with the uncommon option of using a jumper to select High Level/Low Level trigger causes some confusion. The problem is a bit complicated. Let me clarify point by point and see if you agree what I am going to say.

There are two methods for Rpi to control the relay: (a) direct drive using 3.3V GPIO signal, (b) Indirect drive with a buffer/logical level converter. Let us discuss the first method.

For the first method of direct drive without buffer/logical level conversion, I need first describe the Arduino case and explain why there is no problem at all either the jumper is selecting High Level Trigger or Low Level Trigger.

Next I will describe the Rpi case and explain why if jumper selects High Level Trigger, Rpi has no problem. But if jumpers selects Low Level Trigger, then Rpi won't work, the relay is always ON.

My English is very slow telling the long story. Perhaps you might like to make some comments, before I take a break and continue,

update 2018jul15hkt2018
Actually it takes less than 5 minutes to check if my thinking is correct, as summarized below.

  • 1. Write a program to toggle the relay.
  • 2. Jumper select High Level Trigger and run the toggle relay program. The relay should toggle happily.
  • 3. Jumper select Low Level Trigger and run the same program. Relay doesn't toggle.
  • 4. QED.
I am an electronics hobbyist. I started playing with relays some weeks ago. Me finding things so confusing. Google is my friend and makes me great again!

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 2:32 pm

Dear helpers,

I appreciate your help - but I think i'm not succeeding in explaining my self ( sorry for me English ).

1. I use common relays that operate at 5VDC, and triggered by gpio 3.3V. I do not think that labeling it as "Arduino" or "Raspberry Pi" does not make any technical difference.

2. After big amount of tests up till writing this post/ question - I can be certain that main issue - freeze of RPI, cause by EMI caused by activating AC motor or pwr drainage from RPI to activate such motor. Surely it is not code, or OS issue. it happen ONLY RIGHT AFTER MAKING A SWITCH.

3. 2 additional test were done ( some of them were written in this post ) :
3.1 supplying 5VDC + GND to RELAY using external power supply, while using RPI's GPIO to trigger relay - was not successful since external power supply does not share common GND with RPI causing a 3.8V between GPIO (measured on relay ) and GND (on relay ).
3.2 trying to make EMI shield on cables, and on relay using an aluminum foil -failed ( but less - it is not something I can count... )


To sum up :
I hope I made myself clearer this time.
I'll try to L/H jumper as suggested - it would be odd if that makes any diff resulting RPI to stop working due to power/ EMI or other


Appreciate you kind help,
Guy

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 2:39 pm

DougieLawson wrote:
Sun Jul 15, 2018 6:20 am
tlfong01 wrote:
Sun Jul 15, 2018 12:23 am
  1. Select Low level trigger - NOT OK for Rpi.
  2. Select High level trigger - OK for Rpi.
You might like to read my old post below.

RE: RELAY MODULE KY-019 5V Post by tlfong01 2018-Jun-19 Tue 5:24 pm
viewtopic.php?f=63&t=77158&start=75#p1330108
What are you talking about there's no problem with a LOW trigger. You just have to reverse the logic in your code and make it so the GPIO is normally high and goes low to switch the relay.

There's also no problem with Arduino 5V relays, just stick a 5V MCP23017 between it an your RPi. The I2C interface is safe to drive an MCP23017 running at 5V.
can you please explain what is the purpose of MCP23017 - in activating a relay ?

User avatar
tlfong01
Posts: 152
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 2:55 pm

guyd wrote:
Sun Jul 15, 2018 2:32 pm
I'll try to L/H jumper as suggested - it would be odd if that makes any diff resulting RPI to stop working due to power/ EMI or other
Well, the L/H jumper makes a difference not because of power/EMI, but because the circuit design. For L, the relay circuit assumes Rpi GPIO as a sink driver. For H, Rpi GPIO a source driver. The L and H circuits have different requirements. Arduino meets both requirements, but Rpi meets only the H requirement. Don't worry for now. Try my suggestion and see how it is going.

For the EMI problem, I have the following suggestion.

RE: RELAY MODULE KY-019 5V Post by tlfong01 » 2018-Jul-13 Fri 7:53 pm
viewtopic.php?f=63&t=77158&sid=2d46e36b ... 0#p1340412

BTW, I don't have any problem understanding your question. Actually I appreciated you thorough and well thought troubleshooting procedure, like swapping this and that to locate the cause.

Good luck.
I am an electronics hobbyist. I started playing with relays some weeks ago. Me finding things so confusing. Google is my friend and makes me great again!

User avatar
DougieLawson
Posts: 33060
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 3:08 pm

guyd wrote:
Sun Jul 15, 2018 2:39 pm

can you please explain what is the purpose of MCP23017 - in activating a relay ?
It gives you a 5V tolerant GPIO (in fact a single MCP23017 gives you 16 GPIOs).

They're I2C and easy to program. The MCP23017 GPIOs can be input or output, you can even trigger a RPi GPIO when any one of eight (or sixteen) MCP23017 changes state.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

PiGraham
Posts: 3279
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 3:25 pm

guyd wrote:
Sun Jul 15, 2018 2:32 pm

1. I use common relays that operate at 5VDC, and triggered by gpio 3.3V. I do not think that labeling it as "Arduino" or "Raspberry Pi" does not make any technical difference.
The technical difference has been explained several times but I'll to make it plain.

Arduino gpio operates at 5V (Note there are some "Arduino compatible" boards that operate at 3.3V so watch out for that. Always check the specs.)
Raspi gpio operates at 3.3V (5V is too much and can damage the Pi. Pi output may not operate the peripheral correctly.

Peripherals designed for Arduino usually use 5V logic levels. They may expect a high level above what the Pi can output. They may have voltages on their pins >3,3V that will cause undesirable current to flow into the Pi and might affect operation.

guyd
Posts: 13
Joined: Wed Jun 27, 2018 7:28 am

Re: Relay' connected to Rpi Zero W - causes it to freeze

Sun Jul 15, 2018 4:05 pm

PiGraham wrote:
Sun Jul 15, 2018 3:25 pm
guyd wrote:
Sun Jul 15, 2018 2:32 pm

1. I use common relays that operate at 5VDC, and triggered by gpio 3.3V. I do not think that labeling it as "Arduino" or "Raspberry Pi" does not make any technical difference.
The technical difference has been explained several times but I'll to make it plain.

Arduino gpio operates at 5V (Note there are some "Arduino compatible" boards that operate at 3.3V so watch out for that. Always check the specs.)
Raspi gpio operates at 3.3V (5V is too much and can damage the Pi. Pi output may not operate the peripheral correctly.

Peripherals designed for Arduino usually use 5V logic levels. They may expect a high level above what the Pi can output. They may have voltages on their pins >3,3V that will cause undesirable current to flow into the Pi and might affect operation.

Oh... Now I understand. TNK U !!

Return to “Add-ons”

Who is online

Users browsing this forum: No registered users and 6 guests