user4557: I want to use an Arduino Uno for a data-acquisition purpose.
Normally adhoc data acquisition boards can record each sample at a desired sampling rate. So that I can plot all the samples recorded. I want to do the same sort if thing with Arduino.
I want to record 30 minutes of analog voltage input at 4kHz sampling rate and record all the samples taken to a PC. 
And at the end I want to be able to plot the data with all samples not the averages ect.
Is there an easy workaround for this?

user7508: Here is a program I wrote that follows an approach somewhat similar to
Michael Stachowsky's answer:

The ADC is configured with the prescaler set to 128 (just like the
Arduino core does), which gives a 104 µs conversion time,
significantly shorter than the 250 µs sampling period you want.
The first conversion takes longer, and it is discarded.
It is also configured an auto-trigger mode, and the timer 1 overflow
flag is selected as its trigger source.
The timer 1 is configured to loop every 500 × 8 = 4000 CPU cycles
(clocked at F_CPU / 8, with TOP = 499), which
provides the required 250 µs sampling period. It is set in a PWM
mode even though the PWM outputs are not used, simply because in this
mode the overflow flag is set every time the timer loops.
An interrupt is triggered every time an ADC conversion is complete.
The interrupt service routine clears the timer overflow flag (this is
required because the ADC is triggered by the rising edges of this
flag), saves the result in a global variable and sets a global flag.
The main loop waits for that flag and sends the data through the
serial port, in binary, LSB first:

the sample number modulo 64 (6 bits)
the sample value (10 bits).

The serial port runs at 115.2 kb/s, it can then transmit the two bytes
of data in about 174 µs, which is less than the sampling period.
The sample numbers, and a 16-byte preamble can be used as a sanity
check by the receiving end.

#include <avr/interrupt.h>

void setup()
{
    Serial.begin(115200);

    // Transmit preamble.
    for (int i = 0; i < 16; i++)
        Serial.write(0xff);

    // Start the ADC.
    ADMUX  = _BV(REFS0)   // reference = Vcc
           | 0;           // input = ADC0
    ADCSRA = _BV(ADEN)    // enable the ADC
           | _BV(ADSC)    // start first conversion
           | _BV(ADPS0)   // prescaler = 128,
           | _BV(ADPS1)   // ditto
           | _BV(ADPS2);  // ditto

    // Wait for the first conversion to complete.
    loop_until_bit_is_set(ADCSRA, ADIF);

    // Wait for the preamble to be fully transmitted.
    Serial.flush();

    // Stop timer 1.
    TCCR1A = 0;
    TCCR1B = 0;

    // Configure the ADC in auto-trigger mode.
    ADCSRA |= _BV(ADATE)   // enable auto-trigger
            | _BV(ADIF)    // clear interrupt flag
            | _BV(ADIE);   // enable interrupt
    ADCSRB  = _BV(ADTS1)   // trigger source = timer 1 overflow
            | _BV(ADTS2);  // ditto

    // Configure Timer 1.
    ICR1   = 500 - 1;     // period = 500 * 8 CPU cycles
    TCCR1A = _BV(WGM11);  // mode 14: fast PWM,
    TCCR1B = _BV(WGM12)   // ... TOP = ICR1,
           | _BV(WGM13)   // ... overflow flag set on TOP
           | _BV(CS11);   // clock at F_CPU / 8
}

volatile uint16_t reading = 0xffff;
volatile bool reading_available;

ISR(ADC_vect)
{
    TIFR1 |= _BV(TOV1);    // clear timer overflow flag
    uint16_t x = reading;  // work on a copy of the reading
    x &= ~0x03ff;          // remove previous ADC value
    x |= ADC;              // add current ADC value
    x += 0x0400;           // increment sample number
    reading = x;
    reading_available = true;
}

