user37: I made a sketch, but then I lost it. However, I uploaded it to the Arduino before losing it. Is there any way I can get it back?

user76592: Download:
avrdude \
    -c <programmer type> \
    -P <connection port> \
    -b <override RS-232 baudrate> \
    -p <partno, AVR device> \
    -U <memtype>:r:file_name[:format]

Upload:
Use w (write) instead of r (read) for the -U option.
More details at manual - avrdude Option-Descriptions.

Example:
Download UNO v3 (ATmega328) flash ROM (bootloader) given port /dev/ttyACM0 as Intel HEX:
avrdude -c arduino -P /dev/ttyACM0 -b 115200 -p m328p -U flash:r:SaveFlash.hex:i


If used directly from from the arduino IDE archive also add:
-C path-to/arduino-V/hardware/tools/avr/etc/avrdude.conf


user8: You can download the hex dump of the file, but there is no easy way to get all the C++ code and comments. If you can understand assembly, you could recreate the program, but that would take a while. There are dissasemblers available for some devices, i don't know about arduino.

user6796: I think there is another way to do this, without extracting the code from the Arduino board. Remenber the date you create the sketch, and look for it in  C:\Users\User\AppData\Local\Temp\
(For example : C:\Users\User\AppData\Local\Temp\untitled4390292704786567977.tmp\sketch_jan19a ). You could find your unsaved code unless it was deleted by some "freeing space program".
Good luck! 

user10794: Unless your objective is to simply copy the identical code to another device, the simple answer is: no
As has been pointed out in other answers, you can turn the hex code on the device back into assembler code.
For example (once you have copied the code from the device back onto your disk):
avr-objdump -j .sec1 -d -m avr5 yourFileHere.hex

Run on one of the bootloader files I get these results (in part):
00007e00 <.sec1>:
    7e00:       11 24           eor     r1, r1
    7e02:       84 b7           in      r24, 0x34       ; 52
    7e04:       14 be           out     0x34, r1        ; 52
    7e06:       81 ff           sbrs    r24, 1
    7e08:       f0 d0           rcall   .+480           ;  0x7fea
    7e0a:       85 e0           ldi     r24, 0x05       ; 5
    7e0c:       80 93 81 00     sts     0x0081, r24
    7e10:       82 e0           ldi     r24, 0x02       ; 2
    7e12:       80 93 c0 00     sts     0x00C0, r24
    7e16:       88 e1           ldi     r24, 0x18       ; 24
    7e18:       80 93 c1 00     sts     0x00C1, r24
    7e1c:       86 e0           ldi     r24, 0x06       ; 6
    7e1e:       80 93 c2 00     sts     0x00C2, r24
    7e22:       80 e1           ldi     r24, 0x10       ; 16
    7e24:       80 93 c4 00     sts     0x00C4, r24
    7e28:       8e e0           ldi     r24, 0x0E       ; 14
    7e2a:       c9 d0           rcall   .+402           ;  0x7fbe
    7e2c:       25 9a           sbi     0x04, 5 ; 4

As you can see, not particularly helpful for reproducing what your sketch did. There are likely to be one of two scenarios:

Your sketch was short, in which case you might, after weeks of work, turn the assembler code back into C
Your sketch was long, in which case it would be virtually impossible to turn it back into C

In the "short sketch" case, you are better off just rewriting from scratch. That would be faster, almost certainly. In the "long sketch" case - it just isn't worth it. None of the variable names are preserved, and the way the compiler optimizes code, even the structure of the code would be hard to determine.

user136: This answer doesn't directly answer the question, but still will result in the same end result.
The Arduino IDE uses temporary directories to store build files, including the original sketch as well as the HEX and intermediate files.
On a Mac, these are in /var/folders by default, and on a Windows machine they are in …\Local Settings\Temp\ (which depending on the version of Windows could be in several places).
I've found that especially in Windows, these build files don't get deleted when you close the sketch or IDE, so they may exist on your machine for far longer than you would think.
Also, by default, Crashplan, Backblaze and Time Machine back-up these locations, so even if they have been deleted, they may still be in a backup.
The advantage here is that you will recover C code rather than ASM.

user11: It should be possible as long as the security bit isn't set. This question was asked on EE a while back. 
Is it possible to extract code from an arduino board?
But you won't get the Arduino code you wrote back. The code is compiled into assembly and you'll have to convert that back to C yourself.

37: <p>I made a sketch, but then I lost it. However, I uploaded it to the Arduino before losing it. Is there any way I can get it back?</p>
 76592: <p><strong>Download</strong>:</p>
<pre class="lang-sh prettyprint-override"><code>avrdude \
    -c &lt;programmer type&gt; \
    -P &lt;connection port&gt; \
    -b &lt;override RS-232 baudrate&gt; \
    -p &lt;partno, AVR device&gt; \
    -U &lt;memtype&gt;:r:file_name[:format]
