UNO rev3 Serial Communication locks after several minutes

I'm using an UNO rev3 board. My program blinks and sends Hello to my PC:

void setup()
{
  pinMode(13,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  Serial.println("Hello");
}

This results in a blinking pin 13 led AND a regular blinking of the TX led. If the console / communication / serial window is open, this seems to work fine (even over time, say one hour), but if the window is closed the program will continue for a while (a couple of minutes) and then "sort of stops", meaning: the pin 13 led keeps blinking, but the TX led keeps on; it doesn't blink anymore! I fear it doesn't send anything anymore. But: shouldn't it keep sending Hello, even if no-one is listening?

Anyone any thoughts on this ?

Yes your sketch is still sending out serial data, however if there is no program in the PC attached to the com port then there will be no data being sent to the PC, this is a function of the arduino on-board USB serial converter chip and the PC's USB driver supporting the arduino board, and it's that chip that controls the send and receive leds, not the avr chip running your sketch.

So reopen the serial monitor and it will reset the board, restarting the sketch and the serial send led will run for as long as you have the serial monitor opened, close it and the serial send led should stop.

That make sense?

Lefty

Wow, this makes a world of sense. I hadn't thought of that, thank you for the explanation !

Now I might be overstepping the boundary of this thread, but I have several UNO's, and one of them is displaying weird behaviour, of which the topic of the thread was one.

The sketch I intended to use sends serial data from a SRF05 ultrasonic distance sensor to the PC. Now all is working well if I connect the SRF05 to GND, 5V and two pins (2 and 3) and then connect USB to PC. Everything works. But if I connect first USB, and after that 5V and then GND to the sensor, the COM port blocks.

If everything works fine and I remove the 5V from the sensor: the COM port blocks.

Now this seems weird, because disconnecting the 5V from the sensor would stop it from working, which means the software will send "0" to the PC.

Now only one of my UNO's has this behaviour.

I can post this under sensors but I think the problem is not with the sensor (since sketch and sensor work fine in any way with another UNO).

I hope you can shed some light on this as well.

Cheers !

Jack

I hope you can shed some light on this as well.

What it is telling me is that you are clueless. Connecting and disconnecting sensors and LEDs while the Arduino is powered is not a good idea. I can't tell you how many people have destroyed a chip or a whole Arduino because a hot wire slipped and connected to something it shouldn't have. Save your Arduinos. Stop hot swapping attachments.

Dear Paul,

thank you for your reply. The problem does seem to be in the hot swapping. I have used an external power supply for the sensor now and swapping or disconnecting wires is no problem now. It seems connecting / disconnecting Vcc / gnd from the arduino is a problem with this sensor.

That said, I have used arduinos for a couple of years now and have not encountered this problem before. I will remember your advice for when I run into problems like this one again, I'm amazed it never went wrong before. I wonder if it is specific for this sensor (it draws about 0.01 Amps).

The sensor is working now as expected, more or less. It measures about 40 measurements, waits for a while, then starts measuring again. This is not the expected behaviour, but it repeats it over time: a delay between series of measurements where it is not programmed into the code:

#define ECHOPIN 2                            // Pin to receive echo pulse
#define TRIGPIN 3                            // Pin to send trigger pulse

void setup(){
  Serial.begin(9600);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
}

void loop(){
  digitalWrite(TRIGPIN, LOW);                   // Set the trigger pin to low for 2uS
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);                  // Send a 10uS high to trigger ranging
  delayMicroseconds(10);
  digitalWrite(TRIGPIN, LOW);                   // Send pin low again
  int distance = pulseIn(ECHOPIN, HIGH);        // Read in times pulse
  distance= distance/58;                        // Calculate distance from time of pulse
  Serial.println(distance);                     
  delay(50);                                    // Wait 50mS before next ranging
}

I might post this question under sensors, because I have the feeling this is not caused by the connection with the PC.

Cheers

Jack