New User: Simple LED Blink Project - Odd Behaviour

Hi All

New guy here. :slight_smile:

Just a quick one.

I'm starting off with the simple LED blinking program ( Sparkfun Tut 1 ) and it works fine, but after a couple of blinks with a 1 sec delay in between HIGH and LOW states - the LED blinks rapidly a couple of times before resuming the normal 1 sec delayed blinks.

This ONLY happens while connected to my laptop's USB3 port. It does NOT happen when i connect it to an external battery bank... on the battery bank it blinks perfectly 1 sec on and 1 sec off, with no rapid blinks after a while...

Is this something to do with the USB port ?

PS: Running the latest version of the IDE

Code:

int ledPin = 13;

void setup()
{
  pinMode(ledPin, OUTPUT);
}


void loop()
{
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
}

Thank you for your help !

Post your code after reading Read this before posting a programming question and follow the advice given about posting code

Added the code - sorry about that.

It sounds like the board is resetting
Add these 2 lines to setup()

Serial.begin(9600);
Serial.println("Starting up");

Open the Serial monitor and make sure that the baud rate is set to 9600
What do you see in the Serial monitor ?

I’d be guessing that some point, the processor restarts for some reason, and the quick blink is the bootloader prompt.

Edit : AWOL, SNAP!

It may be worth sketching how your circuit is wired as well. because software and hardware can cause restarts.

Thanks - but like i mentioned - i have an external battery bank i use to charge my phone, and when i power the board with that, this doesn't happen at all - only while it's connected to the USB port of my pc, which is why i suspect that as the cause....I even tried a different USB port - same thing.

Not a big deal, but i'd like to figure out why it's doing that.

I'm not home now - but i will try the code suggested by UKHeliBob in the setup loop later this evening if i get a chance.

With regards to the sketch - it is wired exactly like this :

Thanks

So Bob,

I added the code as suggested, and here's the thing:

I saw the "starting up" message pop up in the terminal, but this is the weird part - with the terminal window open , the message never popped up again ( only once ), so does that mean it doesn't reboot ?

While the terminal window is open, multiple short blinks doesn't appear to happen after a few iterations of the loop function, but as soon as i close the terminal window, it happens...

I have read somewhere that it might be a "noisy" usb connection causing the board to reset like this, but like i mentioned - i tried all the USB ports and they all do the same thing.

I just found this interesting, and i still don't know why it happens...

So, if the USB is never connected to the PC after uploading the program, and you power the board from the power bank (USB or other), the LEDs keep on blinking as they should?
If not, can we see how it’s wired up... a photo AND drawn the way you think it’s wired.

lastchancename:
So, if the USB is never connected to the PC after uploading the program, and you power the board from the power bank (USB or other), the LEDs keep on blinking as they should?
If not, can we see how it’s wired up... a photo AND drawn the way you think it’s wired.

Correct... if not plugged into the USB - only battery powered - works 100% as it should. It does work on USB too, but it may complete like 5 or 6 "normal" loops, and then the LED blinks about 3 or 4 times rapidly before continuing with the usual 1 second on/off loop for another 4 or 5 iterations, and then it all repeats itself over and over...

So to give u a graphic illustration see the dots below where a dot is the ON state and a gap is the OFF state...

. . . . . ... . . . . ... . . . .

etc etc etc

I can't show screenshots on this forum... but the circuit is identical to this :

You can show screenshots, but generally they’re frowned upon.
Your diagram is very simple, but it’s curious why it might fail...
I suspect it may be a problem with grounding, or maybe decoupling...
I dint see any caps in your diagram

Hi

Yes - i’m basically following the first tutorial of the sparkfun inventors kit and doing it exactly as instructed. I’m new - so just learning the basics first.

I have already progressed a bit in the meantime and discovered millis() instead of delay() ! :wink: I just don’t know what the deal is with the 50 day thing and how that will affect millis() if you want to run a program indefinitely…

Thanks for the help thus far though…any tips/hints are greatly appreciated !

I just don't know what the deal is with the 50 day thing and how that will affect millis() if you want to run a program indefinitely

See Using millis() for timing. A beginners guide

I just don't know what the deal is with the 50 day thing . . .

Read this:

http://www.gammon.com.au/forum/?id=12127

larryd:
Read this:

Gammon Forum : Electronics : Microprocessors : millis() overflow ... a bad thing?

Yes - thanks - i have since read up on it, and understand why its not a problem if you use a "period" instead of a specific "time" from the current....

So we are all good

I have since taken a tangent on the first tutorial - and made a double LED with alternating timings using millis instead of delay. Simulation here :

Web Page expired...

You may not be surprised that - like screenshots, the experienced devs on here are not big fans of Fritzing, TinkerCad and similar entry-level tools.!

They are playthings, and often ambiguous when we’re trying to isolate and rectify subtle problems.

Good luck with your project.

Oh ok - I didnt know that. I’ll keep that in mind…

Thanks