As an Amazon Associate we earn from qualifying purchases.
A servo motor is one of the easiest actuators to control from an Arduino, and Proteus lets you test the whole setup before you touch any hardware. In this guide you will wire a servo to an Arduino in a Proteus schematic, write the code, load the compiled file and watch the shaft move. The video below shows the simulation running.
How a hobby servo works
A hobby servo contains a small DC motor, a gearbox and a position sensor, usually a potentiometer, with control electronics. You do not tell it how fast to turn. You tell it which angle to hold, and it drives the shaft there and keeps it in place.
The angle is set by a PWM-style control signal. The servo expects a pulse roughly every 20 ms, and the pulse width, typically between about 1 ms and 2 ms, sets the position. Arduino’s Servo library generates this signal for you, so you only work with angles in degrees.
Most servos have three wires:
- Signal (often orange or yellow): connects to an Arduino digital pin.
- Power (usually red): connects to the supply, commonly 5 V.
- Ground (brown or black): connects to ground, shared with the Arduino.
What you need in Proteus
- An Arduino board model (Arduino Uno is the usual choice). Proteus does not include Arduino boards by default, so you need to add an Arduino library for Proteus first.
- A servo model. The MOTOR-PWMSERVO part is the one commonly used for this. Search for “servo” in the component picker if you cannot find it.
- Optionally, a potentiometer (such as POT-HG) if you want to control the angle by hand.
- The Arduino IDE to write and compile the sketch.
Wiring the circuit
- Place the Arduino and the servo on the schematic.
- Connect the servo signal pin to Arduino digital pin 9. Any PWM-capable pin is a safe choice, and pin 9 is what the example code below uses.
- Connect the servo power pin to a 5 V terminal and its ground pin to a ground terminal.
- For the potentiometer version, connect the outer pins to 5 V and ground, and the wiper (middle pin) to analog pin A0.
In Proteus the power and ground connections are sometimes handled with terminal symbols. Check that the servo actually has a supply, because a servo without power will simply not move.
Example 1: sweep the servo back and forth
This sketch moves the shaft from 0 to 180 degrees and back again. It is a good first test because the motion is easy to see.
#include <Servo.h>
Servo myServo;
void setup() { myServo.attach(9); }
void loop() {
for (int angle = 0; angle <= 180; angle++) { myServo.write(angle); delay(15); }
for (int angle = 180; angle >= 0; angle–) { myServo.write(angle); delay(15); }
}
The 15 ms delay gives the servo time to reach each position. A shorter delay makes the sweep faster, and a longer one makes it slower.
Example 2: control the angle with a potentiometer
Here the Arduino reads the potentiometer on A0 and maps the 0 to 1023 reading to an angle between 0 and 180 degrees.
#include <Servo.h>
Servo myServo;
void setup() { myServo.attach(9); }
void loop() {
int value = analogRead(A0);
int angle = map(value, 0, 1023, 0, 180);
myServo.write(angle);
delay(15);
}
While the simulation runs, move the potentiometer slider and the servo shaft should follow it.
Loading the program into the Arduino in Proteus
Proteus does not run the .ino file. It runs the compiled .hex file, so you need to produce one first.
- Open the sketch in the Arduino IDE and verify it compiles.
- Export the compiled binary (Sketch menu), or enable verbose output in the preferences and read the .hex path from the compile log.
- In Proteus, double-click the Arduino board.
- Set the Program File field to the .hex file and click OK.
- Press the play button at the bottom left to start the simulation.
If you change the code, compile again so the .hex file is updated. Proteus will not pick up changes by itself.
Troubleshooting common problems
- The servo does not move: check that the Program File is set, the signal wire goes to the same pin used in attach(), and the servo has power and ground.
- The motion is jerky or very slow: Proteus simulations can run slower than real time on a busy computer. Try a simpler schematic or close other programs.
- The compile works but nothing happens: you may be using an old .hex file. Recompile and reload it.
- The angle looks wrong: some servo models have their own limits or properties. Open the part’s properties to check them.
Moving from simulation to real hardware
The same code works on a real Arduino and a hobby servo, but there is one important difference. A small servo can draw more current than a USB port or the Arduino’s 5 V pin comfortably supplies, especially when the shaft is under load. For anything beyond a light test, power the servo from a separate supply and connect its ground to the Arduino ground. Proteus will not show you this problem, so it is worth remembering when you build the real circuit.
Related Proteus projects
Once the servo is working, you can combine it with other parts. For example, show the current angle on a display, as in our Arduino and LCD simulation guide, or set the angle from buttons using a matrix keypad with Arduino. If you want to compare other motor types, see our guides on DC motor direction control with an H-bridge and stepper motor interfacing with a PIC microcontroller.
FAQ
Can I simulate a servo motor in Proteus without an Arduino?
Yes. You can drive the servo model with a pulse generator or another microcontroller, as long as it receives a suitable control pulse. The Arduino with the Servo library is simply the easiest way to create that signal.
Which Arduino pin should I use for the servo signal?
The Servo library can work on most digital pins, but pin 9 is a common choice and is used in the examples here. Whatever pin you pick, make sure the number in attach() matches the wire in your schematic.
Why is the .hex file needed in Proteus?
Proteus simulates the microcontroller itself, so it needs the compiled machine code rather than the source sketch. The Arduino IDE produces this file when it compiles.
Can I control more than one servo?
Yes. Create one Servo object for each motor, attach each to its own pin and call write() on each one. In real hardware, remember that several servos need a stronger power supply.