小编
Published2025-10-15
Introduction to Servo Motors and Arduino
If you're into DIY electronics, you’ve probably come across the term "servo motor" at some point. Servo motors are essential in various projects, ranging from robotic arms to automated doors. They’re preferred in situations that require precise control of angle and position. In this article, we will explore how to control a servo motor with Arduino and simulate the entire process on Tinkercad, a great platform for virtual electronics projects.

Before diving into the code, let’s take a look at what a servo motor is and how it works.
A servo motor is a type of motor that rotates to a specific angle, controlled by sending electrical pulses. Unlike standard DC motors, which continuously rotate when powered, servo motors are capable of precise angular movement. The most common type of servo motors are used in robotics, model airplanes, and automated systems.
A typical servo consists of a small DC motor, a gear system, a feedback mechanism (usually a potentiometer), and an electronic circuit to control the rotation. The motor's position is determined by a pulse-width modulation (PWM) signal, which dictates how far the motor should rotate. PWM is a technique where the signal is turned on and off at different intervals, controlling the motor’s position with great precision.
How Does Arduino Control a Servo Motor?
Arduino boards are open-source microcontrollers that can be easily programmed to control various electronic components. When it comes to servo motors, Arduino can send the required PWM signals to the servo’s control wire, making it move to a specified angle.
Arduino uses its Servo library to control servo motors. This library abstracts the technicalities of generating PWM signals and makes it easier for users to control the motor with a simple command.
Tinkercad and Virtual Arduino Simulations
Tinkercad is a free, online 3D design and simulation tool developed by Autodesk. It allows you to design circuits, code Arduino projects, and simulate them without needing physical components. For beginners and those who want to test ideas without investing in hardware, Tinkercad provides a convenient platform to get started.
Using Tinkercad, you can easily design a virtual circuit with an Arduino and a servo motor. It also provides a code editor where you can write and run your Arduino code. In this guide, we’ll walk you through creating a virtual circuit in Tinkercad and writing the Arduino code to control the servo motor.
To get started, visit Tinkercad’s website and create a free account. Once logged in, navigate to the “Circuits” section and click on “Create New Circuit.” This will open a virtual workspace where you can start building your circuit and writing your code.
Here’s a quick overview of what we’ll need for the project:
Arduino UNO (or any compatible Arduino board)
Servo motor (a common model is the SG90)
Breadboard (optional, for neatness)
Once you’ve created a new circuit, drag and drop the components onto the virtual workspace. We’ll connect the servo motor to the Arduino, write the code to control it, and observe how the servo motor responds to the signals.
Building the Circuit and Writing the Arduino Code
Now that we understand the basic components, let’s build the circuit and write the code to control the servo motor.
Step 1: Building the Circuit on Tinkercad
Place the Arduino and Servo Motor: Start by placing an Arduino board and a servo motor on the virtual workspace in Tinkercad. You can search for "Arduino" in the component library and drag the UNO model into the workspace. Do the same for the servo motor.
Connect the GND pin on the Arduino to the GND pin of the servo motor.
Connect the 5V pin on the Arduino to the VCC pin of the servo motor to supply power.
Connect the signal pin of the servo motor (usually labeled as “S”) to one of the PWM-capable pins on the Arduino, for instance, pin 9. This will be the pin through which the Arduino will send control signals to the servo.
Simulate Power: Once the wiring is done, click on the "Start Simulation" button to power up the circuit. You should see the servo motor ready to receive signals, although it won’t do anything yet since we haven’t written the code.
Step 2: Writing the Arduino Code
Now, let’s write the code that will make the servo motor rotate. Arduino uses the Servo library to control servo motors, making it super easy to manage the motor’s position. The following code will rotate the servo to different angles, one by one.
#include // Include the Servo library
Servo myServo; // Create a servo object to control the servo motor
myServo.attach(9); // Attach the servo to pin 9
myServo.write(0); // Rotate the servo to 0 degrees
delay(1000); // Wait for 1 second
myServo.write(90); // Rotate the servo to 90 degrees
delay(1000); // Wait for 1 second
myServo.write(180); // Rotate the servo to 180 degrees
delay(1000); // Wait for 1 second
#include : This line includes the Servo library, which contains functions for controlling the servo motor.
Servo myServo;: This creates an instance of the Servo class called myServo, which we will use to control the motor.
myServo.attach(9);: This attaches the servo to pin 9 on the Arduino. This means we will be sending PWM signals to the motor through pin 9.
myServo.write(angle);: The write() function sends a PWM signal to the servo motor. The angle can range from 0 to 180 degrees, where 0 is the minimum position and 180 is the maximum position.
delay(1000);: The delay() function pauses the program for a specified time (in milliseconds). In this case, it waits for one second before moving to the next angle.
Once you’ve written the code, click on the “Start Simulation” button again to run the simulation. You should see the servo motor moving between 0, 90, and 180 degrees every second. This is the basic operation of a servo motor controlled by an Arduino.
You can experiment with different angles and delays to observe how the servo motor behaves. For example, try setting the angles to intermediate values like 45 or 135 degrees, or change the delay times to make the motor move faster or slower.
If the servo motor does not behave as expected, check the following:
Make sure the connections are correct, especially the servo's signal pin.
Ensure the correct pin number is used in the code (e.g., myServo.attach(9);).
Verify that the servo motor’s power supply is adequate. Tinkercad simulations often handle this automatically, but in real-world projects, ensure the Arduino can supply enough current for the motor.
In conclusion, using Tinkercad to simulate controlling a servo motor with Arduino is a fantastic way to practice and experiment without needing physical components. This step-by-step guide has walked you through the entire process, from building the circuit to writing the code and testing the system. In the next part, we’ll explore some advanced techniques, including adding multiple servo motors to your project and creating more complex movements!
Established in 2005, Kpower has been dedicated to a professional compact motion unit manufacturer, headquartered in Dongguan, Guangdong Province, China.
Update:2025-10-15
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.