Serial available function

Hi All, I have come across this program that waits for an analog input before continuing with the program. However the program does not say which analog port is being used;
void setup() {
void loop() {
while(Serial.available() == 0) {
int mydata =;
Is there a particular port you need to use for this program? I am using the arduino Nano board. If there is no particular port how would you set up the port you want to use with this program?

That program does not wait for analogue input; it waits for serial input.

In the sketch, you do not have to set the serial port. The terminal program (e.g. Serial Monitor) that you use needs to be configured for the correct COM port and baudrate. In case you're not using Serial Monitor, you will also have to configure other parameters like format (8N1).

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Please use code tags when posting code. Please edit your post, select all code and click the </> button; next save your post.

this code waits for serial input before reading the A0 port and printing the value read

void loop ()
    if (Serial.available ())  { ();

        int val = analogRead (A0);
        Serial.println (val);

void setup ()
    Serial.begin (9600);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.