# Servo motor woth IR sensor not working

**URL:** <https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637>\
**Category:** Programming\
**Created:** [May 18, 2024, 10:53pm UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637 "2024-05-18T22:53:25Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 18, 2024, 10:53pm UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/1 "2024-05-18T22:53:25Z")

</div>

I was recently trying to make a circuit so that when I press a button on an infrared remote, it would make a servo turn, however the code isn't working. Heres the code:

```arduino
#include <Servo.h>
#include <IRremote.h>

#define Button_1 0xE718FF00
#define Button_2 0xAD52FF00
IRrecv IR(13); // Im using the pin 13
decode_results results;
int servoPin = 3; 
// Create a servo object 
Servo Servo1; 

void setup(){
  Serial.begin(9600);
  IR.enableIRIn();
  Servo1.attach(servoPin); // We need to attach the servo to the used pin number 
}

void loop(){
  if (IR.decode()){
        Serial.println(IR.decodedIRData.decodedRawData, HEX);
        IR.resume();
         switch(results.value) {
           case Button_1 : Servo1.write(45); break;
           case Button_2 : Servo1.write(0); break;
           
      } 
  }
}

```

This code decodes Hex just fine; however, when the correct hex codes are inputted, the servo doesn't move. Help!

---

<div class="post-metadata">

**Author:** ![bluejets](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bluejets/32/1013044_2.png) [@bluejets](https://forum.arduino.cc/u/bluejets)\
**Post date:** [May 18, 2024, 11:07pm UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/2 "2024-05-18T23:07:17Z")

</div>

Complete circuit diagram would be helpful ( NOT Fritzing thankyou).

---

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 18, 2024, 11:14pm UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/3 "2024-05-18T23:14:55Z")

</div>

here you go:

 ![Screenshot 2024-05-18 at 4.14.18 PM](https://europe1.discourse-cdn.com/arduino/original/4X/6/d/4/6d42fbd2a3e3b0c86898347ef52d26889dbd6848.png)

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 18, 2024, 11:30pm UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/4 "2024-05-18T23:30:59Z")

</div>

> [@2ticklemypickle](#):
>
> however the code isn't working.

Statement conveys no useful information.

Good job on properly posting code. 👍

It is a well known conflict between the Servo libraray and the IRremote library. Many people try the ServoTimer2 library. \>\>\>\>\>

> **[GitHub - nabontra/ServoTimer2: ServoTimer2 is a simple library for Arduino...](https://github.com/nabontra/ServoTimer2)**
>
> ServoTimer2 is a simple library for Arduino 1.x that does not use Timer1 in case of a conflict. - nabontra/ServoTimer2

---

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 18, 2024, 11:48pm UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/5 "2024-05-18T23:48:26Z")

</div>

thanks! trying now.

---

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 19, 2024, 12:17am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/6 "2024-05-19T00:17:35Z")

</div>

so, I tried to upload this to my uno r3, and it did not work. can you help me with the code?

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 19, 2024, 1:14am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/7 "2024-05-19T01:14:34Z")

</div>

Please post the latest version of your test code. I cannot help with code that I cannot see.

---

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 19, 2024, 1:42am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/8 "2024-05-19T01:42:01Z")

</div>

with servotimer2? or with servo the normal library

---

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 19, 2024, 1:43am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/9 "2024-05-19T01:43:21Z")

</div>

here you go:

```arduino
#include <ServoTimer2.h>
#include <IRremote.h>

#define Button_1 0xE718FF00
#define Button_2 0xAD52FF00
IRrecv IR(13); // Im using the pin 13
decode_results results;
int servoPin = 3; 
// Create a servo object 
ServoTimer2 Servo1;
void setup(){
  Serial.begin(9600);
  IR.enableIRIn();
  Servo1.attach(3); // We need to attach the servo to the used pin number 
}

void loop(){
  if (IR.decode()){
        Serial.println(IR.decodedIRData.decodedRawData, HEX);
        IR.resume();
         switch(results.value) {
           case Button_1 : Servo1.write(750); break;
           case Button_2 : Servo1.write(1500); break;
           
      } 
  }
}

```

---

<div class="post-metadata">

**Author:** ![bluejets](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bluejets/32/1013044_2.png) [@bluejets](https://forum.arduino.cc/u/bluejets)\
**Post date:** [May 19, 2024, 1:50am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/10 "2024-05-19T01:50:32Z")

</div>

750 might be beyond the range of the servo.  
Normal servo travel is 1000, 1500 and 2000.

Where is the 5v supply coming from?

What is the IR remote spec.?

---

<div class="post-metadata">

**Author:** ![2ticklemypickle](https://avatars.discourse-cdn.com/v4/letter/2/3d9bf3/32.png) [@2ticklemypickle](https://forum.arduino.cc/u/2ticklemypickle)\
**Post date:** [May 19, 2024, 2:23am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/11 "2024-05-19T02:23:15Z")

</div>

the 5v is coming from the arduino

---

<div class="post-metadata">

**Author:** ![bluejets](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bluejets/32/1013044_2.png) [@bluejets](https://forum.arduino.cc/u/bluejets)\
**Post date:** [May 19, 2024, 2:35am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/12 "2024-05-19T02:35:09Z")

</div>

If via the Arduino regulator, not a good idea for driving any servo.  
Which I asked for a "complete" circuit diagram.  
i.e. do you have a higher voltage to the Vin ????

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 19, 2024, 3:33am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/13 "2024-05-19T03:33:10Z")

</div>

It is important that we see a complete schematic as @bluejets requestes.

Do you have the latest versions of each libraray installed? If we are working from different versions it can cause confusion.

I cant work on this till tomorrow. Maybe more timely help will come along.

---

<div class="post-metadata">

**Author:** ![ArminJo](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@ArminJo](https://forum.arduino.cc/u/ArminJo)\
**Post date:** [May 19, 2024, 9:39am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/14 "2024-05-19T09:39:55Z")

</div>

> [@groundFungus](#):
>
> It is a well known conflict between the Servo libraray and the IRremote library

Where is it known???

---

<div class="post-metadata">

**Author:** ![ArminJo](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@ArminJo](https://forum.arduino.cc/u/ArminJo)\
**Post date:** [May 19, 2024, 9:43am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/15 "2024-05-19T09:43:17Z")

</div>

> [@bluejets](#):
>
> Normal servo travel is 1000, 1500 and 2000.

Sorry for being rude, but please do not tell **nonsense** to a beginner!  
see line 38 in Servo.h  
` default min is 544, max is 2400`

---

<div class="post-metadata">

**Author:** ![ArminJo](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@ArminJo](https://forum.arduino.cc/u/ArminJo)\
**Post date:** [May 19, 2024, 9:44am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/16 "2024-05-19T09:44:31Z")

</div>

> [@2ticklemypickle](#):
>
> `IRrecv IR(13);`

It is generally a bad idea to use the LED output pin for any input purpose.

---

<div class="post-metadata">

**Author:** ![ArminJo](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@ArminJo](https://forum.arduino.cc/u/ArminJo)\
**Post date:** [May 19, 2024, 9:47am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/17 "2024-05-19T09:47:58Z")

</div>

> [@2ticklemypickle](#):
>
> `Servo1.write(750);`

If you put this in setup(), does it work?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 15, 2024, 9:48am UTC](https://forum.arduino.cc/t/servo-motor-woth-ir-sensor-not-working/1261637/18 "2024-11-15T09:48:01Z")

</div>

Closed on November 15, 2024, 9:48am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
