I want to control 4 DC motors with Atmega328p. My circuit design is below. When connected to motors, it doesn't work as expected. (Sometimes it works randomly, mostly fails after first DC motor start.)
When not connected to motors, I checked voltages as expected and sketch works fine.
Motors draw 150-300 ma and they have to spin consecutively each 10 seconds with one second intervals according to sketch. I checked diodes, transistors, resistors, chip and sketch (no fault). I know I can use mosfets but I want to learn the fault at circuit design.
What is the 5V power supply? What is the current capability of the 5V supply?
What is the stall current of the motors? Stall current can be many times (10+) the running current. The motor will draw stall current, briefly, every time that it starts. Until you know the stall current you cannot, intelligently, choose a driver. The stall current should be listed on the motor data sheet. If not, one can estimate the stall current. Measure the motor winding resistance. Take several measurements rotating the motor a bit between readings. Use the lowest reading in the calculation. The estimated stall current is the motor supply voltage divided by the measured resistance.
Power supply is a converted PSU which can give up to 8 amps. Also I tried with some Lion batteries.
Stall resistance is 8-9 ohm. 5/8=0.625 A. I dropped resistance to 130 ohm in any case. (Pulls 38 mA from pin) Now base current ratio is 1/16 (38/625)
Nothing changed. It works nonsense. Once, first motor started and run 5-6 seconds (it should 15 sec) then failed. Once 3 motors started at the same time and never stopped. Once, first motor started 2 sec and then failed.
I think something effecting chip??
I see a crystal and 2 caps, which are almost certainly unnecessary for your project, but I don't see any bypass caps for the atmega. There should be ideally 2 of these on the 2 5V pins, 0.1uF ceramic, close to the chip.
I would also try some suppression caps on the motors. Again, 0.1uF ceramic should be ok, ideally across the motor terminals themselves.
Your 10uF power smoothing cap seems inadequate, try replacing with 470uF or 1000uF.
A schematic showing the entire circuit would help clear up any incorrect assumptions I've made looking at one side of your circuit board.
Hi again, I attached schematic. (There is also a 0.1 uF Cap parallel to 1000uF at between VCC and ground, I forget to draw) .
Sketch makes digital pins (9-12) high and then low for 10 seconds consecutively. There is a 1 sec delay between them. But it doesn't. It runs in a different way every time it started. I think there is an interference effecting chip.
When I disconnect motors (with diodes and caps) I measured voltages consecutively as expected according to sketch.
Still it doesn't works as expected. Would you please review?
It appears you followed my suggestions. I'm not sure what to suggest to try next.
Do you have a USB-serial adapter that you can hook up to the Tx/Rx pins on the atmega? You could add some Serial.println() commands to help you use serial monitor to debug what is happening when the motors are attached and the circuit is misbehaving. You could put Serial.println("Start of setup()") and so on at the start & end of setup() and loop() and each time a motor pin is set HIGH or LOW.
If you don't have a USB-serial adapter, perhaps add one or more small leds to unused atmega pins and change the code to flash them in combinations to indicate what part of the code is being executed, similar to the Serial.println() idea.