ESC/Servo control from an IR Remote

Hi there and thanks for your time

What I want to be able to do is control several servos and a couple of brushless motors via my speed controllers via a IR remote.

What I want to know is if I can get the Arduino to get say… my motor to ramp up and down from half to full speed indefinitely with a click of the remote, then from another key on the remote to change to say zero to half speed indefinitely .
I need it to be able to do this with two independent motors (on separate escs of course) also.

I have got it working in so far as I can get it to control my motor with a fixed value and change to another value. So that part works. I can plumb in and code a second motor or a servo and that works also.

I can get the motor to pulse using a for loop, but cannot seem to get the Arduino to break out of the loop. A while loop works, but only for as many reps as I ask it too and I need it to be for a long as there is not another button press on the remote.

I only started playing with this a week ago and the first part came together so quickly I thought I was onto a winner(80% of the work takes 20% of the time). Bar the part I’m stuck on it was all go on night one.

Here is a version (I have many), that shows the approach I have been using.
You can see in the Forward key section (I had a lot of keys plumbed in to try things and had to label them so I could see the breaks in the case’s easier), I remed out a line trying to get it to look at input as part of the loop. I also tried getting it to poll the results value as part of the loop and looking at the (results.value) as a way out, but could not get that to happen either.

#include "IRremote.h"
#include <Servo.h>
int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11
int servoPin = 9;
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'
Servo servo;

void setup()   /*----( SETUP: RUNS ONCE )----*/
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver

  servo.writeMicroseconds(1100); // send "stop" signal to ESC.
  delay(1000); // delay

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
  if (irrecv.decode(&results)) // have we received an IR signal?
    irrecv.resume(); // receive the next value
}/* --(end main loop )-- */

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
// describing Remote IR codes
  switch (results.value)
    //------------------------------------------------------Forward key
    case 0xFF629D: Serial.println(" FORWARD");
        int move = 0;
        for (move = 65; move <= 120; move += 1)
        { servo.write(move);
          if (move > 99) {
            move = -50;
            //if (irrecv.decode(&results) != 0xFF629D) break;
    //------------------------------------------------------Key 0
    case 0xFF6897: Serial.println(" move2");
      int move2;
      servo.write (move2);
    //------------------------------------------------------zero throttle - stop
    case 0xFF9867: Serial.println(" stop");
      int signal = 1100; // Set signal value, which should be between 1100 and 1900
      servo.writeMicroseconds(signal); // Send signal to ESC.
  }// End Case
  delay(500); // Do not get immediate repeat
//END translateIR
/* ( THE END ) */

I’m now of the opinion my approach is wrong.
I did attempt to run the whole thing as a for loop and get the contents of the case’s to change variables in the loop…Nope!

If I only wanted to the motors to run at fixed speeds assigned to keys or pulse for a set number or reps - I would be done.

Apart form getting a similar thing to happen on an xBox controller with Glovepie - I have not touched any code since some Q++ playing with Quake…that’s quite some time ago(HTML doesn’t count)!

Thanks for looking

I think that you may have a conflict between the IRremote and servo libraries. I believe that they both try to use the same timer. (library conflict)

The IRLib library seems to work with Servo as shown on this page.


Thanks for your reply - I will have a look into that. I have spotted another couple of threads that may have some alternate methods of breaking a loop also

There is no need for a for loop to ramp up and down the motor RPM. Just keep track of the current PWM signal (current RPM) and keep track of whether you need to increase or decrease the RPM. For instance, you would have a variable, say, RPM. This would be updated every time the main loop executes and would increase or decrease based on your state. You would then write that value to the ESCs.

Again, there is NO need for a for loop to ramp up or down the motor without missing key presses. Just keep from implementing blocking loops.

Thank you! I will have a play with that right now.