Remote control, Servos and Libraries

I'm new to remote control, and somewhat new to Arduino too.
I've tried to get the following code to work:

 #include <IRLibAll.h>
    #include <Servo.h> 
#define MY_PROTOCOL NEC
    #define RIGHT_ARROW   ff5aa5 //Move several clockwise
    #define LEFT_ARROW    ff10ef //Move servo counterclockwise
    #define SELECT_BUTTON ff38c7 //Center the servo
    #define UP_ARROW      ff18e7 //Increased number of degrees servo moves
    #define DOWN_ARROW    ff4ab5 //Decrease number of degrees servo moves
IRrecv myReceiver(2); //pin number for the receiver
    IRdecode myDecoder;
     
    Servo myServo;  // create servo object to control a servo 
    int16_t pos;         // variable to store the servo position 
    int16_t Speed;       // Number of degrees to move each time a left/right button is pressed
    uint32_t Previous;//handles NEC repeat codes
     
void setup() {
  // put your setup code here, to run once:
     myServo.attach(9);      // attaches the servo on pin 9 to the servo object 
      pos = 90;               // start at midpoint 90 degrees
      Speed = 45;              // servo moves 3 degrees each time left/right is pushed
      myServo.write(pos);     // Set initial position
      myReceiver.enableIRIn(); // Start the receiver
    } 


void loop() {
  // put your main code here, to run repeatedly:
   if (myReceiver.getResults()) {
           myDecoder.decode();
           if(myDecoder.protocolNum==MY_PROTOCOL) {
             if(myDecoder.value==0xFFFFFFFF)
               myDecoder.value=Previous;
             switch(myDecoder.value) {
                case LEFT_ARROW:    pos=min(180,pos+Speed); break;
                case RIGHT_ARROW:   pos=max(0,pos-Speed); break;
                case SELECT_BUTTON: pos=90; break;
                case UP_ARROW:      Speed=min(10, Speed+1); break;
                case DOWN_ARROW:    Speed=max(1, Speed-1); break;
                
             }
             myServo.write(pos); // tell servo to go to position in variable 'pos' 
             Previous=myDecoder.value;
           }
           myReceiver.enableIRIn();
        }
    }

Also see pic of project.

I'm trying to use just 5 buttons of the remote (see pic) and I want to simply use them as follows:
LEFT_ARROW: --- a 45 degree turn to the left
RIGHT_ARROW -----a 45 degree turn to the right
SELECT_BUTTON: --(or actually the red OK button). center position 90 degrees (this is the little 180 degree servo we're talking about)
UP_ARROW --- a little different, a 90 degree turn to the right
DOWN_ARROW a 90 degree turn to the left

I didn't use all the other buttons on the remote, (or put them in the code). I got the hex codes (ff5aa5, etc.) from one of the dump programs - that worked.

Several problems:
the RLibAll.h library --- That does not compile, it is a master zip file, and you can't use the 'load zip' file function.
You can't use the 'add file' function either. On closer inspection the 'ReadMe' file doesn't look like it goes with the Master file. Thought I got it from a reputable source.
I also get the error:
Error compiling for board Arduino/Genuno Uno
I also 'type' error on the receiver.
The code was real close to what I was after, but there are some things I'm definitely not sure of, or don't understand, for example:
Speed = 45 (and then it mentions 3 degrees ???

and the
Speed=min(10, Speed+1); (not sure how that's supposed to work)
Hope the above helps.
I'd like to get this working, because I need to do some other projects with remote control; but I'm wondering if it would be easier using potentiometers instead of fumbling with the codes and libraries.
Thanks

ardnew21:
Several problems:
the RLibAll.h library --- That does not compile, it is a master zip file, and you can't use the 'load zip' file function.

There is little point doing anything else until you fix that. Post a link to the webpage where you got the library.

You have not told us what is sending the commands.

...R

Hi,
I spent way more than 2-3 hours trying to get this to work, doing exactly that - looking at the documentation, etc.. If you look at the enclosed pic, you can see the exact receiver-transmitter combo that I'm using, (and the servo).
Long since lost the notes that had the web page with that particular library, but I think it was github.
I was wondering if someone knew of a library (used in a simialr remote setup like this), such as servo.h - that actually worked.
I've seen a few examples now where if it's just servo.h it works, if it's combined with some other libraies, then it doesn't. But that's just a beginner's observation.
Or if someone knew how to change those 2 lines of code - so that it worked.

I also get the error:
Error compiling for board Arduino/Genuno Uno

There is more than just that; you can scroll through the output window copy all text and paste it here.

Long since lost the notes that had the web page with that particular library, but I think it was github.

That's tough. We have NO idea what you downloaded, you have a little bit of an idea. Anyway, I went through the exercise of searching for that library and installing it; what I found might not be the same one though.

google irliball
first link IRLib2/IRLib2/IRLibAll.h at master · cyborg5/IRLib2 · GitHub
2)
two 'directories' up, GitHub - cyborg5/IRLib2: Library for receiving, decoding, and sending infrared signals using Arduino
3)
download (not to the arduino libraries directory)
4)
unzip

