# control servo without the librery

**URL:** <https://forum.arduino.cc/t/control-servo-without-the-librery/469092>\
**Category:** Programming\
**Created:** [July 9, 2017, 12:39am UTC](https://forum.arduino.cc/t/control-servo-without-the-librery/469092 "2017-07-09T00:39:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![omega4586](https://avatars.discourse-cdn.com/v4/letter/o/b5ac83/32.png) [@omega4586](https://forum.arduino.cc/u/omega4586)\
**Post date:** [July 9, 2017, 12:39am UTC](https://forum.arduino.cc/t/control-servo-without-the-librery/469092/1 "2017-07-09T00:39:15Z")

</div>

hello,  
i try to build an rc car using arduinos and 433Mhz module for the direction the car use a servomotor, in the code i used radiohead RH\_ASK.h for the 433 modules and Servo.h to drive the servo, after compiling the ide is show an error code after i searched on google i found that the RH\_ASK.h and Servo.h have a conflict, they both use timer1 so i desired to not use servo.h here is my code :

```cpp
#include <RH_ASK.h>
#include <SPI.h> 
RH_ASK driver;

void setup()
{
    Serial.begin(9600);  // Debugging only
    if (!driver.init())
        Serial.println("init failed");
        pinMode(9, OUTPUT);
        
}

void loop()
{
int b;
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
  uint8_t buflen = sizeof(buf);
  if (driver.recv(buf, &buflen))
          {
          if((int)buf[1]==66)
              {
                b=(int)buf[0];
                d=map(b, 0, 255, 120, 180);       
                Serial.println(d*10);

              } 
}  

            digitalWrite(9, HIGH);
            delayMicroseconds(d*10);
            digitalWrite(9, LOW);
            delayMicroseconds(20000-d*10);
  
}

```

the receiver work fine, i get the correct value on the serial monitor but the servo go crazy, and when i test the servo code alone it work :

```cpp
void setup(){
pinMode(9, OUTPUT);
void loop(){ 
            int d=150;
            digitalWrite(9, HIGH);
            delayMicroseconds(d*10);
            digitalWrite(9, LOW);
            delayMicroseconds(20000-d*10);
}

```

the servo goes to 90 deg  
can someone please help me ?

---

<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:** [July 9, 2017, 1:01am UTC](https://forum.arduino.cc/t/control-servo-without-the-librery/469092/2 "2017-07-09T01:01:27Z")

</div>

There is an alternative servo library that uses timer 2. It is the [ServoTimer2 library.](https://github.com/nabontra/ServoTimer2)

---

<div class="post-metadata">

**Author:** ![omega4586](https://avatars.discourse-cdn.com/v4/letter/o/b5ac83/32.png) [@omega4586](https://forum.arduino.cc/u/omega4586)\
**Post date:** [July 9, 2017, 1:03am UTC](https://forum.arduino.cc/t/control-servo-without-the-librery/469092/3 "2017-07-09T01:03:37Z")

</div>

thank you man i will try it and feedback

---

<div class="post-metadata">

**Author:** ![omega4586](https://avatars.discourse-cdn.com/v4/letter/o/b5ac83/32.png) [@omega4586](https://forum.arduino.cc/u/omega4586)\
**Post date:** [July 9, 2017, 2:46am UTC](https://forum.arduino.cc/t/control-servo-without-the-librery/469092/4 "2017-07-09T02:46:42Z")

</div>

it worked perfectly, thank you another time.

---

<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:** [May 5, 2021, 10:37pm UTC](https://forum.arduino.cc/t/control-servo-without-the-librery/469092/5 "2021-05-05T22:37:29Z")

</div>

Closed on May 5, 2021, 10:37pm UTC


