Go Down

Topic: Serial monitor not displaying (Read 244 times) previous topic - next topic

alexis27

i used this code

Code: [Select]
int ir_pin = 2;
int counter = 0;
int detected = false;





void setup() {
  Serial.begin(9600);
  pinMode(ir_pin,INPUT);
}

void loop() {

      int val = digitalRead(ir_pin);

      if( (val == 0) && (detected = false )  ){
          counter++;
          detected = true;
         
         
          Serial.print("count =");
          Serial.println(counter);
      }
      else if( (val == 1) && (detected = true ) ){
        detected = false;
           
      }

}



and does not display anything. but when the first time I upload it, it works fine, but when the 2nd time I upload it( I unplugged the arduino to take a break) serial monitor do not display anything.

but when i try this code:
Code: [Select]
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.print("helloo");
}


it works fine, what seems to be the problem?  please help me

sterretje

If you disconnect the Arduino, the connection in the PC is lost. When you connect again, a new connection is created. But serial monitor does not know about that new connection.

Close serial monitor and open it again.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

spycatcher2k

Code: [Select]
if( (val == 0) && (detected = false )

Oops!

Code: [Select]
if( (val == 0) && (detected == false )
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

Go Up