Elegoo UNO R3 runs loop code for 1 second and then stops

Hi,

I've just got an Elegoo Uno R3. I'm trying to run a very basic LED flash which works for about 1 second and then seems to stop. I have nothing else connected to the board. The UNO is simply connected to my PC via USB. Here's the code:

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13, HIGH);
  delay(100);
  digitalWrite(13, LOW);
  delay(900);
}

As I said, the LED blinks at the expected tempo for 1 second and then stops. It doesn't blink again as expected until I reset the board or re-upload the code. The TX and RX LEDs blink at the end of each run. The ON LED holds a stable output while the board is plugged in to my PC. Even if I paste the loop code 4 or 5 times, it still only runs for a second or so and then stops. Yesterday I made an ultrasonic distance measuring circuit which worked but was very intermittent, sometimes requiring a reset before the measurement values on the LCD would update. I'm wondering if there is a core issue causing all of this.

Any ideas what's going on here?

Are you using an external LED or the built-in LED only? If you're using an external LED, do you have a current limiting resistor in place?

The built in LED, no breadboard or any other components attached. I actually just got it working - but I'm not really sure how. For better visibility, I changed my code to:

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13, HIGH);
  delay(3000);
  digitalWrite(13, LOW);
  delay(2000);
}

This ran fine, runnning on a loop as expected. So I changed back to my original code and tried it again and it seems to be working now. Interestingly, the RX and TX lights are no longer blinking, either. I'm really not sure what happened here!

EDIT: sorry guys I think it was just me being stupid HA. Merry Christmas!

You might not be able to see this "on" time, so it looks "off" all the time.

That is odd, but so is your statement that the original works for about 1 sec. Since your loop is 1 sec long (900 + 100), I think you are being imprecise in your description. As far as I can see, you have not answered questions regarding limiting the resistor or external vs. built-in LED.
IF you just want to use the built-in LED, do NOT use 13, use LED_BUILTIN.
Try the built-in sample code for Blink; your delays of 100 and 900 may not allow you to see anything. Here is a reminder of what the example sketch looks like.

Can I ask: it was my understanding thta LED_BUILTIN just automatically uses the correct pin number for whichever board you have selected in the IDE. What is actually the difference, in this case, between LED_BUILTIN and just pin 13?

The built-in LED has a current limiting resistor, pin 13 does not. So you have to add one if you use an external LED.

You answered your own question. By using LED_BUILTIN you do NOT need to know the pin number. Also see post #8.

But, to be clear, LED_BUILTIN is just a variable which, for the Uno, has the value 13.

It's still a puzzle as to what was going on in the first place. Maybe a bad USB connection? Is there anything funny about Elegoo clones, like maybe their own bootloader? The sketch should certainly have run for more than one second.

  • There might be some soldering problems with your new board.
    Take a close look at the quality of each connection.

  • Always show us a good schematic of your proposed circuit. Show us good images of your ‘actual’ wiring.

The 100 ms on-time is clearly visible as a distinct flash.

Would you try this sketch - it is your sketch, plus some Serial Monitor commands?

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.print(digitalRead(LED_BUILTIN));
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  Serial.print(digitalRead(LED_BUILTIN));
  delay(900);
}

I received exactly ONE bad knock-off Uno/NanoR3 from Amazon, and the symptoms were:

  • start blink.ino
  • blink.ino runs a little, then dies
  • I added Serial.print()
  • after a few seconds, serial port starts producing only random characters

I did not try to fix this Uno, as it was part of a kit that I only wanted the peripherals.

Is there any good reason to using symbolic name instead of numerical DPin number for the onboard LED?

I have tried. The onboard LED flashes for 100 ms as usual.

Sorry... I intended that post to be for thread OP to test their Arduino... or are you he?

Your post #13 directly followed my post #12, so I assumed that #13 was addressed to me. If it was intended for someone else, please include @username at the beginning of your post.

I understand you might think my post after your post is addressing you, but my reply was not intended for "someone else." It was intended for OP of the post. I will use your username to directly make a call to you... I hope I will, anyway. [I usually use a "quote" which includes your avatar in my reply]

I used the big Reply-to-thread button, rather than the small Reply-to-user button. This is called "understood" in my native grammar (for example.. "Send the reply (understood is: 'to me')" but can be this ignored/not included with just "Send the reply.").

It might be that I have not yet understood how the Arduino Forum works being here for the last 8 years. Now, I know that a free posted post is always for the OP.

Thanks for clarification.

Not all ripe apples are red.

Yes, suppose you were looking after a small 10,000-line-of-code system, and you had to change pin 13 everywhere to pin 35. With LED_BUILTIN, that is one line of code, with the pin hard-coded; it's probably hundreds, if not thousands, of changes. Yes, loading a bunch of affected files and doing a global find-and-replace speeds it up, but while you are just a few 10's of seconds into that, the LED_BUILTIN has already been changed. Programming 101.