Arduino Uno loop restarts while busy in the loop

Hey Guys,

I'm quite new to the Arduino Board and programming on Microcontrollers.
I wrote a little script to control a little trafficlight circuit. But while not having finished the loop the current glowing LED shuts off, the "L"-Led flashs a few times, then turns back on and the loop of my script restarts.
Thanks for your help guys :slight_smile:
Greets

I think you know we would need to see your code and a picture of your circuit in order to help you.

#define DELAY1 10000
#define DELAY2 2000
#define DELAY3 3000
int ledPinRed = 7;
int ledPinYellow= 6;
int ledPinGreen= 5;
void setup(){
  pinMode(ledPinRed, OUTPUT);
  pinMode(ledPinYellow, OUTPUT);
  pinMode(ledPinGreen, OUTPUT);
}
void loop()
{
  digitalWrite(ledPinRed, LOW);  //GreenPhase
  digitalWrite(ledPinYellow, LOW);
  digitalWrite(ledPinGreen, HIGH);
  delay(DELAY1);
    digitalWrite(ledPinYellow,HIGH);  //YellowPhase
    digitalWrite(ledPinGreen,LOW);
  delay(DELAY3);
    digitalWrite(ledPinRed, HIGH);  //RedPhase
    digitalWrite(ledPinYellow,LOW);
  delay(DELAY1);
    digitalWrite(ledPinYellow, HIGH ); //RedYellowphase
  delay(DELAY2);
}

Here is my code

And in the attachment is a scematic of the circuit.
Just imagine the diode in the middle yellow and the other green

Your 'schematic' is obviously wrong (unless you have a magic yellow LED) so you ought to start by correcting that first.

Next make sure your actual circuit agrees with the corrected diagram.

Are you sure the resistors you are using are 220 ohm and that they are actually in series with your LEDs?

Do you really want to have more than one of the LEDs on at the same time? Typically you turn them all off before turning the next one on.

Don

No offence guys, but to clarify this.
I had the same problem with other circuits i built. So i guess the problem originates from the Board. And not by my project itself.
My project does what it'S supposed to. But it gets interrupted by the error i explained.
After some time the temporarily LED turns off without being implemented.
The Error imo seemed to be that the Board somehow resets / restarts itself after approx. 30 seconds.
I'm not looking for any error in the scematic(besides the ground i missplaced there.[and the colour of the LEDs i didn't find cause it was my first scetch with Fritzing]]) which is why i originally didn't post the code and the Circuit.
I hope this showed what i am having problems with.
Sincerely Tilo

I assume your Fritzing diagram is for guidance only. The first problem I see is that there is no 5v going to your breadboard.

The most likely cause of the board resetting is your circuit (excessive current causing a reset). Disconnect your stuff from the Arduino and then see if the board will operate without resetting. If it does work without resetting troubleshoot and correct your circuit. If it resets with nothing connected then the problem is with the board or power to the board. If you are using a 9v battery try using a 9v power supply.

I'm not looking for any error in the scematic

You should be looking for errors in all aspects of your setup. Lots of people have found that the source of their problem was in some part of the setup that they were sure was OK.

The most likely cause of the board resetting is your circuit (excessive current causing a reset).

Hence the question about the resistors.

If you are using a 9v battery try using a 9v power supply.

Good point. We shouldn't have to be asking questions that a photograph of the setup would clarify.

Don

Update:
As i plugged it back in today it works without getting interrupted.
I don't know what supposedly could've changed from yesterday.
Anyway thanks guys :).
I will try to figure out how this could've happened and keep you updated if you are interested.
Greets

You probably just had a bit of stray radio active fall out on you yesterday. If you've had a shower since, it's probably been washed off now.

Update 2:
It seems like the problem only comes up after the loop completed 3-4 turns after beeing plugged in
(so my preceding update was wrong).
I have made an video for you guys so you can hopefully tell me what i've wired / setup wrong.

Here a little explanation of the circuit:
I use the digital ports 7-5 as outputs and set their level HIGH to power the LEDs , which are in series with an 330 Ohm resistor so the current is about 15mA.
The board is powered through the USB interface, which should be able to provide the 30 mA which the board max. supplies when 2 LEDs are on.

Try powering it with a wall wart instead. I suspect it's a foible with your operating system powering down the usb port. Do you perchance, have Windows 8.1 on there?

I'm running windows 8 at the moment.
I'll try to switch operating systems and will give you the update if it runs without the interrupt.

EDIT:
I've switched to my Mac Partition and it works just fine now.
Thanks a lot for your help. I'll get myself an external power source now. :slight_smile:
Sincerely Tilo

Aren't there some utilities that scan the COM ports every so often, causing a reset?

So it wasn't the radio active fall out after all :slight_smile: