How to control Servo motor precisely above 180° ? [Solved]

Hi there !

I am currently using a Servo PDI-6225MG-300 which can rotate up to 295° I send(through Wi fi) a value between 0 to 295 which is the value of the angle (value called val).

#include <Servo.h>

#include <SPI.h>

#include <RF24.h>
#include <RF24_config.h>
int msg[1];
int val = 0;
RF24 radio(5, 10);
const uint64_t pipe = 0xE9E9F0F0E1LL;
Servo myservo;

void setup() {

  radio.openReadingPipe(1, pipe);


void loop() {
  if (radio.available()) {          
    bool done = false;              
    while (!done) {
      done =, 2);
      val = msg[0];
      val = map(val, 0, 295, 0, 180);

But I have a big problem, I can’t really control it precisely. He is achieving the 295° rotation when the value reach 180 so I tried to “map” the value but it doesnt work.

Is it possible to control it percisely ?
Is it because of the Servo Library which can only control between 0 to 180° ?
What am I doing wrong ?

Ps: spec of the servo

Brand Name: JX Servo
Item Name: PDI-6225MG-300 Degree
Max Angle: 295°
Dead Band: 4μs
Maximum Pulse Width: 500-2500us (for control board)
Motor: Iron core
Voltage range: 4.8V-6.6V
Speed (4.8V): 0.25 sec / 60 degree
Speed (6V): 0.21 sec / 60 degree
Torque (4.8V): 19.9
Torque (6V): 25.3
Size: 40.5 x 20.2 x 38mm
Weight: 62g
Cable: JR 265 mm
Bearing: 2BB
Output Teeth: 25T (Futaba Universal)

Thx in advance !


I tried to "map" the value but it doesnt work.

What doesn't work? What did you expect it to do and how does the actual result differ from that expectation?

Edit - Hit CTRL-T to autoformat your code. It makes it easier to read and understand.
Also, consider using writeMicroseconds() instead of write() any time you are concerned about accuracy.
write simply maps the 0-180 parameter to the microseconds value and passes that in to writeMicroseconds.

Hi, what do not work is that it is still not precise.

Edit, sorry for my bad code presentation :frowning: ok i’ll try it but i’m not sure to understand. Should I transform the value in micro second ?

Hi, what do not work is that it is still not precise.

I am going to ask you to describe this better.
What about its behavior makes you think that it is not precise?

And, yes, I would switch to writeMicroseconds. It should be easy. You just need to know the microsecond range that the attach used. Since you used the single parameter attach method, it used the default min and max of 544 and 2400.

I think that only 2 lines need to change.
Your map should be like this:

val = map(val, 0, 295, 544, 2400);

and your servo.write should change to:


It Worked ! Thank you !

You totally understood the problem, now it's very precise ! I'm really sorry for the bother.

Have a nice day !

Thank you !