In the directory with the extracted library, find the manuals directory and open IRLibReference.pdf
The instructions state

Rather than a single library, this package consists of a total of five libraries each of which
must be in your arduino/libraries/ folder. So for example it should be installed as follows…

  • arduino/libraries/IRLib2
  • arduino/libraries/IRLibFreq
  • arduino/libraries/IRLibProtocols
  • arduino/libraries/IRLibRecv
  • arduino/libraries/IRLibRecvPCI

Find those 5 directories and copy them to the arduino's libraries directory; on a windows system C:\Users\yourusername\Documents\Arduino\libraries so the libraries directory looks like

+---libraries
|   +---some library
|   +---and another library
|   +---IRLib2
|   +---IRLibFreq
|   +---IRLibProtocols
|   +---IRLibRecv
|   +---IRLibRecvPCI
|   +---and yet another library

Now compile and fix the errors. In the sketch, your #defines need to be

#define RIGHT_ARROW   [color=red]0x[/color]ff5aa5 //Move several clockwise
#define LEFT_ARROW    [color=red]0x[/color]ff10ef //Move servo counterclockwise
#define SELECT_BUTTON [color=red]0x[/color]ff38c7 //Center the servo
#define UP_ARROW      [color=red]0x[/color]ff18e7 //Increased number of degrees servo moves
#define DOWN_ARROW    [color=red]0x[/color]ff4ab5 //Decrease number of degrees servo moves

I compiled for an Uno; compiling for Leonardo will throw errors and I think that I saw a note about that in the pdf.

Hi,
OK, I tried several things.
To Recap; 2 things going on here. First was the libraries, Second - trying to modify a sketch that uses something like 15 IR buttons to something that only uses 5 buttons on an IR remote control setup using an arduino uno.
On trying to get the 15 button sketch to verify and compile I got lots of errors
such as: -------------------->

fatal error IRLiball.h No such file exists

compilation terminated
exit status 1
Error compiling for board Arduino/Genuino Uno
library named Arduino-Remote-master already exists

exit status 1
Error compiling for board Arduino/Genuino Uno

Sorry, I can't copy from the output. I'm using Linux, not Windows btw.
Anyway, this is probably a good lesson for copying libraries and such off the web (i.e. not all zip files will necessarily install using the zip method)
The zip file I got was not the same as the one you mentioned, Just would not install using the zip method, also did not have the manuals, pdf you mentioned. However, it DID have the 5 libraries you mention. So I follwed your instructions, manually installing the 5 into the libraries directory. And voila, all 5 show up in the library manager, and running the code (the 5 button code - the original post), verifies and compiles without any errors.
Not sure about the 'Leonardo' part???? also, the hex codes - the original ones I got were just ff4ab5, etc. Why do you add the 0x in front of the hex codes? But again, that does verify and compile.

Now to the code itself:
If I'm trying for 2 buttons that turn the servo 45 degrees and 2 buttons that turn the servo 90 degrees and one button that centers the servo at 90 degrees (out of 180 degrees), then
the existing code:

Speed = 45;              // servo moves 3 degrees each time left/right is pushed

probably won't work, do you need a Speed1 and a Speed 2 one at 45 and one at 90
the 3 degrees in the comment is refferring to the original code (the 15 buttons all using the same 3 degrees

and in the void loop

switch(myDecoder.value) {
                case LEFT_ARROW:    pos=min(180,pos+Speed); break;
                case RIGHT_ARROW:   pos=max(0,pos-Speed); break;
                case SELECT_BUTTON: pos=90; break;
                case UP_ARROW:      Speed=min(10, Speed+1); break;
                case DOWN_ARROW:    Speed=max(1, Speed-1); break;
               
             }
             myServo.write(pos); // tell servo to go to position in variable 'pos'
             Previous=myDecoder.value;
           }
           myReceiver.enableIRIn();

How would that change??? especially the (10,Speed+1) and the (1,Speed-1) Have to change all 4 except the SELECT_BUTTON?????
This is c++ code right ????

Thanks

Not sure about the 'Leonardo' part????

You did not mention which Arduino you are using hence I mentioned the 'warning' about the Leonardo.

also, the hex codes - the original ones I got were just ff4ab5, etc. Why do you add the 0x in front of the hex codes?

I do not know how you got the hex codes; but if you had some test code that showed them, it's just the way they were presented by that code. Hex numbers in C/C++ start with 0x, it's just how it is.

Now to the code itself:
If I'm trying for 2 buttons that turn the servo 45 degrees and 2 buttons that turn the servo 90 degrees and one button that centers the servo at 90 degrees (out of 180 degrees), then

The Speed variable has nothing to do with the positions itself. If you just want the servo to turn clockwise / counterclockwise to fixed positions, you do not need Speed; you can just hard-code the values.

      switch (myDecoder.value) {
        case LEFT_ARROW:    pos = 45; break;
        case RIGHT_ARROW:   pos = 135; break;
        case SELECT_BUTTON: pos = 90; break;
        case UP_ARROW:      pos = 0; break;
        case DOWN_ARROW:    pos = 180; break;
      }

If it's something else that you want to achieve, you need to give a better description