Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Relay turns on when input is LOW?!

Relay turns on when input is LOW?!

Scheduled Pinned Locked Moved Hardware
5 Posts 4 Posters 2.8k Views 3 Watching
  • 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.
  • dakkyD Offline
    dakkyD Offline
    dakky
    wrote on last edited by dakky
    #1

    The title says it all: I have connected a relay to my network and it switches power on (led on the relay lights up), when the input pin goes low and vice versa.

    Thats a little bit confusing, when switching off something in the controller UI and the device is switching on ;) and i don't think, that zwitching the state in the arduino code is the way to go :D

    any idea whats wrong here? Wiring is straight forward (vcc & gnd with corresponding pins on relay + D2 to I1 on the relay).

    The code is the the one from the examples (as far as I remember :D ).

    I inserted some debug statements to prevent stupid errors on my side ;)

        Serial.print("arduino pin: ");
        Serial.println(message.sensor + FIRST_DIGITAL_RELAY_OUTPUT);
        Serial.print("message.bool: ");
        Serial.println(message.getBool());
        digitalWrite(message.sensor + FIRST_DIGITAL_RELAY_OUTPUT, message.getBool() ? RELAY_ON : RELAY_OFF);
    

    =>

    arduino pin: 2
    message.bool: 1
    

    results in switched off relay.

    Thanks for helping

    EDIT: maybe "hardware" is the wrong section and "Troubleshooting" a better location ;) If thats the case: please move the thread if possible

    Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
    Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

    Software: MySensors 2.0development

    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      I don't remember why this happens, but the simple solution is to switch the #defines for RELAY_ON and RELAY_OFF in the beginning of the sketch. The reason those are defined is to make it easy to switch them.

      1 Reply Last reply
      1
      • dbemowskD Offline
        dbemowskD Offline
        dbemowsk
        wrote on last edited by
        #3

        Not sure what kind of relay setup you are using, but are you using a pull-up or pull-down resistor on your data line? If you are using pull-up resistors, the data line is always high and needs to be pulled low to be active. Check that you are not using the internal pull-up resistors on your data line. For this you should use a pull-down resistor if your relay setup does not already have one.

        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

        1 Reply Last reply
        0
        • Boots33B Offline
          Boots33B Offline
          Boots33
          Hero Member
          wrote on last edited by Boots33
          #4

          If you are using a relay module similar to this one

          0_1465897251623_4-81.jpg

          They often use a PNP transistor to drive the relay. That means you will need to switch the arduino output low to turn on the relay, as you have discovered.

          As @mfalkvidd has said the simple fix may be to reverse the #defines

          Here is what the relay circuit would look like. They would also likely have a resistor from the transistor base to vcc to ensure the transistor turns off

          0_1465897544475_pnp driver.jpg

          1 Reply Last reply
          1
          • dakkyD Offline
            dakkyD Offline
            dakky
            wrote on last edited by
            #5

            Ah that explains it for me. Thanks for the dettailed answer. I will @mfalkvidd's and switch the defines. thank you all ;)

            Greetings

            Controller: Raspberry Pi 2 :: Openhab2 :: with @TimO MySensors Binding
            Gateway: Arduino MEGA 2560 R3 :: W5100 :: Ethernet GW

            Software: MySensors 2.0development

            1 Reply Last reply
            1
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            14

            Online

            11.7k

            Users

            11.2k

            Topics

            113.0k

            Posts


            Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular