Arduino UNO uses old code when unplugged from pc

Hi, I'm new to coding and I have somewhat of a very basic understanding of c++. Currently, I'm trying to learn about Arduino but I'm having a little bit of a problem.

You see, when I finished making the contraption for the Arduino (self-driving car kit), I had a code template that I uploaded to the Arduino for testing. It turns out the code had a few flaws on it, so after some tweaking, I finally found out how to fix it. So, I uploaded the new code
The problem here lies in the fact that, when I plugged in the Arduino to my laptop, the code worked just as I intended. But, when I unplugged the Arduino, it went back into using the old code.
I tried resetting the Arduino (both by uploading an empty code before re-uploading the new one, and by pushing the reset button on the board itself), and it somehow still remembered and used the old code. how do I fix this problem?

The Arduino (and you dont say which one) will only have one copy of your Sketch loaded.

The one it runs when powered is the last one you uploaded.

Find out why your new code behaves like the old code after disconnecting from USB. What's the power supply, how much current drawn by external devices from the 5V line?

USB can provide 0.5A @ 5V, other supplies much less.

well, yeah, that's the gist of it, but the last Sketch I uploaded is the new version, which doesn't run on it (for some reason)

You should stay away from boards that have their own spirit. Some woodoo exorcism may be required to return you and your devices into real life.

Tried it. Didn't work. Summoned a friendly demon.

I would, but I actually have no clue

the whole thing (motor driver, arduino, etc) is powered by 4 AA batteries

If the "new" code runs when powered by USB, then that code is loaded on your Arduino. Prove it to yourself with some serial prints in setup that provide a version number.

Then, "all" you have to do is figure out why the project acts up with a different power supply. How are the AA batteries attached?

they are attached to a 12volt module and gnd module on the motor driver. I attached the Arduino and motor driver via 5v and gnd

Please draw a circuit diagram of your power lines and devices. It's only confusing if you say to connect to a gnd "module" - do you mean gnd connector?

You also can not really power 12V and 5V devices from 4 AA batteries.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.