void loop()
{
    // Wait for a reading to be available.
    while (!reading_available) ;

    // Grab a copy.
    uint16_t x = reading;
    reading_available = false;

    // Transmit, LSB first.
    Serial.write(x >> 0);  // low byte
    Serial.write(x >> 8);  // high byte
}

How you deal with the data on the receiving end (save to file, skip
preamble, check sample number consistency, extract sample values, plot
them...) is up to you. You can use whatever language and tools you want.
It is not an Arduino-related question.
Addendum: More about the binary format used.
There is a preamble consisting of 16 0xff bytes. This can be useful
because it is not uncommon to get in one file a mix of data from two
different runs of the program. The buffering of the serial port on the
PC can lead to this happening. If you do not want that preamble, remove
the two lines right after the “Transmit preamble.” comment.
Then there is a continuous stream of 16-bit unsigned integers
(uint16_t), transmitted LSB first (i.e. little endian). The byte order
can be changed by swapping the two Serial.write() by the end of the
program.
Each of these integers contains an ADC reading in the lower 10 bits and
a sample number in the upper 6 bits. The sample number can be extracted
by right-shifting (x >> 10 in C) and could be used as a sanity check
(the number should increment by 1, modulo 64, from one sample to the
next). The ADC reading can be extracted by masking out the sample number
(x & 0x03ff).
If you do not want the sample numbers, you can simplify the ISR to:
ISR(ADC_vect)
{
    TIFR1 |= _BV(TOV1);    // clear timer overflow flag
    reading = ADC;         // read the ADC result
    reading_available = true;
}

and remove the (now useless) initialization of the reading variable.

4557: <p>I want to use an Arduino Uno for a data-acquisition purpose.</p>

<p>Normally adhoc data acquisition boards can record each sample at a desired sampling rate. So that I can plot all the samples recorded. I want to do the same sort if thing with Arduino.</p>

<p>I want to record 30 minutes of analog voltage input at 4kHz sampling rate and record all the samples taken to a PC. </p>

<p>And at the end I want to be able to plot the data with all samples not the averages ect.</p>

<p>Is there an easy workaround for this?</p>
 7508: <p>Here is a program I wrote that follows an approach somewhat similar to
Michael Stachowsky's answer:</p>

<ul>
<li><p>The ADC is configured with the prescaler set to 128 (just like the
Arduino core does), which gives a 104&nbsp;µs conversion time,
significantly shorter than the 250&nbsp;µs sampling period you want.
The first conversion takes longer, and it is discarded.</p></li>
<li><p>It is also configured an auto-trigger mode, and the timer 1 overflow
flag is selected as its trigger source.</p></li>
<li><p>The timer 1 is configured to loop every 500 × 8 = 4000 CPU cycles
(clocked at F_CPU&nbsp;/&nbsp;8, with TOP&nbsp;=&nbsp;499), which
provides the required 250&nbsp;µs sampling period. It is set in a PWM
mode even though the PWM outputs are not used, simply because in this
mode the overflow flag is set every time the timer loops.</p></li>
<li><p>An interrupt is triggered every time an ADC conversion is complete.
The interrupt service routine clears the timer overflow flag (this is
required because the ADC is triggered by the rising edges of this
flag), saves the result in a global variable and sets a global flag.</p></li>
<li><p>The main loop waits for that flag and sends the data through the
serial port, in binary, LSB first:</p>

<ul>
<li>the sample number modulo 64 (6 bits)</li>
<li>the sample value (10 bits).</li>
</ul></li>
<li><p>The serial port runs at 115.2 kb/s, it can then transmit the two bytes
of data in about 174&nbsp;µs, which is less than the sampling period.</p></li>
<li><p>The sample numbers, and a 16-byte preamble can be used as a sanity
check by the receiving end.</p></li>
</ul>



<pre class="lang-c++ prettyprint-override"><code>#include &lt;avr/interrupt.h&gt;

