Arduino UNO problem with programing relays

Any ideas?

This is my code.

int kanalas1 = 0;
int kanalas2 = 1;
int kanalas3 = 2;
int kanalas4 = 3;
int kanalas5 = 4;
int kanalas6 = 5;
int kanalas7 = 6;
int kanalas8 = 7;
int kanalas9 = 8;
int kanalas10 = 9;
int kanalas11 = 10;
int kanalas12 = 11;
int kanalas13 = 12;
int kanalas14 = 13;

unsigned int timer1 = 50;
unsigned int timer2 = 500;
unsigned int timer3 = 200;

int x;
int y;
int z;

int start;
int end;
int time;




void setup()
{
  pinMode(kanalas1, OUTPUT);
  pinMode(kanalas2, OUTPUT);
  pinMode(kanalas3, OUTPUT);
  pinMode(kanalas4, OUTPUT);
  pinMode(kanalas5, OUTPUT);
  pinMode(kanalas6, OUTPUT);
  pinMode(kanalas7, OUTPUT);
  pinMode(kanalas8, OUTPUT);
  pinMode(kanalas9, OUTPUT);
  pinMode(kanalas10, OUTPUT);
  pinMode(kanalas11, OUTPUT);
  pinMode(kanalas12, OUTPUT);
  pinMode(kanalas13, OUTPUT);
  pinMode(kanalas14, OUTPUT);

  /*
  digitalWrite(kanalas1,LOW);
  digitalWrite(kanalas2,LOW);
  digitalWrite(kanalas3,LOW);
  digitalWrite(kanalas4,LOW);
  digitalWrite(kanalas5,LOW);
  digitalWrite(kanalas6,LOW);
  digitalWrite(kanalas7,LOW);
  digitalWrite(kanalas8,LOW);
  digitalWrite(kanalas9,LOW);
  digitalWrite(kanalas10,LOW);
  digitalWrite(kanalas11,LOW);
  digitalWrite(kanalas12,LOW);
  digitalWrite(kanalas13,LOW);
  digitalWrite(kanalas14,LOW);



  Serial.begin(5000);
  delay(5000);
  */
}

