# Can't figure out how to control servo with IR remote

**URL:** <https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403>\
**Category:** General Guidance\
**Created:** [December 30, 2025, 2:13am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403 "2025-12-30T02:13:00Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 7:22am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/41 "2025-12-30T07:22:06Z")

</div>

okay sorry it's flashing now i didn't realize it wasn't plugged into pin 12

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 7:22am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/42 "2025-12-30T07:22:54Z")

</div>

the values pop up on the serial monitor now

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 7:27am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/43 "2025-12-30T07:27:20Z")

</div>

- What IR code do you want to use to make the servo to go to 120° ?

- What IR code do you want to use to make the servo to go to 25° ?

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 7:29am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/44 "2025-12-30T07:29:01Z")

</div>

for 120° i would like 46, and for 25° i would like 15

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 7:30am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/45 "2025-12-30T07:30:14Z")

</div>

- Try this test sketch to see if the servo moves when the IR remote buttons are pressed.

```arduino
//================================================^================================================
//
// Servo.ino
//
// https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403
//
// LarryD
//
// Version YY/MM/DD Comments
// ======= ======== ========================================================================
// 1.00 25/12/29 Running code
//
//
//
//

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

//use IRremote library version 4.4.0 or newer
#include <IRremote.hpp>

#define DECODE_NEC

//================================================
#define LIGHTon 0x46 //Up Arrow
#define LIGHToff 0x15 //Down Arrow 

#define SERVOmax 120
#define SERVOmin 25

//================================================
const byte IR_RECEIVE_PIN = 12;
const byte heartbeatLED = 13; //Optional, toggles every 500ms

//================================================
//timing stuff
unsigned long heartbeatTime;
unsigned long checkRemoteTime;

// s e t u p ( )
//================================================^================================================
void setup()
{
  Serial.begin(9600);

  pinMode(heartbeatLED, OUTPUT);

  myservo.attach(8); // attaches the servo on pin 8 to the servo object

  //start the receiver
  IrReceiver.begin(IR_RECEIVE_PIN);

} //END of setup()

// l o o p ( )
//================================================^================================================
void loop()
{
  //======================================================================== T I M E R heartbeatLED
  //is it time to toggle the heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLED, digitalRead(heartbeatLED) == HIGH ? LOW : HIGH);
  }

  //======================================================================== T I M E R checkRemote
  //is it time to check for a new IR remote character ?
  if (millis() - checkRemoteTime >= 10ul)
  {
    //restart this TIMER
    checkRemoteTime = millis();

    checkRemote();
  }

  //================================================
  // other non blocking code goes here
  //================================================

} //END of loop()

// c h e c k R e m o t e ( )
//================================================^================================================
void checkRemote()
{
  //========================================================================
  //have we received an IR code ?
  if (IrReceiver.decode())
  {
    //determine which button was pressed
    if (IrReceiver.decodedIRData.command != 0)
    {
      byte byteRX = IrReceiver.decodedIRData.command;

      //we will ignore repeat codes
      IrReceiver.decodedIRData.command = 0;

      Serial.print("Code: ");

      //should we add a 0 prefix ?
      if (byteRX <= 0xF)
      {
        Serial.print("0");
      }

      Serial.println(byteRX, HEX);

      if(byteRX == LIGHTon)
      {
        myservo.write(SERVOmax);
      }

      else
      {
        myservo.write(SERVOmin);
      }

    } //END of if (IrReceiver.decodedIRData.command != 0)

    //restart IR code detection
    IrReceiver.resume();
  }

} //END of checkRemote()

//================================================^================================================

```

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 7:34am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/46 "2025-12-30T07:34:06Z")

</div>

it moves when i press the buttons now!

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 7:39am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/47 "2025-12-30T07:39:04Z")

</div>

- Does this schematic make sense to you ?

 ![2025-12-30_00-54-00](https://europe1.discourse-cdn.com/arduino/original/4X/1/f/7/1f7ec8bd0edbb7324118b05423a0c9909d824a1c.jpeg)

- Go though the sketch to see if you can decipher what is being done.

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 7:44am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/48 "2025-12-30T07:44:20Z")

