2.4. Code simulation in simulation software34
2.4.1. Introduction to code simulation
Code simulation is the process of running and testing a program for a microcontroller or embedded system inside simulation software, without necessarily using the real physical hardware.
It allows a designer or learner to check whether the code, circuit, sensors, actuators, and microcontroller work correctly before building the actual circuit.
Common simulation software
Some commonly used tools for embedded-system code simulation include:
- Proteus :widely used for simulating Arduino, PIC, AVR, 8051 and other microcontroller circuits.
- Wokwi : web-based simulator for Arduino, ESP32, Raspberry Pi Pico and other boards.
- Tinkercad Circuits : useful for beginners learning Arduino and basic electronics.
- MATLAB/Simulink : used for more advanced control and embedded-system simulations.
- Multisim : mainly used for electronic circuit simulation.
Example by using Proteus
Suppose you want to control an LED using an Arduino.
The process is:
1. Write the Arduino code
int LED = 13;
void setup() {
pinMode(LED, OUTPUT);}
void loop() {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);}
2. Compile the code
In Arduino IDE, compile the program to generate the compiled file, commonly a .hex file for suitable Arduino/AVR simulation workflows.
3. Build the virtual circuit in Proteus
You can place:
- Arduino board/microcontroller
- LED
- Resistor
- Ground
Power connections
4. Load the compiled program
In the simulated microcontroller’s properties, select the generated program file.
5. Start the simulation
When you press Run, the virtual Arduino executes the program.
The LED should:
- turn ON
- remain ON for 1 second
- turn OFF
- remain OFF for 1 second
- repeat continuously.
Importance of code simulation
Code simulation helps learners and engineers to:
- Test programs before using real hardware.
- Detect programming errors.
- Detect circuit connection errors.
- Observe sensor and actuator behavior.
- Save components and development costs.
- Reduce the risk of damaging expensive components.
- Experiment with different circuit designs.
- Understand the interaction between software and hardware.
Embedded-system development process
Requirement → Circuit Design → Code Development → Simulation → Debugging → Hardware Implementation → Testing
For example:
Arduino + Temperature Sensor + Fan
You can first simulate the entire system:
Temperature Sensor → Arduino → Program → Transistor/Relay → Fan
Note: Simulation is not always identical to real hardware. Real components have tolerances, noise, delays, power limitations, and physical effects that may not be perfectly represented by the simulator.