void loop()
{
  start = millis();
  
  for ( int x = 0; x < 5; x++ )
    {
      digitalWrite(kanalas1, HIGH);
      digitalWrite(kanalas2, HIGH);
      delay(timer1);
      digitalWrite(kanalas1, LOW);
      digitalWrite(kanalas2, LOW);
      
      digitalWrite(kanalas3, HIGH);
      digitalWrite(kanalas4, HIGH);
      delay(timer1);
      digitalWrite(kanalas3, LOW);
      digitalWrite(kanalas4, LOW);
      
      digitalWrite(kanalas5, HIGH);
      digitalWrite(kanalas6, HIGH);
      delay(timer1);
      digitalWrite(kanalas5, LOW);
      digitalWrite(kanalas6, LOW);
      
      digitalWrite(kanalas7, HIGH);
      digitalWrite(kanalas8, HIGH);
      delay(timer1);
      digitalWrite(kanalas7, LOW);
      digitalWrite(kanalas8, LOW);
      
      digitalWrite(kanalas9, HIGH);
      digitalWrite(kanalas10, HIGH);
      delay(timer1);
      digitalWrite(kanalas9, LOW);
      digitalWrite(kanalas10, LOW);
      
      digitalWrite(kanalas11, HIGH);
      digitalWrite(kanalas12, HIGH);
      delay(timer1);
      digitalWrite(kanalas11, LOW);
      digitalWrite(kanalas12, LOW);
      
      digitalWrite(kanalas13, HIGH);
      digitalWrite(kanalas14, HIGH);
      delay(timer1);
      digitalWrite(kanalas13, LOW);
      digitalWrite(kanalas14, LOW);
      delay(timer2);
    }
    
    for ( int x = 0; x < 5; x++ )
    {
      digitalWrite(kanalas1, HIGH);
      delay(timer1);
      digitalWrite(kanalas1, LOW);
      delay(timer1);
      digitalWrite(kanalas2, HIGH);
      delay(timer1);
      digitalWrite(kanalas2, LOW);
      delay(timer1);
      digitalWrite(kanalas3, HIGH);
      delay(timer1);
      digitalWrite(kanalas3, LOW);
      delay(timer1);
      digitalWrite(kanalas4, HIGH);
      delay(timer1);
      digitalWrite(kanalas4, LOW);
      delay(timer1);
      digitalWrite(kanalas5, HIGH);
      delay(timer1);
      digitalWrite(kanalas5, LOW);
      delay(timer1);
      digitalWrite(kanalas6, HIGH);
      delay(timer1);
      digitalWrite(kanalas6, LOW);
      delay(timer1);
      digitalWrite(kanalas7, HIGH);
      delay(timer1);
      digitalWrite(kanalas7, LOW);
      delay(timer1);
      digitalWrite(kanalas8, HIGH);
      delay(timer1);
      digitalWrite(kanalas8, LOW);
      delay(timer1);
      digitalWrite(kanalas9, HIGH);
      delay(timer1);
      digitalWrite(kanalas9, LOW);
      delay(timer1);
      digitalWrite(kanalas10, HIGH);
      delay(timer1);
      digitalWrite(kanalas10, LOW);
      delay(timer1);
      digitalWrite(kanalas11, HIGH);
      delay(timer1);
      digitalWrite(kanalas11, LOW);
      delay(timer1);
      digitalWrite(kanalas12, HIGH);
      delay(timer1);
      digitalWrite(kanalas12, LOW);
      delay(timer1);
      digitalWrite(kanalas13, HIGH);
      delay(timer1);
      digitalWrite(kanalas13, LOW);
      delay(timer1);
      digitalWrite(kanalas14, HIGH);
      delay(timer1);
      digitalWrite(kanalas14, LOW);
      delay(timer1);
      digitalWrite(kanalas14, HIGH);
      delay(timer1);
      digitalWrite(kanalas14, LOW);
      delay(timer1);
      digitalWrite(kanalas13, HIGH);
      delay(timer1);
      digitalWrite(kanalas13, LOW);
      delay(timer1);
      digitalWrite(kanalas12, HIGH);
      delay(timer1);
      digitalWrite(kanalas12, LOW);
      delay(timer1);
      digitalWrite(kanalas11, HIGH);
      delay(timer1);
      digitalWrite(kanalas11, LOW);
      delay(timer1);
      digitalWrite(kanalas10, HIGH);
      delay(timer1);
      digitalWrite(kanalas10, LOW);
      delay(timer1);
      digitalWrite(kanalas9, HIGH);
      delay(timer1);
      digitalWrite(kanalas9, LOW);
      delay(timer1);
      digitalWrite(kanalas8, HIGH);
      delay(timer1);
      digitalWrite(kanalas8, LOW);
      delay(timer1);
      digitalWrite(kanalas7, HIGH);
      delay(timer1);
      digitalWrite(kanalas7, LOW);
      delay(timer1);
      digitalWrite(kanalas6, HIGH);
      delay(timer1);
      digitalWrite(kanalas6, LOW);
      delay(timer1);
      digitalWrite(kanalas5, HIGH);
      delay(timer1);
      digitalWrite(kanalas5, LOW);
      delay(timer1);
      digitalWrite(kanalas4, HIGH);
      delay(timer1);
      digitalWrite(kanalas4, LOW);
      delay(timer1);
      digitalWrite(kanalas3, HIGH);
      delay(timer1);
      digitalWrite(kanalas3, LOW);
      delay(timer1);
      digitalWrite(kanalas2, HIGH);
      delay(timer1);
      digitalWrite(kanalas2, LOW);
      delay(timer1);
      digitalWrite(kanalas1, HIGH);
      delay(timer1);
      digitalWrite(kanalas1, LOW);
      delay(timer2);
    }

    for ( int x = 0; x < 5; x++ )
    {
      digitalWrite(kanalas1, HIGH);
      digitalWrite(kanalas8, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas2, HIGH);
      digitalWrite(kanalas9, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas3, HIGH);
      digitalWrite(kanalas10, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas4, HIGH);
      digitalWrite(kanalas11, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas5, HIGH);
      digitalWrite(kanalas12, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas6, HIGH);
      digitalWrite(kanalas13, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas7, HIGH);
      digitalWrite(kanalas14, HIGH);
      delay(timer1);
      
      digitalWrite(kanalas1, LOW);
      digitalWrite(kanalas8, LOW);
      delay(timer1);
      
      digitalWrite(kanalas2, LOW);
      digitalWrite(kanalas9, LOW);
      delay(timer1);
      
      digitalWrite(kanalas3, LOW);
      digitalWrite(kanalas10, LOW);
      delay(timer1);
      
      digitalWrite(kanalas4, LOW);
      digitalWrite(kanalas11, LOW);
      delay(timer1);
      
      digitalWrite(kanalas5, LOW);
      digitalWrite(kanalas12, LOW);
      delay(timer1);
      
      digitalWrite(kanalas6, LOW);
      digitalWrite(kanalas13, LOW);
      delay(timer1);
      
      digitalWrite(kanalas7, LOW);
      digitalWrite(kanalas14, LOW);
      delay(timer2);
    }
 
  end = millis();
  time = end - start;
  Serial.println(time);
}

