user4557: Consider the following code:
void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

The line buttonState = digitalRead(buttonPin); checks the input voltage.
But how is that checked internally? 
I mean at what rate the input is checked?

user4143: That depends on the frequency your Arduino runs at. 
It's basically once per iteration of the loop, and that depends on everything that is happening in the loop.
You can examine the assembly language output of the compiler (disassemble the .elf file using avr-objdump -h -S <elf file>) and count the number of clock cycles per iteration (the datasheet has the number of clock cycles per instruction). However that is tedious.
If you want to read the input at a specific frequency then you should do it using a timer interrupt.

user30005: 
When I get time, I will provide more definitive answers.

I did follow through with this, and the result is here, towards the end of the page: https://dannyelectronics.wordpress.com/2016/05/01/the-price-of-avr-arduino/
the short answer is: digitalRead() takes 4.9us to execute on a 16MIPS Arduino Uno, or 79 ticks (=instructions).
the fastest you can read digitalRead() is then 200KHz (= 1/4.9us).
Hope it helps.

user30179: It read a port just like it reads memory (to which it's mapped.) So speed is how fast an instruction can read memory.  EEPROM is a different animal.
Might get it a little faster by replacing  
buttonState = digitalRead(buttonPin);
    with
buttonState = PORTB & _BV(buttonPin);
Assuming it's PORTB that you are using. This will alleviate at least one function call, I would think, and will generate a single instruction to read the port into the variable. It may require an instruction to load the variable address, but that's up to the compiler.  The replacement may be more trouble porting to other micros.  Normally you don't see a variable as a parameter although legal, usually a constant in a #define.  
_BV(INPUT_PIN_X) is a macro (BV is for 'bit value') that expands to
(1 << INPUT_PIN_X)
dannyf times seem quick to me, but it sounds like he's done the testing. Is he taking into account the complete function call as part of the time?  I run at 1Mhz normally, so it's more difficult to relate.  
Take Majenko advice and start reading the generated assembler :)
Best of luck.

4557: <p>Consider the following code:</p>

<pre><code>void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}
</code></pre>

<p>The line <strong>buttonState = digitalRead(buttonPin);</strong> checks the input voltage.</p>

<p>But how is that checked internally? </p>

<p>I mean at what rate the input is checked?</p>
 4143: <p>That depends on the frequency your Arduino runs at. </p>

<p>It's basically once per iteration of the loop, and that depends on everything that is happening in the loop.</p>

<p>You can examine the assembly language output of the compiler (disassemble the .elf file using <code>avr-objdump -h -S &lt;elf file&gt;</code>) and count the number of clock cycles per iteration (the datasheet has the number of clock cycles per instruction). However that is tedious.</p>

<p>If you want to read the input at a specific frequency then you should do it using a timer interrupt.</p>
 30005: <blockquote>
  <p>When I get time, I will provide more definitive answers.</p>
</blockquote>

<p>I did follow through with this, and the result is here, towards the end of the page: <a href="https://dannyelectronics.wordpress.com/2016/05/01/the-price-of-avr-arduino/" rel="nofollow noreferrer">https://dannyelectronics.wordpress.com/2016/05/01/the-price-of-avr-arduino/</a></p>

<p>the short answer is: digitalRead() takes 4.9us to execute on a 16MIPS Arduino Uno, or 79 ticks (=instructions).</p>

<p>the fastest you can read digitalRead() is then 200KHz (= 1/4.9us).</p>

<p>Hope it helps.</p>
 30179: <p>It read a port just like it reads memory (to which it's mapped.) So speed is how fast an instruction can read memory.  EEPROM is a different animal.</p>

<p>Might get it a little faster by replacing  </p>

<p>buttonState = digitalRead(buttonPin);<br>
    with<br>
buttonState = PORTB &amp; _BV(buttonPin);</p>

<p>Assuming it's PORTB that you are using. This will alleviate at least one function call, I would think, and will generate a single instruction to read the port into the variable. It may require an instruction to load the variable address, but that's up to the compiler.  The replacement may be more trouble porting to other micros.  Normally you don't see a variable as a parameter although legal, usually a constant in a #define.  </p>

<p>_BV(INPUT_PIN_X) is a macro (BV is for 'bit value') that expands to<br>
(1 &lt;&lt; INPUT_PIN_X)</p>

<p>dannyf times seem quick to me, but it sounds like he's done the testing. Is he taking into account the complete function call as part of the time?  I run at 1Mhz normally, so it's more difficult to relate.  </p>

<p>Take Majenko advice and start reading the generated assembler :)</p>

<p>Best of luck.</p>
