Home > Industry Insights >BLDC
TECHNICAL SUPPORT

Product Support

How to Control a Servo Motor Using an Infrared Remote (Complete Step-by-Step Guide)

Published 2026-04-19

This guide provides a complete, practical solution for controlling aservomotor using a standard infrared (IR) remote control. By following the steps below, you will be able to precisely position aservomotor by pressing buttons on any common IR remote (e.g., a TV or set-top box remote). No brand-specific components are required, and the instructions are based on widely available, low-cost modules.

01Core Concept and How It Works

An IR remote emits pulses of invisible light. An IR receiver detects these pulses and converts them into a digital code unique to each button. A microcontroller reads this code and sends a corresponding pulse-width modulation (PWM) signal to theservomotor, setting its shaft to a specific angle.

Example scenario:A common TV remote’s “volume up” button rotates a servo to 90° (e.g., opening a small latch), while “volume down” returns it to 0°. This principle is used in DIY robot arms, automatic pet feeders, and remote-controlled camera pan-tilt systems.

02Required Components (No Brand Names)

Component Typical Specification Quantity
Microcontroller board Any common board (e.g., 5V logic, with PWM output) 1
IR receiver module 1838B or equivalent (38kHz carrier frequency) 1
Servo motor Standard 5V analog servo (e.g., SG90-sized, 0°–180°) 1
IR remote control Any household remote (TV, DVD, air conditioner) 1
Jumper wires Male-to-female or male-to-male 6–8
Power supply 5V DC (USB or battery pack) 1

Important:Most servos draw significant current (200–500 mA). Do not power the servo directly from the microcontroller’s 5V pin if it requires more than 500 mA. Use an external 5V supply with common ground.

03Wiring Connection (Verified and Reliable)

Connect the components as follows. This wiring has been tested with standard 5V systems.

IR Receiver Module (looking at flat side):

Left pin: Signal → Microcontroller digital pin 11 (example)

Center pin: GND → Common ground

Right pin: VCC → 5V output

Servo Motor:

Brown/Black wire: GND → Common ground

Red wire: 5V → External 5V supply (or microcontroller 5V only for tiny servos)

Orange/Yellow wire: Signal → Microcontroller PWM pin 9 (example)

Common ground: Connect the external power supply’s GND to the microcontroller’s GND. This is mandatory for stable operation.

04Step-by-Step Procedure

Step 1: Identify Your Remote’s Button Codes

Every IR remote sends different codes. You must first read the codes from your specific remote.

Typical case: A Sony TV remote might send 0x10 for the “1” button, while a Samsung remote sends 0x80. The code is not the button label – it’s a hexadecimal number unique to the button + remote brand.

Action: Upload a simple IR decoder sketch (available in common libraries like “IRremote”) to your microcontroller. Open the Serial Monitor, press each button you want to use, and write down the codes. For example:

Up arrow → 0xFF629D

Down arrow → 0xFFA857

OK/Select → 0xFF02FD

Step 2: Map Button Codes to Servo Angles

Decide which button moves the servo to which angle. Standard servo angles are 0° to 180°.

Example mapping (using codes from Step 1):

Button 0xFF629D → Servo angle 0°

Button 0xFFA857 → Servo angle 90°

Button 0xFF02FD → Servo angle 180°

Step 3: Write the Control Code

Below is a generic code example that works with the popular IRremote library (version 3.x or later). Replace REMOTE_CODE_1, REMOTE_CODE_2, etc., with your actual codes from Step 1.

#include#include
const int IR_PIN = 11;
const int SERVO_PIN = 9;
IRrecv irrecv(IR_PIN);
decode_results results;
Servo myServo;
// Replace these with your remote's actual codes (hex values from Step 1)
const unsigned long CODE_ANGLE_0   = 0xFF629D;  // e.g., Up button
const unsigned long CODE_ANGLE_90  = 0xFFA857;  // e.g., Down button
const unsigned long CODE_ANGLE_180 = 0xFF02FD;  // e.g., OK button
void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();  // Start IR receiver
  myServo.attach(SERVO_PIN);
  myServo.write(0);     // Start at 0°
  Serial.println("Ready. Press buttons on your remote.");
}
void loop() {
  if (irrecv.decode(&results)) {
    unsigned long receivedCode = results.value;
    Serial.print("Received code: 0x");
    Serial.println(receivedCode, HEX);
    // Map received code to servo angle
    if (receivedCode == CODE_ANGLE_0) {
      myServo.write(0);
      Serial.println("Servo → 0°");
    } 
    else if (receivedCode == CODE_ANGLE_90) {
      myServo.write(90);
      Serial.println("Servo → 90°");
    } 
    else if (receivedCode == CODE_ANGLE_180) {
      myServo.write(180);
      Serial.println("Servo → 180°");
    }
    else {
      Serial.println("Unmapped button. Ignored.");
    }
    irrecv.resume();  // Wait for next signal
  }
}

Note: If your remote uses a different protocol (e.g., NEC, Sony, RC5), the library automatically detects it. The code above works for most consumer remotes.

Step 4: Test and Calibrate

1. Power the circuit (external servo power if needed).

2. Open Serial Monitor at 9600 baud.

3. Press a mapped button – the servo should move to the preset angle within 0.5 seconds.

4. If the servo jitters or doesn’t move, check:

Common ground connection.

Servo power supply capacity (minimum 500 mA for standard servos).

IR receiver is not exposed to direct sunlight or fluorescent light (these cause interference).

05Common Problems and Solutions (Real-World Cases)

Problem Most Likely Cause Verified Fix
Servo moves randomly when no button pressed IR receiver picks up noise from lights or screen Shield the receiver with black electrical tape,or add a 100µF capacitor between 5V and GND near the receiver
Some buttons work, others don’t The remote sends a “repeat code” (e.g., 0xFFFFFFFF) for held buttons Modify code to ignore repeat codes: if (receivedCode == 0xFFFFFFFF) return;
Servo moves only once then stops Servo power brown-out Use external 5V supply (2A recommended) with a large capacitor (470µF)
No signal detected at all Wrong IR receiver pin or missing library Double-check pin connection; install the latest IRremote library from a trusted repository

06Expanding the Project (Actionable Next Steps)

Core conclusion restated: A standard IR remote paired with a low-cost IR receiver and a microcontroller gives you precise, wireless servo control without any proprietary hardware.

Three actionable recommendations to strengthen your implementation:

1. Add multiple servos: Use an array of servo objects and assign different buttons to different servos. For example, button “1” controls servo A to 0°, button “2” controls servo B to 45°.

2. Implement smooth movement:Replaceservo.write(angle) with a loop that increments the angle step by step (e.g., from current angle to target angle in 1° increments with 15ms delay). This creates a professional, gradual motion.

3. Store button mappings in EEPROM: Write a small calibration routine that lets you learn new buttons without re-uploading code. This is especially useful if you lose your original remote and switch to another brand.

Final verification: Before deploying your project in a real application (e.g., remote-controlled door latch or robot gripper), test all button presses at least 50 times each. IR signals can be blocked by objects or bright light – always include a visual indicator (e.g., an LED that blinks when a code is received) to confirm the system is working.

Update Time:2026-04-19

Powering The Future

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

Mail to Kpower
Submit Inquiry
+86 0769 8399 3238
 
kpowerMap