void setup()
{
    Serial.begin(115200);

    // Transmit preamble.
    for (int i = 0; i &lt; 16; i++)
        Serial.write(0xff);

    // Start the ADC.
    ADMUX  = _BV(REFS0)   // reference = Vcc
           | 0;           // input = ADC0
    ADCSRA = _BV(ADEN)    // enable the ADC
           | _BV(ADSC)    // start first conversion
           | _BV(ADPS0)   // prescaler = 128,
           | _BV(ADPS1)   // ditto
           | _BV(ADPS2);  // ditto

    // Wait for the first conversion to complete.
    loop_until_bit_is_set(ADCSRA, ADIF);

    // Wait for the preamble to be fully transmitted.
    Serial.flush();

    // Stop timer 1.
    TCCR1A = 0;
    TCCR1B = 0;

    // Configure the ADC in auto-trigger mode.
    ADCSRA |= _BV(ADATE)   // enable auto-trigger
            | _BV(ADIF)    // clear interrupt flag
            | _BV(ADIE);   // enable interrupt
    ADCSRB  = _BV(ADTS1)   // trigger source = timer 1 overflow
            | _BV(ADTS2);  // ditto

    // Configure Timer 1.
    ICR1   = 500 - 1;     // period = 500 * 8 CPU cycles
    TCCR1A = _BV(WGM11);  // mode 14: fast PWM,
    TCCR1B = _BV(WGM12)   // ... TOP = ICR1,
           | _BV(WGM13)   // ... overflow flag set on TOP
           | _BV(CS11);   // clock at F_CPU / 8
}

volatile uint16_t reading = 0xffff;
volatile bool reading_available;

ISR(ADC_vect)
{
    TIFR1 |= _BV(TOV1);    // clear timer overflow flag
    uint16_t x = reading;  // work on a copy of the reading
    x &amp;= ~0x03ff;          // remove previous ADC value
    x |= ADC;              // add current ADC value
    x += 0x0400;           // increment sample number
    reading = x;
    reading_available = true;
}

void loop()
{
    // Wait for a reading to be available.
    while (!reading_available) ;

    // Grab a copy.
    uint16_t x = reading;
    reading_available = false;

    // Transmit, LSB first.
    Serial.write(x &gt;&gt; 0);  // low byte
    Serial.write(x &gt;&gt; 8);  // high byte
}
</code></pre>

<p>How you deal with the data on the receiving end (save to file, skip
preamble, check sample number consistency, extract sample values, plot
them...) is up to you. You can use whatever language and tools you want.
It is <em>not</em> an Arduino-related question.</p>

<p><strong>Addendum</strong>: More about the binary format used.</p>

<p>There is a preamble consisting of 16 <code>0xff</code> bytes. This can be useful
because it is not uncommon to get in one file a mix of data from two
different runs of the program. The buffering of the serial port on the
PC can lead to this happening. If you do not want that preamble, remove
the two lines right after the “Transmit preamble.” comment.</p>

<p>Then there is a continuous stream of 16-bit unsigned integers
(<code>uint16_t</code>), transmitted LSB first (i.e. little endian). The byte order
can be changed by swapping the two <code>Serial.write()</code> by the end of the
program.</p>

<p>Each of these integers contains an ADC reading in the lower 10 bits and
a sample number in the upper 6 bits. The sample number can be extracted
by right-shifting (<code>x &gt;&gt; 10</code> in C) and could be used as a sanity check
(the number should increment by 1, modulo 64, from one sample to the
next). The ADC reading can be extracted by masking out the sample number
(<code>x &amp; 0x03ff</code>).</p>

<p>If you do not want the sample numbers, you can simplify the ISR to:</p>

<pre class="lang-c++ prettyprint-override"><code>ISR(ADC_vect)
{
    TIFR1 |= _BV(TOV1);    // clear timer overflow flag
    reading = ADC;         // read the ADC result
    reading_available = true;
}
</code></pre>

<p>and remove the (now useless) initialization of the <code>reading</code> variable.</p>
