Viewing/modifying a sketch that is currently loaded

i am semi new to Arduino, my question is this. Can i view a sketch that is programmed into my Arduino? Can the sketch be uploaded from the Arduino to my PC? I often forget what is programmed into my Arduino (I have quite a few) and it would be nice to be able to see what code is programmed.

You can extract the compiled binary from the Arduino, but even if you then ran it through a disassembler it would make no sense to you. You can’t turn it back into the sketch you wrote.

One neat trick for the future is to include some details in your code that will be printed to the serial monitor to give you some information.
This could be straightforward text (but you’d need to remember to update it) or you can use C++ built-in ‘macros’ like these:

__FILE__     The date the file was compiled
__TIME__     The time the file was compiled
__FILE__     The filename of the .ino file


1 Like

when you upload the code from pc to arduino, the compiler takes your human readable code and transforms to machine code. microcontrollers can’t understand the human readable format, only machine code, which in turn is not interpretable for humans. the compiler acts as a translator between the two languages but this translation is one way only.

the machine code looks like this:
8020 78
8021 A9 80
8023 8D 15 03
8026 A9 2D
8028 8D 14 03
802B 58
802C 60
802D EE 20 D0
8030 4C 31 EA

so, the best way is what @PeteKnight recommends, always save a copy of your “human readable code” - the sketch, and put a short info in the setup function. i use like this:

void printVersionInfo()
  Serial.println(F("company name"));
  Serial.print("IDE v");
  Serial.print("FW master v");
  Serial.println(__FILE__ " compiled @ " __DATE__ ", " __TIME__);