user82341: I am reading analog sensor data using Arduino nano, and the required sampling rate is around 1kHz. I am using the AnalogReadSerial example provided by Arduino with a delay of 1ms, so I am expecting to get around 1000 samples per second or slightly less due to the ADC conversion delay. However, the maximum number of samples I am able to get in my laptop a little bit less than 200 samples per seconds. I have tried increasing the baud rate to 115200 but that was not helpful. Am I missing something here, or is there something I need to do to get my data at the required sampling rate?
Below is AnalogReadSerial code I used for reference:
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}


user7508: As I said in a comment, your code on my Uno gives me
791.5 samples/s. This is about 1263 µs per sample:

about 110 µs for analogRead(), including 104 µs for the
conversion proper
presumably 1000 µs for delay(1)
153 µs for the rest of the code, mostly formatting sensorValue
in ASCII

According to these timings, if it were not for the call to delay(),
the Arduino should be able to complete the loop in one millisecond, and
still have 737 µs to spare. The simplest way to achieve this is to
follow the Blink Without Delay strategy:
void loop() {
    static uint32_t last_conversion_time = micros();
    if (micros() - last_conversion_time >= 1000) {
        last_conversion_time += 1000;
        Serial.println(analogRead(A0));
    }
}

This does give me 1000 samples per second. Note that
last_conversion_time is updated by adding 1000 µs rather than
setting it to micros(), so this is actually a variation on the Blink
Without Delay strategy. Updating last_conversion_time in this fashion
ensures that whenever the program gets late and misses the exact
microsecond it wanted, the small timing errors do not accumulate.
For the maximum possible timing accuracy, it would be more appropriate
to trigger the ADC by a timer, but that approach is more complex and
requires carefully reading the datasheet of the microcontroller.

82341: <p>I am reading analog sensor data using Arduino nano, and the required sampling rate is around 1kHz. I am using the AnalogReadSerial example provided by Arduino with a delay of 1ms, so I am expecting to get around 1000 samples per second or slightly less due to the ADC conversion delay. However, the maximum number of samples I am able to get in my laptop a little bit less than 200 samples per seconds. I have tried increasing the baud rate to 115200 but that was not helpful. Am I missing something here, or is there something I need to do to get my data at the required sampling rate?</p>
<p>Below is AnalogReadSerial code I used for reference:</p>
<pre><code>// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
</code></pre>
 7508: <p>As I said in a comment, your code on my Uno gives me
791.5 samples/s. This is about 1263 µs per sample:</p>
<ul>
<li>about 110 µs for <code>analogRead()</code>, including 104 µs for the
conversion proper</li>
<li>presumably 1000 µs for <code>delay(1)</code></li>
<li>153 µs for the rest of the code, mostly formatting <code>sensorValue</code>
in ASCII</li>
</ul>
<p>According to these timings, if it were not for the call to <code>delay()</code>,
the Arduino should be able to complete the loop in one millisecond, and
still have 737 µs to spare. The simplest way to achieve this is to
follow the <a href="https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay" rel="nofollow noreferrer">Blink Without Delay</a> strategy:</p>
<pre class="lang-cpp prettyprint-override"><code>void loop() {
    static uint32_t last_conversion_time = micros();
    if (micros() - last_conversion_time &gt;= 1000) {
        last_conversion_time += 1000;
        Serial.println(analogRead(A0));
    }
}
</code></pre>
<p>This does give me 1000 samples per second. Note that
<code>last_conversion_time</code> is updated by adding 1000 µs rather than
setting it to <code>micros()</code>, so this is actually a variation on the Blink
Without Delay strategy. Updating <code>last_conversion_time</code> in this fashion
ensures that whenever the program gets late and misses the exact
microsecond it wanted, the small timing errors do not accumulate.</p>
<p>For the maximum possible timing accuracy, it would be more appropriate
to trigger the ADC by a timer, but that approach is more complex and
requires carefully reading the datasheet of the microcontroller.</p>
