Seems plausible. No adjustment in code will compensate for an inadequate power supply.
Time to post a schematic of your project. Hand drawn is often better than what you'll come up with if you have to struggle with a real schematic drawing program. Please don't use Fritzing to do this. Pencil and paper...
a7