Export the program you compiled in the Arduino IDE as a HEX file and load it into an ATmega328P in Proteus. Start with blink, then measure LED brightness and average voltage with PWM.
You are writing a board for a greenhouse that sets the fan speed according to temperature. Removing the board and re-uploading every time you change the program, or burning a MOSFET because of a wrong pin number, gets old fast. This is where Proteus's most loved feature comes in: it simulates the ATmega328P microcontroller, the brain of the Arduino, together with your program. Even without a board you run your code with the circuit and measure the pins with an oscilloscope.
Theory: how does Proteus run a program?
Proteus does not understand your .ino source file directly. A real microcontroller runs machine code, and so does Proteus. So you first compile the program in the Arduino IDE and take the resulting machine code as a .hex file in Intel HEX format. Then you give that file to the "program file" property of the microcontroller in Proteus. Some newer Proteus versions can also write and compile the program inside Proteus; but the HEX route works in every version, and the same idea applies to real boards.
Arduino Uno pin numbers actually map to the port pins of the ATmega328P. When you use the bare chip in Proteus you need to know this mapping:
Arduino D13 -> PB5 (on-board LED)
Arduino D9 -> PB1 (PWM, Timer1, about 490 Hz)
Arduino D5 -> PD5 (PWM, Timer0, about 980 Hz)
Arduino A0 -> PC0 (analog input)
Step 1: export the HEX file
// Blink: turns the LED on D13 on for 1 s and off for 1 s
const int LED_PIN = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(1000);
}
- Open a new sketch in the Arduino IDE, paste the code and select Arduino Uno as the board.
- Run Export Compiled Binary from the Sketch menu.
- Open the sketch folder. Depending on the IDE version, the files are directly in the sketch folder or in a
buildsubfolder. You will see two HEX files: one withwith_bootloaderin its name and one without. For simulation use the one without the bootloader.
If you enable verbose output during compilation in the IDE preferences, the end of the build log also shows the full path of the HEX file in the temporary folder.
Step 2: prepare the microcontroller in Proteus
- Press P and add an ATMEGA328P. (Depending on your version, the library may also include a ready-made Arduino Uno model; if so, the idea is the same.)
- Add a RES (220 ohm) and an LED-RED. PB5 pin → 220 ohm → LED anode, LED cathode → GROUND.
- Double-click the chip. In the Program File field, click the folder icon and choose the
.hexfile without the bootloader. - Set the clock frequency field to 16 MHz. Arduino code is compiled for 16 MHz; at a different frequency
delay(1000)will not last one second. Field names (e.g. clock frequency or CKSEL fuses) vary by version. - Start the simulation.
LED: on for 1 s, off for 1 s, repeating
Oscilloscope on PB5: square wave between 0 and 5 V, period 2 s
Proteus usually hides the power pins (VCC, GND) of microcontrollers on the schematic and connects them to the default power nets itself. That is why the chip works even though you didn't wire 5 V to it. On a real board, supply and decoupling capacitors are mandatory.
Step 3: brightness and average voltage with PWM
A microcontroller cannot produce a true analog voltage; a pin is either 0 V or 5 V. PWM (pulse width modulation) switches the pin on and off very quickly. The larger the duty cycle, the higher the average voltage. On Arduino you give analogWrite(pin, value) a value from 0 to 255:
Duty cycle D = value / 255
Average voltage Vavg = 5 x D
value = 64 -> D = 25.1% -> Vavg = 1.25 V
value = 128 -> D = 50.2% -> Vavg = 2.51 V
value = 191 -> D = 74.9% -> Vavg = 3.75 V
// PWM: steps the LED on D9 through three brightness levels
const int LED_PIN = 9;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
analogWrite(LED_PIN, 64); // about 25%
delay(1000);
analogWrite(LED_PIN, 128); // about 50%
delay(1000);
analogWrite(LED_PIN, 191); // about 75%
delay(1000);
}
Compile this code and load the new HEX. Move the LED to the PB1 pin (through 220 ohm). Connect oscilloscope channel A to PB1, and set 0.5 ms per division and 2 V per division.
Period: about 2.04 ms (about 490 Hz), the same at every level
At 25%: about 0.51 ms high, 1.53 ms low
At 50%: about 1.02 ms high, 1.02 ms low
At 75%: about 1.53 ms high, 0.51 ms low
The frequency stays the same; only the pulse width changes. The LED's brightness also steps up in the animation.
Try it with the mini simulator
In the mini simulator below, move the duty cycle slider and watch the average voltage and LED brightness change. Compare the average voltage you read at 25%, 50% and 75% with the calculation above. Then connect a DC voltmeter to PB1 in Proteus; the voltmeter may show something close to the average of the fast pulses, but that depends on the instrument model and settings. The truly reliable measurement is the pulse width on the oscilloscope.
Common mistakes
Trying to load the source file: Proteus does not run an .ino file; it needs the compiled .hex.
Not setting the clock frequency: if the default frequency is not 16 MHz, every timing shifts; a 1-second blink looks far too slow or too fast.
Using analogWrite on a non-PWM pin: on the Uno, PWM exists only on pins 3, 5, 6, 9, 10 and 11. On the others the pin stays low for values below 128 and high for 128 and above.
Exercise
To keep a fan quiet, fix the PWM at 30%. Calculate the required analogWrite value and the average voltage. Then write a loop that smoothly brightens the LED from 0 to 255 over two seconds and dims it again, and watch it in Proteus.
Hint: dividing 2000 ms by 256 steps gives about 8 ms per step.
Solution
value = 0.30 x 255 = 76.5 -> 77
Vavg = 5 x 77 / 255 = 1.51 V
const int LED_PIN = 9;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
for (int d = 0; d <= 255; d++) {
analogWrite(LED_PIN, d);
delay(8);
}
for (int d = 255; d >= 0; d--) {
analogWrite(LED_PIN, d);
delay(8);
}
}
Export the HEX again and load it in Proteus. On the oscilloscope the pulse width slowly opens and closes, and the LED brightens and dims as if breathing.
In short: the key to running Arduino in Proteus is the compiled HEX and the correct clock frequency; with PWM the frequency is fixed and the duty cycle varies. In the next lesson you will connect a temperature sensor to the microcontroller and measure it with the ADC.
// Mini simulator
Move the sliders; the circuit and the values update instantly. Build the same circuit in Proteus and compare.
// Spot the bug +10 XP
Exactly one line below is wrong. Click the faulty line.
Proteus does not run source code (.ino). The program file field needs the compiled .hex file without the bootloader that you found in step 3.
// Mini quiz
Click an option; you will see right away, with the reason, whether it is correct or not.
Mark it when you finish: your progress is saved and you earn +20 XP.
Tip: ← → keys let you move between lessons.


