Weird arduino behavior solved by reset

I’m working on a walking robot project and using a pro micro board (5V). The project has several components including a DC motor, DC motor driver, bluetooth module, servos and encoders.

The weird behavior is as follows:

When I first power up the arduino the servos will start “clicking” and after 2-3 seconds (I assume after “setup()”) the DC motor will start going crazy.

However, if I reset the arduino (I added a button for convenience) right after power-up it will do the setup and start looping without a problem.

To sum up: complex project with quite a bit of code, goes crazy on power-up unless I hit reset within 1-2 seconds, then it runs fine.

Any ideas will be highly appreciated!

Your Arduino is crashing and not properly running its startup code on power up. Probably because your motors are causing power initialization problems. Try either delaying the Arduino startup until power stabilizes or get a beefier power supply.

I’m not sure that the problem is really the power supply. This happens with a DC power supply set to 11.1V and with a 3S LiPo battery (also ~11.1V).

I already tried adding a delay at the start of setup() and that didn’t help. Any other suggestions to delay startup?

Adding code to the Arduino won’t help. The problem is that the arduino isn’t executing any code properly until you manually reset it. You need a hardware delay to keep the arduino from starting up. Activating the brown-out reset on the AVR may also help, but I don’t think the IDE lets you set fuses.

If it really is a power issue then the servos are probably to blame. I’ve built projects with the same bluetooth module, dc motor and dc motor driver before without encountering this issue.

I guess for now I’ll stick to manually resetting it until I find a better solution.

One more thing: make sure you are using heavy enough wire gauge to handle the current for the motors & servos. I recently ran into a similar problem that turned out to be that my temporary jumper wires were introducing enough resistance to pull the power supply down and cause erratic behavior when a servo turned on.