I have a program that turns on a couple of relays and then runs 3 RGB LEDs using PWM and for some reason it intermittently resets itself when it's trying to turn the things on, I have delays in between turning on each item so as not to overload the chip and yet it still resets itself, would diodes on the pins prevent the resets?
for some reason it intermittently resets itself when it's trying to turn the things on
It could be one or more of several issues depending on how you're driving the relays. If the actuating current for the relay is too large for the power supply, you may be getting a "voltage droop" that causes the reset. This can be remedied by using a heftier supply or by powering the relays with a separate supply (with common ground) and actuating them by pulling the other end of the coil low with an output pin.
Another possible cause is "back emf" (also called "flyback voltage" or "inductive kickback"). This occurs when you turn off the relay. The inductance of the relay coil tries to keep the current constant by generating a large reverse voltage. This kickback can reset the CPU or even damage it permanently. You can suppress the kickback by placing a diode across the relay coil with the cathode connected to the more positive terminal.
An alternate solution is to use a solid state relay (SSR). This type of relay has no inductive effects (because there is no coil) and they typically have a low actuating current. They are commonly available with DC switching voltage of 3 to 30 volts or so making them suitable for direct drive from a microcontroller. They come in two distinct types - one for switching AC loads and one for switching DC loads. Special versions of the AC type are available that switch the load at zero crossing; useful for handling large inductive loads.
I am using the separate supply for the relay, I'm going to try to place a diode across the coils of the relay I have the pin on the arduino going high which connects to the relay coils anode (if relays have anodes?) I'm not sure i understand what you mean about having the pin go low.
there are 4 states that a relay an be in, 2 on, 2 off.
Arduino---Relay---Common
LOW--- ---LOW ==> OFF
HIGH------LOW ==> ON
HIGH------HIGH ==> OFF
LOW--- ---HIGH ==> ON
The top 2 are the 'normal' way of doing it. The Arduino provides the power to the relay to switch it with the common going to ground.
The Arduino can only provide 50mA like this though, so if the relay draws more, the Arduino resets.
The last 2 the power comes from a common wire with the Arduino sinking the current to ground to drive it. It can tolerate a lot more power this way (about 200mA i think, though dont quote me on that) because it does not need to drive it. For reference I think most relays draw about 150mA when active.
You MUST put a diode across the coils though! a relay coil can act like a small Tasor when the relay turns off! Never a good thing to hook too the chip!!!
I'm not sure i understand what you mean about having the pin go low.
As described by Cynar, an output pin can either "source" (i.e. provide) current or it can "sink" current in order to drive an external device. When sourcing current, you make the output high to activate the external device. When sinking current, you make the output low to activate the external device.
Many engineers/developers prefer to make their outputs active low (sinking current) perhaps because that makes it somewhat easier to design the circuit so that it is inactive between powerup and the completion of the initialization. Also, as Cynar pointed out, microcontroller output pins are sometimes capable of sinking more current than they can source. You'll need to check the datasheet of the microcontroller to determine if that is the case with yours.