Home Industry InsightBLDC
Looking for a suitable motor? Looking for a suitable motor?
Looking for a suitable motor?

Arduino Control Servo Motor with IR Remote: A Step-by-Step Guide to Building Your Project

小编

Published2025-10-15

Learn how to control a servo motor using an IR remote with an Arduino. This detailed guide will walk you through the setup, coding, and troubleshooting of this innovative project that integrates Arduino and infrared technology. Perfect for hobbyists, makers, and engineers, this article explains the process in simple terms while offering valuable insights into electronics and programming.

Arduino, servo motor, IR remote, control, electronics, programming, infrared, hobby project, robotics, DIY

Introduction to Arduino Servo Motor Control with IR Remote

Arduino is an open-source platform that has gained immense popularity for creating interactive electronic projects. One of the most common applications for Arduino is controlling motors, such as servo motors, which are widely used in robotics, automation, and modeling. Servo motors, unlike regular DC motors, can precisely control angular position, making them ideal for applications where accuracy and precision are needed.

In this project, we'll dive into the fascinating world of infrared (IR) remote controls. IR technology has been around for decades and is used in devices ranging from television remotes to garage doors. By integrating IR technology with Arduino, we can wirelessly control a servo motor. This project is a perfect example of how you can combine basic electronics with software programming to create a functional system with practical real-world applications.

The Basic Components You Will Need

Before we start building, let’s first identify the components needed for this project:

Arduino Board: The Arduino Uno board is the most commonly used microcontroller. It’s perfect for beginners and has sufficient processing power for controlling motors and reading input from sensors like the IR receiver.

Servo Motor: A standard servo motor like the SG90 is ideal for this project. It has a small form factor, operates on 5V, and is easy to control.

IR Remote Control: This is the heart of the remote control system. Any basic IR remote that outputs signals on common frequencies (like 38kHz) should work. However, some remotes may require specific programming based on the signals they send.

IR Receiver Module: The IR receiver picks up signals from the remote control and sends them to the Arduino. You will need an IR receiver like the TSOP38238, which is a widely used model for Arduino projects.

Jumper Wires: These are essential for making all the necessary connections between the Arduino, servo motor, and IR receiver.

Breadboard: A breadboard allows you to set up and test your circuit before you finalize your connections.

Power Supply: A stable power source for your Arduino and servo motor is essential for reliable performance.

The Principle of Servo Control with IR

A servo motor typically has three wires: power, ground, and control. The control wire receives PWM (Pulse Width Modulation) signals that determine the position of the motor. The motor will move to different angles depending on the duty cycle of the PWM signal. When we use an IR remote to control the servo, the remote sends commands as pulses of infrared light, which are received by the IR module.

The Arduino decodes these pulses, processes the commands, and then generates PWM signals that are sent to the servo motor, which moves accordingly. In simple terms, the IR remote acts as the user interface, while the Arduino handles the logic and communication with the servo.

Setting Up the Circuit

To begin, we need to connect all the components. The setup is relatively straightforward:

Connect the Servo Motor:

Connect the servo motor’s power (usually red) and ground (usually black or brown) wires to the Arduino’s 5V and GND pins, respectively.

The control wire (usually yellow or orange) should be connected to one of the Arduino’s PWM pins, typically pin 9.

Connect the IR Receiver:

Connect the VCC pin of the IR receiver to the 5V pin of the Arduino.

Connect the GND pin of the IR receiver to the GND pin of the Arduino.

The signal pin of the IR receiver should be connected to a digital input pin on the Arduino, for example, pin 11.

Once you have the circuit connected, we can move on to the programming.

Coding and Testing the Arduino Servo Motor Control with IR Remote

Step-by-Step Programming

Now that the hardware is ready, we can move on to writing the code for the Arduino. This code will listen for commands from the IR remote and use those commands to move the servo motor to different positions. Don’t worry if you’ve never worked with IR sensors before — the process is relatively simple!

Install the IR Library:

The first thing you need to do is install the IRremote library, which is available in the Arduino IDE’s Library Manager. To do this:

Open Arduino IDE and navigate to Sketch > Include Library > Manage Libraries.

Search for IRremote and click Install.

This library will handle all the heavy lifting of decoding the IR signals.

Write the Code:

Here’s an example of the code that you can upload to your Arduino to control the servo using the IR remote:

#include

#include

// Define pins for IR receiver and servo

const int recv_pin = 11;

IRrecv irrecv(recv_pin);

decode_results results;

Servo myservo;

void setup()

{

Serial.begin(9600); // Start the serial monitor for debugging

irrecv.enableIRIn(); // Start the IR receiver

myservo.attach(9); // Attach the servo to pin 9

}

void loop()

{

if (irrecv.decode(&results)) // Check if IR signal is received

{

long int decCode = results.value; // Get the code of the button pressed

Serial.println(decCode); // Print the code to the serial monitor

// Map the IR codes to servo positions

if (decCode == 0x1FE48B7) // Button 1 on the remote

{

myservo.write(0); // Rotate servo to 0 degrees

}

else if (decCode == 0x1FE58A7) // Button 2 on the remote

{

myservo.write(90); // Rotate servo to 90 degrees

}

else if (decCode == 0x1FEB847) // Button 3 on the remote

{

myservo.write(180); // Rotate servo to 180 degrees

}

irrecv.resume(); // Receive the next value

}

}

How the Code Works

IRremote Library: The IRremote library is responsible for receiving and decoding the IR signals from the remote. When you press a button on the remote, the IR receiver sends the signal to the Arduino, which is decoded and stored in the results object.

Servo Control: Based on the decoded IR signal (which is a unique number for each button on the remote), the Arduino decides which angle to move the servo to. In this case, when you press Button 1, the servo moves to 0°, Button 2 moves it to 90°, and Button 3 moves it to 180°.

Serial Monitor: The Serial.println(decCode) line helps you debug the project by printing the IR code to the Serial Monitor. This way, you can check the codes for each button on your IR remote.

Testing the Project

Once you’ve uploaded the code to your Arduino, open the Serial Monitor to see the decoded IR codes when you press buttons on your remote. If everything is set up correctly, pressing the buttons will move the servo motor to the specified positions (0°, 90°, or 180°).

You can modify the code to add more buttons, control the servo with different angles, or even trigger multiple servos if you’re building a more complex robotic project.

Conclusion

In this two-part guide, we've explored the process of controlling a servo motor using an Arduino and IR remote. We’ve covered everything from the basic components to the setup, programming, and testing. With this knowledge, you can create a variety of projects that incorporate wireless control for motors, including robotics, home automation, and more.

Whether you're a beginner or an experienced maker, this project provides a great hands-on experience with Arduino, IR communication, and servo motor control. The possibilities for extending this project are endless—adding more motors, integrating sensors, or creating more sophisticated remote control systems. The combination of Arduino and IR technology is a powerful tool for any DIY electronics enthusiast.

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 a motor expert for product recommendation.
Contact a motor expert for product recommendation.

Powering The Future

Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.