When i create more program for LED lights than this problem shows faster but when i use first two programs for LED lights then need to wait more time when shows this problem. When Arduino is runing hes working correct one or two cycles with my code. But when should begin next part of code (all time different line of code) flashing two first lights and one last (same like i push reset button on Arduino but i didn't push it). Then everything starts over. After some cycles this problem shows again...

This is my components

"Any ideas?"

Yeah! One big one! Read the post entitled "How to use this forum - please read."

And, I've got a second idea as well. Don't expect much help when posting like this. You refer to "this problem" but all I see is a bunch of flashing lights. Without knowing how they were supposed to Flash, I don't see a Problem at all.

Sorry, I here firs time ..

When Arduino is runing hes working correct one or two cycles with my code. But when should begin next part of code flashing two first lights and one last. Then everything starts over. After some cycles this problem shows again...

Sorry, I here firs time ..

Have you read read this before posting a programming question and noted the advice that it contains ?

Not all because I work with it second day and I need finish it today. If i should have more time I try it to do mysefl but now I need help ..

please understand me!

but now I need help ..

There would be more chance of getting help if you posted your code here and described what the program is supposed to do and what it actually does. If there are inputs to the circuit then describe how they are wired and similarly with outputs.

Connection with Arduino, Relays and LED I think is't okay (I used all digital pins). I think problem in code because when i changing delays program working more time. Maybe I need reset Arduino memory or something like that? I try reset millis each period but it's didn't help me..

int kanalas1 = 0;
int kanalas2 = 1;
...
  Serial.println(time);

Pins 0 and 1 are used by the system for Serial.println(). Whenever you do Serial.println() they will be toggled very quickly, and end up in a state you may not want.

int kanalas14 = 13;

Also, pin 13 is connected to the on-board LED, and it blinks when the Arduino is reset.

Jimmus:

int kanalas14 = 13;

Also, pin 13 is connected to the on-board LED, and it blinks when the Arduino is reset.

This means I can't use 0, 1 and 13 pins? If I clean "Serial.println(time);" line I can use 0 and 1 pins? And what about 13 pin? Can I use it?

I use this mini project on water tower. Now I have 28 LED garlands (one garland length about ~30 meters). I need all 14 digital outputs control all garlands (two in one channel this mean 14 channels).

You do need to remove the Serial.println(); statement if you don't want those lights doing weird stuff.

When you first power on the Arduino, or when you do a reset, it will blink pin 13 briefly. After that it should be OK.

As long as it's just powering lights, and not... you know... setting off an alarm or opening a valve or arming a bomb or something, you'll be fine.

Jimmus:
You do need to remove the Serial.println(); statement if you don't want those lights doing weird stuff.

When you first power on the Arduino, or when you do a reset, it will blink pin 13 briefly. After that it should be OK.

As long as it's just powering lights, and not... you know... setting off an alarm or opening a valve or arming a bomb or something, you'll be fine.

I tried run program without 0, 1 and 13 pins in code (also disconected from Arduino) and same problem still killing me .. Also I tried delete "Serial.println();" nothing chanched ..

How are you powering the relay boards? It looks like maybe having them all on at the same time is overloading the power supply and causing a low voltage reset of the Arduino. Or maybe turning them all off at the same time is causing an EMF spike. You might need a snubber of some kind.

It is hard to tell exactly what is happening because the gif you posted repeats, and it's hard to tell when it starts and ends.

You do know you can also use pins A0-A5 as digital output pins, right?

How are you powering the relay boards?

From Arduino 5V supply.

It is hard to tell exactly what is happening because the gif you posted repeats, and it's hard to tell when it starts and ends.

This is all video. I hope that will help more to understand whats happens.

You do know you can also use pins A0-A5 as digital output pins, right?

Now I know. Thanks!

That might be a problem. There's a limit to how much current the Aruino board can supply. Those relays pull a decent amount of current to keep the electromagnet going. If each of those relays pulls 70 millamps when it's activated, you are probably pushing the limit. Do you have another power supply you could offload the relays onto?

How many volts are you supplying into the Arduino? Is the voltage regulator getting hot?

Have you considered using solid state circuits instead of relays? They sound really cool and all when they're clicking away, but it could get annoying pretty fast. And they have a limited number of cycles, and they use a lot of current. I bet some MOSFETs would work just as well for LEDs. What do you plan to be switching for the final project?

Do you have another power supply you could offload the relays onto?

I tried use 6V 500mA power supply but it's not enough (relay LEDs didn't light good).

