DEV Community

Hedy
Hedy

Posted on

How to Get HEX from Arduino?

There are several ways to get the compiled HEX file from Arduino IDE or platform. Here are the most common methods:

Image description

Method 1: Using Arduino IDE (Easiest Way)
For AVR Boards (Arduino Uno, Nano, Mega)

  1. Enable Verbose Output
  • Go to File > Preferences
  • Check "Show verbose output during compilation"
  1. Compile the Sketch (Ctrl + R or Sketch > Verify/Compile)
  • The IDE will display the temporary build folder path in the console.
  • Look for a line like:
C:\Users\YourUser\AppData\Local\Temp\arduino_build_123456/YourSketch.ino.hex
Enter fullscreen mode Exit fullscreen mode
  1. Manually Copy the HEX File

Navigate to the temporary folder and copy the .hex file.

For ARM Boards (Arduino Due, Zero, MKR)
ARM-based boards generate .bin files instead of .hex.

  • The file is located in the same temporary folder (look for *.bin).
  • You can flash it using BOSSAC or OpenOCD.

Method 2: Using Arduino CLI (Advanced)
If you prefer command-line tools:

sh
arduino-cli compile --fqbn arduino:avr:uno YourSketch.ino --output-dir ./output
Enter fullscreen mode Exit fullscreen mode

The .hex file will be saved in the ./output folder.

Method 3: Using PlatformIO (Best for Advanced Users)

  1. Compile the Project
sh
pio run
Enter fullscreen mode Exit fullscreen mode
  1. Find the HEX File

Located in:

.pio/build/your_board/firmware.hex
Enter fullscreen mode Exit fullscreen mode

Method 4: Manually Dumping HEX from a Programmed Arduino
If you need to extract HEX from an already programmed Arduino(What is Arduino?):

Using avrdude (AVR Boards)

sh
avrdude -p atmega328p -c arduino -P COM3 -b 115200 -U flash:r:backup.hex:i
Enter fullscreen mode Exit fullscreen mode
  • Replace COM3 with your Arduino's port.
  • This reads the flash memory into backup.hex.

Using STM32CubeProgrammer (STM32 Boards)

  1. Connect via ST-Link or USB DFU.
  2. Read memory and export as HEX.

How to Use the HEX File
AVRDUDE: Flash using:

sh
avrdude -p atmega328p -c usbasp -U flash:w:your_file.hex:i
Enter fullscreen mode Exit fullscreen mode

STM32CubeProgrammer: For ARM-based boards.

XLoader: Simple GUI for uploading HEX to AVR.

Why Extract the HEX File?
✔ Direct flashing without Arduino IDE
✔ Mass production programming
✔ Reverse engineering (for educational purposes)

Top comments (1)

Collapse
 
abdelwahid_nejmeddine_7b0 profile image
Abdelwahid Nejmeddine

To get a HEX file from an Arduino sketch, follow one of these methods depending on your setup:


Method 1: Using Arduino IDE (Standard method)

  1. Open your sketch in the Arduino IDE.

  2. Compile it by clicking the checkmark (Verify) button.

  3. Locate the temporary build folder:

Go to File > Preferences.

Enable "Show verbose output during: compilation".

Click Verify again.

Look at the output panel below — it will show the full path to the .hex file, something like:

.../AppData/Local/Temp/arduino_build_xxxxxx/your_sketch.ino.hex

  1. Copy the file from that temporary folder to a safe location.

Method 2: Using Arduino CLI

If you prefer terminal tools:

  1. Install Arduino CLI.

  2. Run:

arduino-cli compile --fqbn arduino:avr:uno your_sketch

  1. This generates a .hex file in the build directory.

Method 3: From PlatformIO (VS Code)

If you're using PlatformIO in VS Code:

  1. Build your project.

  2. The HEX file is generated in:

.pio/build/your_board/firmware.hex


Do you need the HEX file to upload it using another programmer or tool? I can guide you with that too.