Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    5V Relay on pycom

    Scheduled Pinned Locked Moved MicroPython
    pycomrelaylopy
    22 Posts 4 Posters 4.8k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      Kebson
      last edited by

      Hi all,
      I have a pycom with the LoPy integrated.
      I would like to push up a relay, but I don't know if what I'm doing is well.
      I have a water pump motor joined to the relay. When I connect the pycom to my machine, I heard the relay sound noise, but nothing else.
      I did it like this.

      p_relay = Pin('P11', mode=Pin.OUT, pull=Pin.PULL_UP)
      while True:
      p_relay.PULL_DOWN
      print("OFF for 2 seconds")
      time.sleep(2)
      p_relay.PULL_UP
      print("ON for 2 seconds")
      time.sleep(2)
      

      Is it a good sample for starting ? Do you have any other idea?

      Note that I have a AC/DC adapter, how can I joined it to my relay?

      T robert-hhR 2 Replies Last reply Reply Quote 0
      • T Offline
        timh @Kebson
        last edited by

        @kebson You will need to check the specs of the relay to see what voltage and current is required to actually hold the relay closed.

        ESP32 details can be found here
        https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf

        1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @Kebson
          last edited by

          @kebson What kind of relay is that? In any case, you need a switching transistor (like a simple N-Channel Mosfet [e.g. 2N7000]) and a flyback diode [e.g. 1N4148]) to switch the 5V the relay needs. There are some modules which have that integrated, but the circuitry is so bad designed that it still needs a 5V level to fully switch.

          1 Reply Last reply Reply Quote 0
          • E Offline
            Eric73
            last edited by Eric73

            @Kebson
            I'm not sure about pycom lexical, but in electronics, pull-up and pull-down is used for input pin only (not push-pull output as you configure your pin). If you want to drive your relay with a low value on your pin use "p_relay.value(0)" and "p_relay.value(1)".
            Please note that if you have directly connected your solenoid to the output of your device it's insane and will not work (even you can destroy your pycom device if you haven't a free wheel diode) (output pin of pycom device cannot source more than few milli amp, and can sink about 10mA max). You must use a transistor NPN or fet to drive more current as robert-hh said.

            1 Reply Last reply Reply Quote 0
            • K Offline
              Kebson
              last edited by

              Thanks for the response,
              My relay is like this.

              Yeah I heard I must have a transistor, but when I connect it, nothing happens, and if I deconnect if, I heard the relay noise.
              @robert-hh @timh @Eric73

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @Kebson
                last edited by

                @kebson The picture in the link shows a transistor and and a flyback diode on the board. And the text tells about 3.3 and 5V compatibility.
                The in the code above, to swich the output, you have to issue:
                p_relay.value(1)
                and
                p_relay-value(0)
                to switch the output to high and low. You may also write:
                p_relay(1) and p_relay(0).

                K 2 Replies Last reply Reply Quote 0
                • K Offline
                  Kebson @robert-hh
                  last edited by

                  @robert-hh Ok I will try it in a few minutes to see.

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    Kebson @robert-hh
                    last edited by

                    @robert-hh I try what you said but, nothing special

                    p_relay = Pin('P11', mode=Pin.OUT)
                    p_relay.value(1)
                    p_relay.value(0)
                    while True:
                       if result_dht.is_valid():
                            p_relay(1)
                       else:
                            p_relay(0)
                    

                    Is there something wrong in the code?

                    robert-hhR 1 Reply Last reply Reply Quote 0
                    • robert-hhR Offline
                      robert-hh @Kebson
                      last edited by

                      @kebson I do not understand why you have that:

                      p_relay.value(1)
                      p_relay.value(0)
                      

                      at the beginning, because that gives just a 3µs pulse at the output. Besides that I assume, that you want to switch the relay on, when result_dht.is_valid() returns True.
                      If you have a voltmeter, you should see output P11 change it's level. If it does, the program logic is OK, but the relay board does not switch with 3.3 V.

                      K 1 Reply Last reply Reply Quote 0
                      • K Offline
                        Kebson @robert-hh
                        last edited by

                        @robert-hh YEah I commentend the second line, but yes, I would like to put the relay on when result_dht returns True. and turn it off otherwise.
                        Yesterday, I joined the relay with a transistor, a resistance, but nothing happened. That's why, i disconnect the transistor, and now, it's directly connected on the 3V3 pycom.

                        robert-hhR 1 Reply Last reply Reply Quote 0
                        • robert-hhR Offline
                          robert-hh @Kebson
                          last edited by

                          @kebson Can you post an as-good-as-possible picture of the upper and lower side of the relay board. The upper side should show the transistor and the LED. Then I can derive the schematics.

                          K 1 Reply Last reply Reply Quote 0
                          • K Offline
                            Kebson @robert-hh
                            last edited by

                            @robert-hh
                            2_1529414258021_3.jpeg 1_1529414258020_2.jpeg 0_1529414258018_1.jpeg

                            robert-hhR 1 Reply Last reply Reply Quote 0
                            • robert-hhR Offline
                              robert-hh @Kebson
                              last edited by

                              @kebson Thanks. Did you ever see the LED turning on. And if yes, what's the color?

                              K 1 Reply Last reply Reply Quote 0
                              • K Offline
                                Kebson @robert-hh
                                last edited by Kebson

                                @robert-hh Yeah, when I connect the pycom on the machine, the LED turns on in RED color and I heard a little sound. But he does it once in two.

                                robert-hhR 1 Reply Last reply Reply Quote 0
                                • robert-hhR Offline
                                  robert-hh @Kebson
                                  last edited by

                                  @kebson Is the relay Vcc connected to 5V or 3.3V? And again, what is the color of the LED? Red or green or yellow or blue? It is important, because from the color I can tell the voltage dop of the LED.

                                  K 1 Reply Last reply Reply Quote 0
                                  • K Offline
                                    Kebson @robert-hh
                                    last edited by

                                    @robert-hh I edited my last answer and put RED color. The relay VCC is connected to my first pin (Vin (3.5-5.5V)).

                                    robert-hhR 1 Reply Last reply Reply Quote 0
                                    • robert-hhR Offline
                                      robert-hh @Kebson
                                      last edited by

                                      @kebson Red is ok. That has a drop voltage of about 1.4 V, and should work with 3.3 V input voltage. The Vcc input at the board should be 5V, if the device is connected to USB. You could try to bypass the LED and connect the P11 output to the point indicated by the arrow in the picture below.
                                      0_1529416790230_relais.jpg

                                      K 1 Reply Last reply Reply Quote 0
                                      • K Offline
                                        Kebson @robert-hh
                                        last edited by

                                        @robert-hh It's what i did, but like i said, I just heard a sound, and see the LED turns on, but nothing else.

                                        My relay if it will work, I would like to connect it to a water pump. So, if I can't have the steps on turns on and off the relay, I couldn't continue.

                                        robert-hhR 1 Reply Last reply Reply Quote 0
                                        • robert-hhR Offline
                                          robert-hh @Kebson
                                          last edited by

                                          @kebson What do you expect from a relay? It is just a solenoid operated switch. When it turns on, you hear a sharp click, it if turns off, you'll hear a soft click. In order to tell if it is working, you have to switch something with it.

                                          K 1 Reply Last reply Reply Quote 0
                                          • K Offline
                                            Kebson @robert-hh
                                            last edited by

                                            @robert-hh yes, and it's my water pomp I will switch with. But for now, I just would like to see its turns on and off. Because it doesn't. I'm using a transistor P2N2222 to try with it now.

                                            K 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom