Serial Monitor Problems, Please Help

Hello all,
Newbie here,
I was trying to make the serial monitor output to my windows computer using a USB connection. I was initially just going to output the data being read in on an analog output. I couldn’t make that work. Then I put in a line just to output Hello World. Niether are coming on the serial monitor. I looked at the language reference to no avail.

Please Help. The code is here:

int counter = 0;
int sensorPin = A0;
int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
pinMode(10, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(9600); // open the serial port at 9600 bps:

}

void loop()
{
// PWM Code
while(counter < 50)
{
digitalWrite(10, HIGH);
delay(5);
digitalWrite(10, LOW);
delay(5);
}
delay(50);

// Thermostat Circuit
//Serial.print(Hello World);
Serial.print(“Hello world.”);
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue,DEC); // Output to the serial monitor
if (sensorValue < 50) //500 is original Value for the temperature input
{
digitalWrite(2, HIGH); // turn fan on
}
else
{
digitalWrite(2, LOW); // turn fan off
}
}
//}

  while(counter < 50)
  {
   digitalWrite(10, HIGH);
   delay(5);
   digitalWrite(10, LOW);
   delay(5);
   }

What is the value of counter when the while loop is entered? What is the value of counter for the second pass through the while loop?

Move the hello, world print to the setup function. Just after the Serial.begin.

Also, I put a delay(2000) immediately after the Serial begin to allow time for me to activate the Serial Monitor. Not sure if needed.

In any event, moving the hello, world OUTSIDE all the analog stuff will tell you if you have a printing problem or a 'something else' problem. --jim

Also, I put a delay(2000) immediately after the Serial begin to allow time for me to activate the Serial Monitor. Not sure if needed.

The rest of us are. It isn't. Opening the Serial Monitor resets the Arduino, if the Arduino has not been modified to prevent that.

Thanks all, the printer does now print the first line. I modified the code accordlingly:

int counter = 0;
int sensorPin = A0;
int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
pinMode(10, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(9600); // open the serial port at 9600 bps:

}

void loop()
{
Serial.print(“This is a test”);
// PWM Code
while(counter < 50);
{
digitalWrite(10, HIGH);
Serial.print(“pin 10 is high”);
delay(5);
digitalWrite(10, LOW);
Serial.print(“pin 10 is low”);
delay(5);
}
delay(50);
int counter = 0;
Serial.print(“counter is now reset”);

// Thermostat Circuit
digitalWrite(13, HIGH);

Serial.print(“Hello world it’s temperature measurement Time.”);
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue,DEC); // Output to the serial monitor
if (sensorValue < 50) //500 is original Value for the temperature input
{
digitalWrite(2, HIGH); // turn fan on
Serial.print(“Fan is now on”);
}
else
{
digitalWrite(2, LOW); // turn fan off
Serial.print(“Fan is now off”);
}
delay(1000);
digitalWrite(13, LOW);
}

Problem now is only the first line prints, then it seems to stall in the while loop. Any thoughts on how to get it past this one.

Go back and read all the replies. There is nothing in the while loop that changes the value of counter, so the while statement is always true.