0

I have a small hobby motor (5v) mounted with a hobby fan that is connected to Normally Open on the Relay (pic) enter image description here and 5V Wall Power supply (via a barrel/terminal block adapter.)

On the input side, the relay connections are:

  • VCC to Pi Pico 3.3V/pin 36
  • GND to GND
  • input pin to GPIO 15

Relay 1

Relay 2

Everything works well with this code:

import time
time.sleep(2)

import machine from machine import Pin #pi pico #led = Pin(25, Pin.OUT) #pi pico w led = machine.Pin("LED", machine.Pin.OUT) print('sleep before turn off led') time.sleep(2) led.off()

print('sleep before turn on led') time.sleep(2) led.on()

from machine import Pin relay = Pin(15, Pin.OUT)

relay_sleep=5

count=0 while True: print('sleep before turn on relay') time.sleep(relay_sleep) relay.value(0)

print('sleep before turn off  led')
time.sleep(relay_sleep)
relay.value(1)
count+=1
print(count)

But if I make one change and put the relay connected to pin 40 (5 volts out) instead of pin 36 on the pico, the fan turns on but it never turns off. The relay does not appear to even try to change (multi-meter confirms no voltage change).

Is this expected?

EDIT:

  • Replacing the 5V relay with a 3V relay and all is well.
  • I also replaced the relay with a transistor a la https://github.com/jouellnyc/pico_thermostat, which is what I wanted in the first place (OLED/temp probe), but I tried it all out with the 5V relay first and got curious and followed this little rabbit hole ... :)
james6125
  • 103
  • 3
  • Sounds like an electrical question, not really Pi relevant. Perhaps if Vcc is 5V then 3V3 is not enough to switch the relay (some circuits require a logic high to be at least 70% of Vcc, 3.3V is 66% of 5V. – joan Sep 17 '23 at 21:46
  • 1
  • NOTE if you continue to use this with 5V you risk damaging your Pico – Milliways Sep 17 '23 at 22:10
  • @Milliways - thanks - you mean the damage is if I continue to connect the pico's pin 40 to the relay vs pin 36, yes? – james6125 Sep 17 '23 at 22:45
  • You will be putting 5V on a GPIO (via a transistor BE and resistor. GPIO are NOT 5V tolerant. I ended up with one of these lousy modules (which was falsely advertised as having an optoisolator) and ended up adding a transistor. – Milliways Sep 18 '23 at 00:16
  • OK thank you - I thought vcc was specific to the relay's power only and was not the same voltage that it sent to the pi pico on the GPIO (but thinking about that now makes sense). Thanks! – james6125 Sep 18 '23 at 00:46
  • Yes, that faq link answers my question... Thanks! – james6125 Sep 20 '23 at 23:02
  • I disagree @Milliways, how is a 5v magically appear through BE? The concern I should rise is that relays is causing rush currents and can therefore cause voltage drops, that cause the MCU to reset or crash. This can be prevented by using short wires, capacitor for stabilizing the power. – MatsK Oct 03 '23 at 10:44
  • @MatsK if you actually look at the circuitry of these dodgy modules the emitter of a PNP transistor is connected to 5V. The base goes to input (via a resistor). The BE junction becomes a simple forward biassed diode. If you have one try it (but don't connect to a Pi) – Milliways Oct 03 '23 at 11:05
  • @Milliways The Collector is connected to the relay and the Emitter is connected to GND and the base to a GPIO via a resistor! So I repeat my question. – MatsK Oct 03 '23 at 11:22
  • @james6125, Your code is OK. So to trouble shoot the relay module, connect it to 5v and GND and add 3,3 volt to the input and see if you can activate/deactivate the relay by adding/removing the 3,3 volt. – MatsK Oct 03 '23 at 11:24
  • @MatsK the only reference is a picture. I have an identical looking device which has a PNP transistor and these infect eBay. It would be a trivial task for the OP to work out what he has. The symptoms described point to a PNP controlled device. – Milliways Oct 03 '23 at 11:58
  • The same logic you apply to my comment can be applied to yours. So I fail to see your point. And If you want to discuss this further, lets move it to meta. – MatsK Oct 04 '23 at 08:53

0 Answers0