Non-latching relay fails to deactivate

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
aleb
Posts: 1
Joined: Sat Mar 31, 2018 9:28 pm
Location: Zurich

Non-latching relay fails to deactivate

Post by aleb » Sun Apr 01, 2018 4:50 am

I connected the pyboard v1.1 and this 5V relay like this:
https://www.aliexpress.com/item/Free-Sh ... 0.0.reQrIv
- V+ to VIN
- GND to GND
- IN to X1

I'm using this to test the relay control:
[code]
relay_pin = machine.Pin('X1', machine.Pin.OUT)
while True:
relay_pin.high()
pyb.delay(1000)
relay_pin.low()
pyb.delay(1000)
[/code]

There is something strange going on with the relay, though:
- When the pyboard is connected to the USB of my PC: it activates when high, but does not deactivate when low, remaining activated until I disconnect IN from X1.
- When the pyboard is connected to a simple USB power source: it works fine.

The pin output seems ok, 0 V when low and 3.28 V when high.
The voltage on VIN-GND is 4.10 V when connected to the PC and 4V when connected to the USB power source.

Any idea what's going on?

chuckbook
Posts: 135
Joined: Fri Oct 30, 2015 11:55 pm

Re: Non-latching relay fails to deactivate

Post by chuckbook » Tue Apr 03, 2018 10:23 am

Let's assume the relay works fine if Vin is at +5VDC and IN is either connected to Vin or GND.
Repeat the test with Vin at 4V.
If this also works fine I would recommend to use the output in open-drain mode with an external pull-up resistor connected to Vin.

Note:
If it is just a plain relay without extra circuit (protection diode, coil transistor etc.) at least a protection diode and an extra transistor to handle at least 100mA current to drive the coil is required. Otherwise you will most likely destroy the output port.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Non-latching relay fails to deactivate

Post by pythoncoder » Wed Apr 04, 2018 7:43 am

It's hard to tell from the Chinese data but from the photos the relay module does appear to have a driver transistor and protection diode.

Is there a voltage drop somewhere in the circuit? When the relay is supposed to be off, measure between In and Gnd directly on the pins of the relay board. Any voltage above 0.3V or so might just be enough to keep the relay on.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Non-latching relay fails to deactivate

Post by Roberthh » Wed Apr 04, 2018 11:00 am

Looking at the board picture, it seems as if the relay coil is connected to GND on on side, and the transistor's collector is connected to Vcc. So I guess it needs a low level to activate and a high level to deactivate. if Vcc of the module is 4v, and Vin is ~3.3 V, then it's no surprise that is stays activated. You could add a small diode in series with the input shift the switch level, Anode to the module, Kathode to the micro.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Non-latching relay fails to deactivate

Post by pythoncoder » Thu Apr 05, 2018 8:43 am

Boggle :!: Well spotted. But what an absurd piece of design.
Peter Hinch
Index to my micropython libraries.

Post Reply