Arduino strange behavior with dc motors

Can you explain in more detail? I'm sorry but I'm newbie(
Here is my scheme:

where I need to add capacitors?
Thanks.