DC motor causing project to work unexpectedly
Looks like your circuit is missing a decoupling capacitor. If you have a motor in the circuit, you will probably trigger undervoltage lockout/brownout protection followed by restart.

The normal decoupling capacitor is a 100 nF disc capacitor for though-hole and MLCC for SMD. Place it as close to the IC as possible. Ground and Vcc planes are important too here.

Image taken from Connecting a decoupling capacitor straight to the ground plane