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

How to Control a Servo Motor with an IR Remote: A Step-by-Step Guide

小编

Published2025-10-15

Understanding the Basics of Servo Motors and IR Remotes

What is a Servo Motor?

A servo motor is a high-precision motor used for controlling angular position. Unlike standard motors that spin continuously, a servo motor moves to a specific position based on a control signal. These motors are widely used in robotics, automation, and model-building projects due to their accuracy and ability to hold a fixed position.

Typically, a servo motor consists of a small DC motor, gears for mechanical advantage, and a control circuit to handle the positioning. The most common servo motors operate within a range of 0° to 180°, though some can rotate even further.

What is an IR Remote?

An IR (infrared) remote is a device that allows you to control electronic devices by sending infrared signals. These signals carry encoded data that the receiving device can interpret. IR remotes are commonly used in TV controls, air conditioners, and even robotics.

The working principle behind an IR remote is simple: when a button is pressed, it generates an infrared light signal, which is picked up by a sensor on the receiving device. The sensor decodes the signal and acts accordingly, whether that’s turning on a TV or adjusting the position of a servo motor.

The Power of Combining Servo Motors and IR Remotes

When combined, servo motors and IR remotes enable users to control mechanical movements wirelessly and conveniently. For instance, in a robotics project, you could use an IR remote to control the position of a robotic arm or even adjust the tilt of a camera for surveillance purposes.

In addition to robotics, controlling a servo motor with an IR remote has applications in home automation, security systems, and even model vehicles. You can fine-tune the servo motor’s position remotely without needing physical interaction.

How to Set Up the Hardware: Servo Motor + IR Remote

Components You Will Need

Before we dive into the step-by-step guide on how to control a servo motor with an IR remote, let's take a look at the components you'll need for this project:

Servo Motor – Typically, a 9g or 15g servo motor is used for small projects, while larger servos can handle bigger loads.

IR Remote Control – A basic IR remote, often from TV or air conditioner controllers, will work just fine.

IR Receiver Module – The receiver will pick up the signals from the IR remote. The most common IR receiver is the TSOP1838 or IR Receiver Module.

Microcontroller – An Arduino is ideal for this project. It has enough GPIO pins to control the servo motor and receive data from the IR sensor.

Jumper Wires and Breadboard – To make the connections between the various components.

Power Supply – Ensure you have a proper power supply for your servo motor. Small servo motors can be powered by the Arduino, but larger ones might require external power.

Circuit Setup

The setup is quite simple:

Servo Motor to Arduino:

Connect the power pin of the servo to the 5V pin on the Arduino.

Connect the ground pin of the servo to the GND pin on the Arduino.

Connect the signal pin of the servo to one of the PWM pins on the Arduino, like Pin 9.

IR Receiver to Arduino:

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

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

Connect the OUT pin of the IR receiver to a digital input pin on the Arduino, like Pin 11.

Now that you’ve set up the hardware, let’s move on to the software side.

Programming and Controlling the Servo Motor with an IR Remote

Programming the Arduino

To get your servo motor moving with the IR remote, you’ll need to program the Arduino. The Arduino will read the signals from the IR receiver and convert them into servo motor movements.

The first thing you'll need is the IRremote library. This library simplifies the process of decoding signals from the IR remote.

Step 1: Install the IRremote Library

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

In the Library Manager, type IRremote in the search bar.

Click Install to install the IRremote library by shirriff.

Step 2: Write the Arduino Code

Here’s a simple example of Arduino code to control the servo motor with an IR remote:

#include

#include

// Pin definitions

const int recv_pin = 11;

IRrecv irrecv(recv_pin);

decode_results results;

Servo myservo;

// Servo positions

int pos = 90;

void setup()

{

Serial.begin(9600);

irrecv.enableIRIn();

myservo.attach(9);

myservo.write(pos); // Initialize servo position to 90 degrees

}

void loop() {

if (irrecv.decode(&results)) {

long int decCode = results.value;

Serial.println(decCode); // Print IR code for debugging

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

// If button 1 is pressed on the IR remote

if (decCode == 0xFFA25D) { // Replace with your remote's code

pos += 10; // Increase position by 10 degrees

if (pos > 180) pos = 180; // Limit position to 180 degrees

}

// If button 2 is pressed

if (decCode == 0xFF629D) { // Replace with your remote's code

pos -= 10; // Decrease position by 10 degrees

if (pos < 0) pos = 0; // Limit position to 0 degrees

}

myservo.write(pos); // Set the servo to the new position

delay(200); // Delay for 200ms to prevent multiple reads

}

}

Step 3: Upload the Code

Connect your Arduino board to your computer.

In the Arduino IDE, select the correct board and port from the Tools menu.

Click on the Upload button to upload the code to the Arduino.

Step 4: Test Your Setup

Once the code is uploaded, point your IR remote at the IR receiver and press the buttons. The servo motor should move according to the commands you’ve programmed.

Button 1 will increase the position of the servo motor by 10 degrees.

Button 2 will decrease the position of the servo motor by 10 degrees.

You can further customize the code based on the specific buttons of your remote and the required movement for your servo motor.

Conclusion: Expanding Your Project

Controlling a servo motor with an IR remote opens up a world of possibilities for your electronics projects. Whether you’re building a robotic arm, controlling the tilt of a camera, or designing a simple home automation system, this project is a great starting point.

In this guide, you’ve learned the basics of servo motors, IR remotes, and how to combine both in an Arduino-controlled project. With just a few simple components and some coding knowledge, you can build a wide range of interactive and automated systems.

Want to take your project further? Consider adding multiple servos for more complex movements, or integrate sensors like ultrasonic or temperature sensors for enhanced functionality. The sky's the limit!

By mastering this basic setup, you’ve unlocked the potential for more advanced automation, robotics, and remote control systems. Happy building!

Kpower has delivered professional drive system solutions to over 500 enterprise clients globally with products covering various fields such as Smart Home Systems, Automatic Electronics, Robotics, Precision Agriculture, Drones, and Industrial Automation.

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.