R/C servo control

I am a complete noob, and i currently have a robot in which i can only control four servos with. Can somebody write me some code to to recieve information from the reciever, convert it into servo-friendliness, and output it to the servo? i know C++, a bit of Java, BASIC, and i can understand most of what is happening in C. I have looked EVERYWHERE, but can't find anything that is just straight up code which i can use. Help please

Can somebody write me some code to to recieve information from the reciever

You have THE receiver. Cool. Could I borrow THE receiver for a few minutes? Please.

ummmmm, it's a Hitec reciever, HFD-08RD

Oh, good, you can take a hint. :)

Now, how is it connected to the Arduino?

i know C++

Then you should have no problem writing a Arduino sketch to perform what you want, as the arduino is programmed with C/C++ gcc compiler.

I don’t think you will ever just find a program on the web that you can simply cut and paste to perform exactly what you want with exactly what hardware setup you have. Also it’s very unlikely that someone is going to write you such a customized sketch for free. One normally obtains an Arduino knowing they will have to learn how to write the sketches they need for their projects. Certainly if you have some programming backround, your learning curve should be short, and once you have some code to post here there is lots of help if it’s not working correctly.


well i know programming, not electrical engineering. In other words, i don't know exactly how all of the components work, so I can edit code to some degree, but i don't know about how to convert the output of the reciever to something that a servo can understand.

and the arduino is connected to the computer with the usb connection. Also, it is a bit of an overstatement saying that i KNOW C++, i am very familiar with it and can write a bunch of things, but its not like i know everything about it. And ALL help is very appreciated.

and the arduino is connected to the computer with the usb connection.

And the relevance of this is?

Presumably the hard part will be interpreting what the RC controller is sending. Making the servo do something is easy.

So, is the RC controller connected to the Arduino?

You, sir, are very sarcastic. i misunderstood the question, yes, it is connected to the arduino. indirectly, through the use of the bread board. and what you said is the problem i am having. i was able to get the servo to jitter and respond to the remote controller such that it wouldn't really turn at all, but i could hear the difference. considering that this isn't chat, just disregard the last sentance if it is irrelevant. i just mentioned it to show that i know how to hook it up.

if you want some code, i just took a shot in the dark with the code here:

#include <SoftwareServo.h>

SoftwareServo myservo1;

int ch1 = 2;

unsigned long ch1v;

void setup()

pinMode(8, INPUT);//the reciever

//This is the part that i require help with
void loop()
ch1v = pulseIn(ch1, HIGH);


Well pulseIn returns a long variable, that value equal to the pulse duration in microseconds, which from your receiver should be a value between 1000 and 2000. You are then passing it to the servo.write() command that expects and int of 0-180 degree value. You need to do a little coding between those two operations, perhaps with a map() function. There are examples in the servo library:



I see. so that would mean that the values from the reciever are directly proportional to that of the degrees of rotation? so, would it be

variable = map(ch1, 1000, 2000, 0, 180); i'll try that now, thanks

So i tried it and there was no response to the controller.

Does anybody have any other suggestions? My ENTIRE project has ceased to move forward because of this seemingly simple problem.

IT WORKS!!!! ok, so for all people that had the same question as i did, use pulseIn() and then map that value, which should be from 1 to 2 ms, to 0-180. Then use that value in in write() and you should be set. the only thing that i am experiencing now is a lot of jitter and a couple of bugs, so the correct version of what i just said might be a little different, values and all.

Below is some code I use to test my servos using the arduino. If the pulsein produces a number between 1000 and 2000, you might could use the writeMicroseconds function.

// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-21"); // so I can keep track of what is loaded

void loop() {

  while (Serial.available()) {
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray); 
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180