</code></pre>
<p><strong>Upload</strong>:</p>
<p>Use <code>w</code> (write) instead of <code>r</code> (read) for the <code>-U</code> option.</p>
<p>More details at <a href="https://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions" rel="nofollow noreferrer">manual - avrdude Option-Descriptions</a>.</p>
<hr />
<p><strong>Example</strong>:</p>
<p>Download UNO v3 (ATmega328) flash ROM (bootloader) given port <code>/dev/ttyACM0</code> as Intel HEX:</p>
<pre class="lang-sh prettyprint-override"><code>avrdude -c arduino -P /dev/ttyACM0 -b 115200 -p m328p -U flash:r:SaveFlash.hex:i
</code></pre>
<hr />
<p>If used directly from from the arduino IDE archive also add:</p>
<pre><code>-C path-to/arduino-V/hardware/tools/avr/etc/avrdude.conf
</code></pre>
 8: <p>You can download the hex dump of the file, but there is no easy way to get all the C++ code and comments. If you can understand assembly, you could recreate the program, but that would take a while. There are dissasemblers available for some devices, i don't know about arduino.</p>
 6796: <p>I think there is another way to do this, without extracting the code from the Arduino board. Remenber the date you create the sketch, and look for it in  C:\Users\User\AppData\Local\Temp\
(For example : C:\Users\User\AppData\Local\Temp\untitled4390292704786567977.tmp\sketch_jan19a ). You could find your unsaved code unless it was deleted by some "freeing space program".
Good luck! </p>
 10794: <p>Unless your objective is to simply copy the identical code to another device, the simple answer is: <strong>no</strong></p>

<p>As has been pointed out in other answers, you can turn the hex code on the device back into assembler code.</p>

<p>For example (once you have copied the code from the device back onto your disk):</p>

<pre><code>avr-objdump -j .sec1 -d -m avr5 yourFileHere.hex
</code></pre>

<p>Run on one of the bootloader files I get these results (in part):</p>

<pre><code>00007e00 &lt;.sec1&gt;:
    7e00:       11 24           eor     r1, r1
    7e02:       84 b7           in      r24, 0x34       ; 52
    7e04:       14 be           out     0x34, r1        ; 52
    7e06:       81 ff           sbrs    r24, 1
    7e08:       f0 d0           rcall   .+480           ;  0x7fea
    7e0a:       85 e0           ldi     r24, 0x05       ; 5
    7e0c:       80 93 81 00     sts     0x0081, r24
    7e10:       82 e0           ldi     r24, 0x02       ; 2
    7e12:       80 93 c0 00     sts     0x00C0, r24
    7e16:       88 e1           ldi     r24, 0x18       ; 24
    7e18:       80 93 c1 00     sts     0x00C1, r24
    7e1c:       86 e0           ldi     r24, 0x06       ; 6
    7e1e:       80 93 c2 00     sts     0x00C2, r24
    7e22:       80 e1           ldi     r24, 0x10       ; 16
    7e24:       80 93 c4 00     sts     0x00C4, r24
    7e28:       8e e0           ldi     r24, 0x0E       ; 14
    7e2a:       c9 d0           rcall   .+402           ;  0x7fbe
    7e2c:       25 9a           sbi     0x04, 5 ; 4
</code></pre>

<p>As you can see, not particularly helpful for reproducing what your sketch did. There are likely to be one of two scenarios:</p>

<ul>
<li>Your sketch was short, in which case you might, after weeks of work, turn the assembler code back into C</li>
<li>Your sketch was long, in which case it would be virtually impossible to turn it back into C</li>
</ul>

<p>In the "short sketch" case, you are better off just rewriting from scratch. That would be faster, almost certainly. In the "long sketch" case - it just isn't worth it. None of the variable names are preserved, and the way the compiler optimizes code, even the structure of the code would be hard to determine.</p>
 136: <p>This answer doesn't directly answer the question, but still will result in the same end result.</p>

<p>The Arduino IDE uses temporary directories to store build files, including the original sketch as well as the HEX and intermediate files.</p>

<p>On a Mac, these are in /var/folders by default, and on a Windows machine they are in …\Local Settings\Temp\ (which depending on the version of Windows could be in several places).</p>

<p>I've found that especially in Windows, these build files don't get deleted when you close the sketch or IDE, so they may exist on your machine for far longer than you would think.</p>

<p>Also, by default, Crashplan, Backblaze and Time Machine back-up these locations, so even if they have been deleted, they may still be in a backup.</p>

<p>The advantage here is that you will recover C code rather than ASM.</p>
 11: <p>It should be possible as long as the security bit isn't set. This question was asked on EE a while back. </p>

<p><a href="https://electronics.stackexchange.com/questions/61079/is-it-possible-to-extract-code-from-an-arduino-board">Is it possible to extract code from an arduino board?</a></p>

<p>But you won't get the Arduino code you wrote back. The code is compiled into assembly and you'll have to convert that back to C yourself.</p>
