There are several ways to get the compiled HEX file from Arduino IDE or platform. Here are the most common methods:
Method 1: Using Arduino IDE (Easiest Way)
For AVR Boards (Arduino Uno, Nano, Mega)
- Enable Verbose Output
- Go to File > Preferences
- Check "Show verbose output during compilation"
- 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
- 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
The .hex file will be saved in the ./output folder.
Method 3: Using PlatformIO (Best for Advanced Users)
- Compile the Project
sh
pio run
- Find the HEX File
Located in:
.pio/build/your_board/firmware.hex
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
- Replace COM3 with your Arduino's port.
- This reads the flash memory into backup.hex.
Using STM32CubeProgrammer (STM32 Boards)
- Connect via ST-Link or USB DFU.
- 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
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)
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)
Open your sketch in the Arduino IDE.
Compile it by clicking the checkmark (Verify) button.
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
Method 2: Using Arduino CLI
If you prefer terminal tools:
Install Arduino CLI.
Run:
arduino-cli compile --fqbn arduino:avr:uno your_sketch
Method 3: From PlatformIO (VS Code)
If you're using PlatformIO in VS Code:
Build your project.
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.