Simple LED blinking loop gets interrupted for some reason

Hi all,

Maybe your experience can help me with something realy odd. I try to create led(s) that blink in an infinite loop. But for some reason the led loop stops and kind of starts again from "beginning".
Can you help me to solve this loop failure?

I have recorded the behavior:

Here's the code:
int redPin = 2; // Red LED connected to digital pin 12
int greenPin = 3; // Green LED connected to digital pin 11

void setup() // run once, when the sketch starts
{
pinMode(redPin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digital pin as output
}

void loop() // run over and over again
{
digitalWrite(redPin, HIGH); // sets the Red LED on
digitalWrite(greenPin, HIGH); // sets the Green LED on
delay(500); // waits for half a second
digitalWrite(redPin, LOW); // sets the Red LED off
digitalWrite(greenPin, LOW); // sets the Green LED off
delay(500); // waits for half a second
}

It does not matter how many leds i try to blink, Arduino always gets interrupted by something... :frowning:
I am using newest Arduino SW and an old Duemilanove board.

Thanks for your help in Advance.

Br,
Walter

I'm going to guess that your Arduino is being reset.
Put a serial print in setup, and see if it gets printed repeatedly.

Do you have something else wired with either pin2 or pin3?
Repeat your test with some other pins, say 4 and 5.

If the problem still exists, replace the arduino and see what happens then.
Does the reset come always after a "repeatable" time or without pattern?
If so, then check your power supply (USB cable from PC?) and repeat the test with a DC adapter.

Wow, I didn't expect such fast help from forum members :slight_smile:
Thanks.

The serial.print trick is a good advice. I added it to the code. It seems that the code/LEDs started to work immediately after my posting. I strongly believe that I have some kind of loose connection which resets the board :confused:

Br,
Walter

walter_v:
Maybe your experience can help me with something realy odd. I try to create led(s) that blink in an infinite loop. But for some reason the led loop stops and kind of starts again from "beginning".
Can you help me to solve this loop failure?

What 'failure'? The program does exactly(!) what you have programmed.

Two times delay(500); in the loop means that the loop() roughly restarts after one second.

So what do you expect the code to do?

Add together all the delay() used within loop and you will know when loop() will restart!

@jurs: Yeah, but the loop should not be interrupted like in the video. I.e. a constant running blink...

Hi,
Is the problem still there?
What are the LED current limit resistor values?

Tom.. :slight_smile:

walter_v:
@jurs: Yeah, but the loop should not be interrupted like in the video. I.e. a constant running blink...

Yeah, but also the comments in the code seem to be wrong.

int redPin = 2;                  // Red LED connected to digital pin 12
int greenPin = 3;                // Green LED connected to digital pin 11

Perhhaps much more than the comments (or pin numbers) is wrong, I don't know, insufficient information.
Besides of that I don't see about current limiting resistors and circuit schematics diagram.