ARDUINO AND SERVO MOTOR INTERFACING SIMULATION IN PROTEUS

Photo of author

By Jackson Taylor

Home » Electronics Topics » Arduino » ARDUINO AND SERVO MOTOR INTERFACING SIMULATION IN PROTEUS

As an Amazon Associate we earn from qualifying purchases.

A servo motor is one of the easiest ways to learn how an Arduino controls physical movement. Before you wire anything on a breadboard, you can test the whole idea in Proteus. This article shows how to simulate a servo motor in Proteus with an Arduino Uno, including the connections, a working sketch and what to check if the servo does not move.

The example sweeps the servo through three positions: 0, 90 and 180 degrees, pausing one second at each.

What you need

  • BOARD – Arduino Uno
  • SIMULATION – Proteus 8.1 (newer versions should work in a similar way)
  • A servo motor model from the Proteus component library
  • The Arduino IDE, to compile the sketch and get the HEX file

How a hobby servo works

A hobby servo has a small motor, a gearbox and a position sensor inside one case. You do not tell it how fast to turn. You tell it which angle to go to, and its internal circuit moves the shaft there and holds it.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

The angle is set by a PWM-style control signal on the signal wire. The servo expects a pulse roughly every 20 ms, and the width of that pulse (typically around 1 to 2 ms) sets the shaft position. The Arduino Servo library generates these pulses for you, so you only give it an angle between 0 and 180.

Servo connections

A servo has three wires. In this example the colours are:

  • Orange – signal, connected to Arduino pin 9
  • Red – power, connected to 5V
  • Brown – ground, connected to GND

Wire colours vary between manufacturers. Many servos use yellow or white for signal, so check the datasheet of the servo you buy. In the Proteus model, use the pin labels rather than colours.

Simulation files and video

You can download the Proteus project from the link below and open it directly. The video shows the simulation running.

See also
WIFI CONTROLLED FAN( SPEED CONTROL ALSO) AND LIGHT USING ARDUINO

DOWNLOAD SIMULATION FILES

Circuit in Proteus

The schematic below shows the Arduino Uno with the servo signal pin on digital pin 9, plus the power and ground connections.

Proteus schematic of an Arduino Uno connected to a servo motor signal pin 9
Arduino Uno and servo motor circuit in Proteus

Building it yourself

  1. Open Proteus and start a new schematic.
  2. Press P (Pick Devices) and add the Arduino Uno. If it is not listed, your Proteus version may need an Arduino library added first.
  3. Search for “servo” in the component picker and add the servo motor model. Proteus includes a PWM servo model, so you normally do not need to download a separate servo library. The exact name can differ between versions.
  4. Place a power terminal and a ground terminal.
  5. Connect the servo signal pin to Arduino pin 9, the servo power pin to 5V and the servo ground pin to GND.

Arduino program

The sketch uses the standard Servo library that ships with the Arduino IDE. It creates a servo object, attaches it to pin 9 and then moves the shaft between three angles in a loop.

//SERVO CONNECTIONS --ORANGE-SIGNAL,RED-5V,BROWN-GND
#include <Servo.h>
Servo myservo;   // create servo object to control a servo
void setup()
{
  myservo.attach(9);   // attaches the servo on pin 9 to the servo object
}
void loop()
{
  myservo.write(0); // moves the servo to 0 degrees
  delay(1000);  
  
  myservo.write(90); //90 DEGREE
  delay(1000);
  myservo.write(180);
  delay(1000);
}

How the code works

  • #include <Servo.h> loads the library that creates the control pulses.
  • Servo myservo; creates a servo object. You can create one object per servo.
  • myservo.attach(9); tells the library that the signal wire is on pin 9.
  • myservo.write(angle); sets the target angle from 0 to 180 degrees.
  • delay(1000); waits one second so the shaft has time to reach the position and you can see it.

Running the simulation

  1. In the Arduino IDE, compile the sketch. Use the option to export the compiled binary, or find the HEX file in the build folder.
  2. In Proteus, double-click the Arduino Uno and set the Program File field to that HEX file.
  3. Press the Play button at the bottom left of Proteus.
See also
Bidirectional DC-DC converter fed drive for electric vehicle system with speed variation

The servo shaft should move to 0 degrees, then 90, then 180, waiting one second at each position, and repeat. If you change the angles or the delay values and compile again, the movement changes accordingly.

If the servo does not move

  • Check the HEX file. The most common cause is a missing or outdated program file on the Arduino component.
  • Check pin 9. The signal wire in the schematic must match the pin number in attach().
  • Check power and ground. An unconnected power or ground pin on the servo model will stop it responding.
  • Make sure the simulation is running and not paused or stopped on an error. The message bar at the bottom shows any problems.
  • Slow simulation. Proteus can run slower than real time on a busy computer, so the one-second delays may look longer.

Moving to real hardware

The same sketch works on a real Arduino Uno. A small servo can often run from the Arduino 5V pin for a quick test, but a servo that is loaded or stalls can draw more current than the board supplies and cause resets. For anything beyond a light test, use a separate 5V supply for the servo and join its ground to the Arduino ground.

Where to go next

Once the basic sweep works, you can replace the fixed angles with values from a potentiometer, buttons or a keypad. If you want to explore other motor types, look at DC motor direction control with an H-bridge and relay, or stepper motor interfacing with a PIC microcontroller. For displaying the servo angle, you can combine this circuit with an Arduino and LCD simulation, and for entering angles by hand you can try a keypad with Arduino.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

FAQ

Do I need to download a servo library for Proteus?

Usually not. Proteus ships with a PWM servo model in its component library, which you can find by searching for “servo” in the component picker. Separate downloads are only needed if your version lacks the model or you want a specific servo type.

See also
ARDUINO ,UART AND LCD SIMULATION IN PROTEUS (DISPLAYING UART DATA IN LCD USING ARDUINO AND PROTEUS)

Which Arduino pin should the servo signal wire use?

Any digital pin works with the Servo library. This example uses pin 9, so the schematic and the attach() call must both use that pin.

What angle range can the servo reach?

The write() function accepts 0 to 180 degrees, which suits most standard hobby servos. Continuous rotation servos behave differently, because the value controls speed and direction rather than position.

Why does the code use delay()?

The delay gives the servo time to reach each position before the next command. Without it, the sketch would change the target so quickly that you would not see the shaft stop at 0, 90 or 180 degrees.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works