user11856: I am working in my project and i want to use Timer2 interrupt every 100ms to get new measurement from the output of my 5 sensors which connected to pins A1,A2,A3,A4,A5.
I read in some article that using delay instruction is not as good as using timers'Interruptions so, I tried this code put it didn't work properly :
void setup(){

cli();

  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2  = 0;
  OCR2A = 99;
  TCCR2A |= (1 << WGM21);
  TCCR2B |= (1 << CS21);   
  TIMSK2 |= (1 << OCIE2A);
sei();

Serial.begin(9600);  
}
void loop()
{
Serial.print(digitalRead(1));
Serial.print(' ');
Serial.print(digitalRead(2));
Serial.print(' ');
Serial.print(digitalRead(3));
Serial.print(' ');
Serial.print(digitalRead(4));
Serial.print(' ');
Serial.print(digitalRead(5));
Serial.println(' ');

}


user10794: Well let's start from the start ...

Analog readings

to get new measurement from the output of my 5 sensors which connected to pins A1,A2,A3,A4,A5.

Serial.print(digitalRead(1));

That is not reading analog pin A1, it is reading digital pin 1. If you want to read A1 you need:
Serial.print(analogRead(1));


Check the time
By far the simplest thing would be to simply check the time and take a reading when 100 ms is up.
Example:
void setup()
{
  Serial.begin(115200);  
}  // end of setup

unsigned long lastReading;
const unsigned long INTERVAL = 100;  // ms

void loop()
{

  // is time up?
  if (millis () - lastReading >= INTERVAL)
    {
    lastReading = millis ();  // when we took this reading
    Serial.print(analogRead(1));
    Serial.print(" ");
    Serial.print(analogRead(2));
    Serial.print(" ");
    Serial.print(analogRead(3));
    Serial.print(" ");
    Serial.print(analogRead(4));
    Serial.print(" ");
    Serial.print(analogRead(5));
    Serial.println();
    }  // end of if time up

  // do other things here

}  // end of loop

I increased the baud rate to 115200. Why use 9600 when you are trying to print 5 x 4 characters every 100 ms? 

Using timers
If you really want to use timers (and I don't see what they achieve here) I have a page about timers that describes using them, and interrupts, in some depth.
The very least you would need is a timer 2 "compare A" interrupt like this:
ISR (TIMER2_COMPA_vect) 
  {
  // Timer 2 has reached its comparison value
  }


11856: 

<p>I am working in my project and i want to use Timer2 interrupt every 100ms to get new measurement from the output of my 5 sensors which connected to pins A1,A2,A3,A4,A5.</p>

<p>I read in some article that using delay instruction is not as good as using timers'Interruptions so, I tried this code put it didn't work properly :</p>

<pre class="lang-C++ prettyprint-override"><code>void setup(){

cli();

  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2  = 0;
  OCR2A = 99;
  TCCR2A |= (1 &lt;&lt; WGM21);
  TCCR2B |= (1 &lt;&lt; CS21);   
  TIMSK2 |= (1 &lt;&lt; OCIE2A);
sei();

Serial.begin(9600);  
}
void loop()
{
Serial.print(digitalRead(1));
Serial.print(' ');
Serial.print(digitalRead(2));
Serial.print(' ');
Serial.print(digitalRead(3));
Serial.print(' ');
Serial.print(digitalRead(4));
Serial.print(' ');
Serial.print(digitalRead(5));
Serial.println(' ');

}
</code></pre>
 10794: 

<p>Well let's start from the start ...</p>

<hr>

<h2>Analog readings</h2>

<blockquote>
  <p>to get new measurement from the output of my 5 sensors which connected to pins A1,A2,A3,A4,A5.</p>
</blockquote>

<pre class="lang-C++ prettyprint-override"><code>Serial.print(digitalRead(1));
</code></pre>

<p>That is not reading <strong>analog</strong> pin A1, it is reading <strong>digital</strong> pin 1. If you want to read A1 you need:</p>

<pre class="lang-C++ prettyprint-override"><code>Serial.print(analogRead(1));
</code></pre>

<hr>

<h2>Check the time</h2>

<p>By far the simplest thing would be to simply check the time and take a reading when 100 ms is up.</p>

<p>Example:</p>

<pre class="lang-C++ prettyprint-override"><code>void setup()
{
  Serial.begin(115200);  
}  // end of setup

unsigned long lastReading;
const unsigned long INTERVAL = 100;  // ms

void loop()
{

  // is time up?
  if (millis () - lastReading &gt;= INTERVAL)
    {
    lastReading = millis ();  // when we took this reading
    Serial.print(analogRead(1));
    Serial.print(" ");
    Serial.print(analogRead(2));
    Serial.print(" ");
    Serial.print(analogRead(3));
    Serial.print(" ");
    Serial.print(analogRead(4));
    Serial.print(" ");
    Serial.print(analogRead(5));
    Serial.println();
    }  // end of if time up

  // do other things here

}  // end of loop
</code></pre>

<p>I increased the baud rate to 115200. Why use 9600 when you are trying to print 5 x 4 characters every 100 ms? </p>

<hr>

<h2>Using timers</h2>

<p>If you really want to use timers (and I don't see what they achieve here) I have a <a href="http://www.gammon.com.au/timers" rel="nofollow">page about timers</a> that describes using them, and interrupts, in some depth.</p>

<p>The very least you would need is a timer 2 "compare A" interrupt like this:</p>

<pre class="lang-C++ prettyprint-override"><code>ISR (TIMER2_COMPA_vect) 
  {
  // Timer 2 has reached its comparison value
  }
</code></pre>
