This question already has an answer here:
I have a simple working circuit to control a DC motor with an Arduino as indicated in the Arduino examples. For instance,
The circuit uses 3 AA batteries and has a diode. When I changed the arduino to an Attiny85, the motor switches between on and off randomly. Looking in the internet, I found that this may be happening because the Attiny cannot handle the amperage but also because when the motor is on it reduces the amperage to the Attiny.
I presume it is the second option because the circuit works well when I use an adaptor instead of the batteries. I presume replacing the diode for a capacitator could prevent the reduction of the amperage to the Attiny. But I wonder if you know what is the best solution to this problem?