How many volts are you supplying into the Arduino? Is the voltage regulator getting hot?

Just for Arduino supplying I use 12V DC 1,2A power supply. He's cold.

Have you considered using solid state circuits instead of relays? They sound really cool and all when they're clicking away, but it could get annoying pretty fast. And they have a limited number of cycles, and they use a lot of current. I bet some MOSFETs would work just as well for LEDs. What do you plan to be switching for the final project?

I need control high voltage power supplies.

So the way I understand it, the Arduino has an LDO voltage regulator on-board. It's the black chip right next to the barrel jack where you plug in your 12 volts. Its function is to convert the 12 volts to 5 volts the Arduino needs, and that you plugged everything else into. The problem is that it does this by converting everything above 5 volts into heat. That means you're getting 5 volts to power your electronics and 7 volts gets converted into heat. This is not usually a problem if you don't use very much current, because the power (watts) that gets converted into heat is volts * amps. The Arduino generally runs less than 100 millamps, so 7 volts * .1 amps = .7 watts. However, if you're using 14 relays, and each one is pulling 70 milliamps, that's 980 milliamps. 7 volts * .980 amps = 6.86 watts! That little black chip can't dissipate that much heat for very long. It will get very hot, and then it will shut down for a short time. You could check and see if this is the problem by touching it with your finger if you don't mind getting a blister.

You could try putting a heat sink on it, but it would only delay the problem. You could try supplying less than 12 volts to the barrel jack. 7.5 woud be much better. But again, it would probably only delay the problem. You really need to power the relay boards with a separate power supply. Something more than 500 mA. Like 1.5 Amps.

Jimmus:
So the way I understand it, the Arduino has an LDO voltage regulator on-board. It's the black chip right next to the barrel jack where you plug in your 12 volts. It's function is to convert the 12 volts to 5 volts the Arduino needs, and that you plugged everything else into. The problem is that it does this by converting everything above 5 volts into heat. That means you're getting 5 volts to power your electronics and 7 volts gets converted into heat. This is not usually a problem if you don't use very much current, because the power (watts) that gets converted into heat is volts * amps. The Arduino generally runs less than 100 millamps, so 7 volts * .1 amps = .7 watts. However, if you're using 14 relays, and each one is pulling 70 milliamps, that's 980 milliamps. 7 volts * .980 amps = 6.86 watts! That little black chip can't dissipate that much heat for very long. It will get very hot, and then it will shut down for a short time. You could check and see if this is the problem by touching it with your finger if you don't mind getting a blister.

You could try putting a heat sink on it, but it would only delay the problem. You could try supplying less than 12 volts to the barrel jack. 7.5 woud be much better. But again, it would probably only delay the problem. You really need to power the relay boards with a separate power supply. Something more than 500 mA. Like 1.5 Amps.

Thank you very much! I will try this when I find more powerful power supply and I'll be sure to let you know if the problem will be solved.

When I use separate power supply (5V 10A) I have problem with relays controling. When I needed turn on all relays (HIGH) not all relays is on (I can heard the sound when almost relay turns on but she didn't, light on relay LED also lighting blurry like not enaugh power). When need turn on a few relays then all it's okay. For Arduino powering I use 12V 1,2A power supply.

Also I tried supply all relays board with Arduino 5V pin. Then all relays working correct, but after some time I have same problem which I have before that.

Problem SLOVED. Just needed connect Arduino GND with relays GND. Special thanks for Jimmus!