</div>

from what i can tell the 6v conection is connected to ground and has a switch that's connected to the positive on the servo

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 7:50am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/49 "2025-12-30T07:50:42Z")

</div>

- Common hobby servos can be powered from 4.5V to 6V (some can work at7V).  
As mentioned do not power a motor from the Arduino 5V pin.  
Doing so can damage your Arduino.

- There must be a common GND connection between the Arduino and Servo power supply as seen in the schematic.

- The Heartbeat LED should toggle every 1 second.  
It gives us a rough indication our sketch is running and our code is non-blocking.  
This LED is optional but I like using it.  
The on board " **L**" LED will also toggle at a 1 second rate.

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 7:55pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/50 "2025-12-30T19:55:38Z")

</div>

So, I was able to get the code to work with a smaller servo motor, but I ended up having to get a 25g because the old one didn't have enough torque. When i plugged in the 25g servo it just kept turning without pressing any button. Do you have any ideas on how to fix that?

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 8:01pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/51 "2025-12-30T20:01:16Z")

</div>

![IMG_0125](https://europe1.discourse-cdn.com/arduino/original/4X/2/e/0/2e02aeb61ee536096e029efda97312d5cd2711de.jpeg)  
 ![IMG_0127](https://europe1.discourse-cdn.com/arduino/original/4X/5/d/8/5d81012cbe17d33f8e4fa8d5e23474939c270125.jpeg)

this is the new motor

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 8:01pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/52 "2025-12-30T20:01:25Z")

</div>

> [@meglowdude](#):
>
> it just kept turning without pressing any button

- Sounds like you purchased a **continuous** servo as discussed earlier in this thread.

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 8:03pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/53 "2025-12-30T20:03:19Z")

</div>

so i'm assuming i can't use this servo for the purpose that i intended it for?

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 8:07pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/54 "2025-12-30T20:07:24Z")

</div>

- For an ON/OFF application like this you need a **normal** servo one that goes from 0° to 180°.

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 8:09pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/55 "2025-12-30T20:09:24Z")

</div>

how can i differntiate the two before i purchase one? what should I be on the lookout for?

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 30, 2025, 8:18pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/56 "2025-12-30T20:18:18Z")

</div>

- If you see something like **Operating Speed : 0.13sec / 60 degrees (6.0V no load)** in the description, it indicates a 0 to 180 degrees servo.

- Most of the time, **if** the servo is continuous servo, it will state so.

- An MG996R is a good choice, you need to confirm the torque and dimensions.

Example:

 ![IMG_4335](https://europe1.discourse-cdn.com/arduino/original/4X/b/c/0/bc06d463de4ed1fa288bcb81fdc15e9096f2adb6.jpeg)

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 8:22pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/57 "2025-12-30T20:22:04Z")

</div>

do you think an mg90s would be good? I feel like I would need a smaller form factor

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 8:24pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/58 "2025-12-30T20:24:56Z")

</div>

never mind, I looked up the data sheet for both and I feel like i would run into the same issues as the sg90 i'm currently using

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 30, 2025, 8:29pm UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/59 "2025-12-30T20:29:39Z")

</div>

the hobby store i got it from didn't have anything that stated that it was continuous rotation on the packaging sadly, I should've done more research but I was just impatient

---

<div class="post-metadata">

**Author:** ![meglowdude](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/meglowdude/32/1253059_2.png) [@meglowdude](https://forum.arduino.cc/u/meglowdude)\
**Post date:** [December 31, 2025, 12:07am UTC](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403/60 "2025-12-31T00:07:32Z")

</div>

> [@meglowdude](#):
>
> do you think an mg90s would be good?

I ended up buying a 2 pack on amazon, I will keep you posted on that. Thank you so much for all of your help!

[Previous page](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403.md?page=2)

[Next page](https://forum.arduino.cc/t/cant-figure-out-how-to-control-servo-with-ir-remote/1422403.md?page=4)
