[SOLVED]cannot connect relay module

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
atux_null
Posts: 20
Joined: Tue Jul 10, 2018 2:16 pm

[SOLVED]cannot connect relay module

Post by atux_null » Wed Aug 08, 2018 2:27 pm

hi. i a taking my baby steps with micropython and esp8266 nodemcu. i am trying to connect a relay and play with it.Image and i have a 9V battery and a led connected. the circuit is:
-a cable from the + side of the battery goes to the middle of the relay (C)
-a cable from the NO of the relay goes to one leg of the led.
-a cable from the - side of the battery goes to the other leg of the led.
Once everything is connected i see the led to be switched on.
the pin used in ESP8266 nodemcu to connect to is the D1.

then i issue on the repl:

Code: Select all

from machine import Pin
relay = Pin(5, Pin.OUT)
relay.value(0) # to switch it off
relay.value(1) # to switch it on
the problem is that the led statys always on and the onboard led(red) of the relay is always on. Also i do not hear a click as it is supposed to be when changing state.
thanks in advance.
Last edited by atux_null on Mon Aug 13, 2018 12:25 pm, edited 1 time in total.

yeyeto2788
Posts: 28
Joined: Wed Mar 30, 2016 4:09 pm

Re: cannot connect relay module

Post by yeyeto2788 » Wed Aug 08, 2018 2:43 pm

Try adding a delay between on and off to see if it's doing what is supposed to do.

What could be happening is that the pin changes its state (from on to off and vice-versa) so quick that you might not be seeing the led to go off or hearing the relay being activated/deactivated.

try something like this:

Code: Select all

from machine import Pin
import time
relay = Pin(5, Pin.OUT)
relay.value(0) # to switch it off
time.sleep(2)
relay.value(1) # to switch it on
Note the `time.sleep(2)` which will hang for 2 secs.
P.D: Hope it helps!

atux_null
Posts: 20
Joined: Tue Jul 10, 2018 2:16 pm

Re: cannot connect relay module

Post by atux_null » Wed Aug 08, 2018 2:55 pm

no changes at all. :?

yeyeto2788
Posts: 28
Joined: Wed Mar 30, 2016 4:09 pm

Re: cannot connect relay module

Post by yeyeto2788 » Wed Aug 08, 2018 7:46 pm

Are you sure the relay is 3.3 volts compatible? Is it active low or active high? If it is active low try connecting it to GND directly.

Also take into account that you should have all GND (relay and esp8266 GND) connected together.

I don't really see anything wrong on the code side, so it might be hardware related.

atux_null
Posts: 20
Joined: Tue Jul 10, 2018 2:16 pm

Re: cannot connect relay module

Post by atux_null » Thu Aug 09, 2018 4:34 pm

solved. instead of vin i had to connect to 3.3v pin.

Thanks a lot.

yeyeto2788
Posts: 28
Joined: Wed Mar 30, 2016 4:09 pm

Re: cannot connect relay module

Post by yeyeto2788 » Mon Aug 13, 2018 10:39 am

No problem! Glad you got it working. :D

You might consider changing the name of the Post adding a [SOLVED] at the beginning.

Regards.

Sniper
Posts: 21
Joined: Mon Jan 06, 2020 2:32 pm

Re: cannot connect relay module

Post by Sniper » Tue Feb 11, 2020 9:53 pm

yeyeto2788 wrote:
Wed Aug 08, 2018 2:43 pm
Try adding a delay between on and off to see if it's doing what is supposed to do.

What could be happening is that the pin changes its state (from on to off and vice-versa) so quick that you might not be seeing the led to go off or hearing the relay being activated/deactivated.

try something like this:

Code: Select all

from machine import Pin
import time
relay = Pin(5, Pin.OUT)
relay.value(0) # to switch it off
time.sleep(2)
relay.value(1) # to switch it on
Note the `time.sleep(2)` which will hang for 2 secs.
P.D: Hope it helps!
I get this output in micropython

Code: Select all

>>> from machine import Pin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Pin

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

Re: [SOLVED]cannot connect relay module

Post by Roberthh » Wed Feb 12, 2020 9:13 pm

Which module are you using? Really ESP8266? And are you sure that you are talking to that device?

Post Reply