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. General Discussion
  3. Using only two digital pins for a button? (no GND, no VCC)

Using only two digital pins for a button? (no GND, no VCC)

Scheduled Pinned Locked Moved General Discussion
7 Posts 4 Posters 1.1k 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.
  • alowhumA Offline
    alowhumA Offline
    alowhum
    Plugin Developer
    wrote on last edited by
    #1

    If I only have two digital pins left, could they be used to support a button? Online searches have proven fruitless.

    For example:

    - D4 functions as output, set to permanently high.
    >>
    [ button ]
    >>
    - D5 functions as input, with pullup resistor enabled.
    

    Would this work? Or would this fry the Arduino/pin?

    Y 1 Reply Last reply
    0
    • alowhumA alowhum

      If I only have two digital pins left, could they be used to support a button? Online searches have proven fruitless.

      For example:

      - D4 functions as output, set to permanently high.
      >>
      [ button ]
      >>
      - D5 functions as input, with pullup resistor enabled.
      

      Would this work? Or would this fry the Arduino/pin?

      Y Offline
      Y Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @alowhum almost, if you set D4 permanently LOW.
      Then you button on D5 toggles between HIGH (when open, due to pullup) and LOW (when closed, shorted to D4).

      http://yveaux.blogspot.nl

      1 Reply Last reply
      0
      • alowhumA Offline
        alowhumA Offline
        alowhum
        Plugin Developer
        wrote on last edited by alowhum
        #3

        @Yveaux Thanks!

        // It works!

        For anyone finding this:

        In the Setup / Before function:

          // BUTTON
          pinMode(BUTTON_OUTPUT_PIN, OUTPUT);                          // Set a digital pin as power output
          digitalWrite(BUTTON_OUTPUT_PIN, LOW);
          pinMode(BUTTON_INPUT_PIN, INPUT_PULLUP);                     // Set another digital pin as power input
        

        In the loop:

          wait(20);
        
          // ON DEVICE TOGGLE BUTTON
          if (digitalRead(BUTTON_INPUT_PIN) == LOW) {
            button_pressed = true;
            Serial.print(F("."));
          }
        
        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbemowsk
          wrote on last edited by
          #4

          Out of curiosity, would there be any practical reason for doing it this way? Maybe there is an advantage that I am not thinking of. It just seems though that it is a waste of a pin, not to mention that it is more code to get it working.

          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
          1
          • alowhumA Offline
            alowhumA Offline
            alowhum
            Plugin Developer
            wrote on last edited by
            #5

            @dbemowsk The Nano only has so many GND and VCC pins. This allows me to connect a relay, an LED and this button directly with dupont wires. No breadboard/expansion board/soldering required.

            zboblamontZ 1 Reply Last reply
            1
            • alowhumA alowhum

              @dbemowsk The Nano only has so many GND and VCC pins. This allows me to connect a relay, an LED and this button directly with dupont wires. No breadboard/expansion board/soldering required.

              zboblamontZ Offline
              zboblamontZ Offline
              zboblamont
              wrote on last edited by
              #6

              @alowhum Seems a bit wasteful of Nano pins for the sake of 2 lines of Veroboard and some header pins though, but if it works for you... ;)

              alowhumA 1 Reply Last reply
              0
              • zboblamontZ zboblamont

                @alowhum Seems a bit wasteful of Nano pins for the sake of 2 lines of Veroboard and some header pins though, but if it works for you... ;)

                alowhumA Offline
                alowhumA Offline
                alowhum
                Plugin Developer
                wrote on last edited by
                #7

                @zboblamont It's not very wasteful if you're not using them for anything else anyway. I'd rather use some extra code than extra hardware.

                1 Reply Last reply
                1

                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
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                4

                Online

                12.0k

                Users

                11.2k

                Topics

                113.4k

                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