I'm working on a home IOT using Rpi to run script that controls opening/ closing window's shade ( switching its electric motor up or down ).
1) Code is very simple and working fine - switching gpio "on" and "off"( using python, gpiozero, pigpio ).
2) Code can switch up or down using schedule (code ) or a physical switch ( input ).
3) Hardware in use: Rpi zero, a standard 2 relays with opto-coupler 5vDC, 220VAC motor to open close shade, and 3 state switch ( UP/OFF/DOWN ), originally belongs to window's shade.
As said - code works fine on the same hardware on table, for a very long time - doing the same tasks: scheduled on/off , switch using a physical switch.
Problem starts when installed to operate a real UP/DOWN of motorized shade, cause after some operations to Rpi to FREEZE. This freeze happens only when triggering UP/DOWN, it can happen after 1-30 switches. when pi freezes only unplugging it and plug back on restarts it.
This are the set of experiments done to find out what is the reason for freezing:
1)RPi was replaced with a new one - same result.
2) GPIO pins were replaced - same result.
3) RPI powered using battery (window uses wall outlet ) - same result
4) USB cable + DC converter - replaced several times - same result.
5) To be sure physical input does not causes this - I wrote a test code to create fast switches ( about 0.1 sec between UP/DOWN ) - caused same result ( meaning that physical switch does not causes it )
6) Twin relays was replaced 2 single relays - SAME result
7) Running test code to do same switching -without any relays connected - OK !
8) Disconnecting relay's output, 220VAC( and running code ) - OK !!
9) Returning Relay AC output - back to freeze.
to sum up:
a) RPI freezes due to switching 220 relay. it happens more frequent when switching is fast. Switching the relay while its output was not connected- it never fails, nor switch a 220AC bulb. My guess - It has something to do with switching an AC motor.
b) It is not related to input power, DC converter, USB cable, physical switch, cables or so.
Any ideas why it is happening ?