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. Troubleshooting
  3. RELAY_ON 0 or 1?

RELAY_ON 0 or 1?

Scheduled Pinned Locked Moved Troubleshooting
4 Posts 3 Posters 2.0k Views 1 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.
  • M Offline
    M Offline
    mikeones
    wrote on last edited by mikeones
    #1

    I am running the relay sketch and I am having an issue with checking if the relay is HIGH or LOW. I don't have a whole lot of experience with these arduinos but shouldn't RELAY_ON == 1 (LOW) and off == 0 (HIGH)

    #define RELAY_ON 0
    #define RELAY_OFF 1
    

    When using the example relay state, RELAY_OFF sets the relay to off but when I check the PIN state via digitalRead(RELAY_1) I get the opposite of what I expect.

    digitalRead(RELAY_1) returns HIGH when the relay is OFF and LOW when the relay is ON. I have tried changing the state definitions to the reverse of what is in the example but this results in the relay turning ON when it should be OFF. Anyone know what might be causing this?

    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    1 Reply Last reply
    0
    • jendrushJ Offline
      jendrushJ Offline
      jendrush
      wrote on last edited by
      #2

      If i think correct some relays are activated by high state, but some by low state. If i'm wrong, please correct me.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mikeones
        wrote on last edited by
        #3

        After more searching, I see the relay I am using is ACTIVE LOW. Which means it acts in reverse of an ACTIVE HIGH relay. I guess I need to reverse the value from digitalread before updating the GW.

         digitalRead(RELAY_1+i)==1?0:1
        
        Z 1 Reply Last reply
        0
        • M mikeones

          After more searching, I see the relay I am using is ACTIVE LOW. Which means it acts in reverse of an ACTIVE HIGH relay. I guess I need to reverse the value from digitalread before updating the GW.

           digitalRead(RELAY_1+i)==1?0:1
          
          Z Offline
          Z Offline
          Zeph
          Hero Member
          wrote on last edited by
          #4

          @mikeones

          Yes you got it, some devices are active low.

          (Just to confuse things, some relays have double throw outputs, meaning that one pair of conductors is shorted when the relay is powered - "Normally Open/NO" - and one when it's not powered - "Normally Closed/NC" (with one of those contact being common to both).

          So sometimes you might power a device with the NC connection of the relay output, meaning the device loses power when the relay is powered. One reason do so this would be if you want the device to be powered even if the microcontroller was disabled.

          Anyway, take that into account too, and return 1 if after all the possible inversions, the hardware device is powered on.

          For code, you could just return !digitalRead(...), where the NOT operator ! will convert 0 into 1, and 1 into 0 more simply than the ?: syntax (actually it will change any non-zero value to zero, not just 1).

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


          27

          Online

          11.7k

          Users

          11.2k

          Topics

          113.1k

          Posts


          Copyright 2025 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