Motor fly back or something else?

My Atmega controls my motor via 2 double throw relays, to give me forward and reverse. The whole thing is battery powered, no voltage regulators. (6) C batteries. The atmega runs on 4.5 volt, the motor on 9 volt. When the motor cuts on and off sometimes it resets my Atmega. I have a fly back diode on the relays’ coil, but that is all. Do I need it on the motor, too? I put a 0.1 uF cap across the motor terminals like someone suggests to help noise, and now my Atmega resets every time the motor turns on. I put a 1000uF cap across gnd and 9 volts, and that fixed my issue. I’m just wondering if that’s the appropriate fix? Would the motor diodes fix this problem, or would I still need a large cap in the picture?

image.jpg

Can you enlarge that image so the text is legible?

If you are reversing the voltage across the motor do not put a diode across the motor terminals.
Consider a MOV.
I see no reason that the motor power supply ground has to be connected to the Arduino ground "if it is".

Edit:
On second thought a MOV really should not be used in a constant transient condition like a motor.

Sorry about the poor photo. I'll upload a better one when I get home. The grounds are connected because they are the same. I have two 3 D cell battery packs wired in series. 4.5 + 4.5 volts. The Arduino is powered off one, the motor off both for 9 volts. I wouldn't put a diode across the terminals, but rather 4 of them, 2 tying each motor terminal to gnd and 9 volts, to take care of fly back voltage, but I'm not sure that's the problem. Fly back should be affecting the 4.5 volt should it? It seems more like when the motor starts it drops the voltage for a split second. I didn't put any polarized caps in the system like I do when using a voltage regulator, I thought battery voltage would be constant, but I wonder if it's dropping out sometime when the little motor starts.

Here a PDF file of my schematic. I can't seem to get a photo uploaded tonight.

Add something like 47uF electrolytic decoupling close to the relay switching transistors -
the current pulses from turning on/off the relays is probably triggering reset. The
ATmega should have 0.1uF caps on each supply pin, not just one of them.

Any wiring connected to the reset pin needs to be routed away from all the high-current
paths to the relays and motors, or perhaps change the 10k pull-up on it to 1k.

MarkT:
Add something like 47uF electrolytic decoupling close to the relay switching transistors -
the current pulses from turning on/off the relays is probably triggering reset. The
ATmega should have 0.1uF caps on each supply pin, not just one of them.

Any wiring connected to the reset pin needs to be routed away from all the high-current
paths to the relays and motors, or perhaps change the 10k pull-up on it to 1k.

I just discovered I don’t even have pin 6 (Vcc) of the Atmega328P-AU connected to anything! That could be causing a problem? Pins 4 & 6 are Vcc, pins 3 & 5 are GND. One cap in there would be as close to one Vcc as the other, but maybe that’s what you meant-that you saw I didn’t even have the one pin connected? What about pins 18 & 21? They are AVcc & AGnd. I have them tied to Vcc & Gnd, respectively. Should I add a 0.1uF cap by them?

The 47uF cap for the 2N3904 transistors --I’m not sure where to put them. Check out my picture, They are C7 & C8. I’m guessing C7 is the right way to do it, but I don’t understand transistors well enough to visualize how they work.

The 47uF cap for the 2N3904 transistors – does it just go from 5V to Gnd, near the 2N3904?