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. Development
  3. using pins A6 and A7 of arduino pro mini to read push button state

using pins A6 and A7 of arduino pro mini to read push button state

Scheduled Pinned Locked Moved Development
7 Posts 4 Posters 5.2k Views 5 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.
  • rozpruwaczR Offline
    rozpruwaczR Offline
    rozpruwacz
    wrote on last edited by
    #1

    Hi all,

    so I run out of pins in my project where I use arduino pro mini. After 2 days of thinking I realised that my arduino has two more not used pins, but the are only for ADC. But hey, I just want to read a push button state (pressed or released). So I figured out that I will add a pull up resistor to this pins and just use analogRead for those pins and just do:
    pinState = analogRead(A6) >= 512;

    so is there any drawbacks to this solution ? I would imagine that analogRead would be slower than digitalRead, is there a way to make it faster ? I just need to know if the button is pressed or not.

    mfalkviddM 1 Reply Last reply
    0
    • rozpruwaczR rozpruwacz

      Hi all,

      so I run out of pins in my project where I use arduino pro mini. After 2 days of thinking I realised that my arduino has two more not used pins, but the are only for ADC. But hey, I just want to read a push button state (pressed or released). So I figured out that I will add a pull up resistor to this pins and just use analogRead for those pins and just do:
      pinState = analogRead(A6) >= 512;

      so is there any drawbacks to this solution ? I would imagine that analogRead would be slower than digitalRead, is there a way to make it faster ? I just need to know if the button is pressed or not.

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #2

      @rozpruwacz I am not sure if analogRead is slower but if it is, it will not make a difference when reading button presses, unless you are able to click many thousand times per second.

      You can perform a digitalRead on an analog pin if you want to though, see https://www.arduino.cc/en/Reference/DigitalRead

      One thing to remember: there is no internal pullup on A6 and A7, so you'll have to add your own external pullup.

      Nca78N 1 Reply Last reply
      1
      • rozpruwaczR Offline
        rozpruwaczR Offline
        rozpruwacz
        wrote on last edited by rozpruwacz
        #3

        @mfalkvidd said in using pins A6 and A7 of arduino pro mini to read push button state:

        own external pullu

        from the documentation it takes 100us for analog read, so its about 800 instructions for single read when running at 8MHz. Doing it in the main loop in every iteration for couple of pins will make a difference. Of course I will try first as simple as possible, but i'm worried that my node which acts as a repeater will not do its reapeter job very well ...

        mfalkviddM 1 Reply Last reply
        0
        • rozpruwaczR rozpruwacz

          @mfalkvidd said in using pins A6 and A7 of arduino pro mini to read push button state:

          own external pullu

          from the documentation it takes 100us for analog read, so its about 800 instructions for single read when running at 8MHz. Doing it in the main loop in every iteration for couple of pins will make a difference. Of course I will try first as simple as possible, but i'm worried that my node which acts as a repeater will not do its reapeter job very well ...

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

          @rozpruwacz sending a single message on nrf24 takes about 1ms, which is 10x the time it takes to do an analogRead (1ms = 1,000 us). So unless you need to check the button more than several thousand times per second you're going to be fine.

          Quick calculation example: let's say you have 10 buttons and you want to check each them 50 times per second (which is much faster than a human can react, normal reaction time is about 1/10 to 1/20 second). That would require checking 10 * 50 * 100us = 50,000us = 50 ms. You'll still have 950ms to do everything else. So even an extreme case would not be a problem.

          1 Reply Last reply
          0
          • rozpruwaczR Offline
            rozpruwaczR Offline
            rozpruwacz
            wrote on last edited by
            #5

            ok, that is fair enough :) didn't know the time needed to send message on nrf24.

            1 Reply Last reply
            1
            • NeverDieN Offline
              NeverDieN Offline
              NeverDie
              Hero Member
              wrote on last edited by NeverDie
              #6

              Maybe you could somehow bond your buttons and whatever else to the same interrupt pin, and then sort out after-the-fact what triggered the interrupt after the interrupt occurs? Then you wouldn't need to waste all that time polling.

              1 Reply Last reply
              0
              • mfalkviddM mfalkvidd

                @rozpruwacz I am not sure if analogRead is slower but if it is, it will not make a difference when reading button presses, unless you are able to click many thousand times per second.

                You can perform a digitalRead on an analog pin if you want to though, see https://www.arduino.cc/en/Reference/DigitalRead

                One thing to remember: there is no internal pullup on A6 and A7, so you'll have to add your own external pullup.

                Nca78N Offline
                Nca78N Offline
                Nca78
                Hardware Contributor
                wrote on last edited by
                #7

                @mfalkvidd said in using pins A6 and A7 of arduino pro mini to read push button state:

                You can perform a digitalRead on an analog pin if you want to though, see https://www.arduino.cc/en/Reference/DigitalRead
                Not on A6/A7, they are exclusively analog pins.

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


                13

                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