Controlling 3 Servos with an IR Remote

I'm using an IR remote to control three separate servos using 6 keys on the remote. I can't find any existing code for this and I'm only a beginner. I have tried editing some existing code to work with three servos but it doesn't work.

I have the single servo version working great, but just cant figure out how to change it to work with three.

Here's the code

#include <IRremote.h>      //must copy IRremote library to libraries
#include <Servo.h>
#define plus 0xE08D3DB2   //clockwise rotation button
#define minus 0x127FDDEE  //counter clockwise rotation button

int RECV_PIN = 3;       //IR receiver pin
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(9);     //servo pin
}

void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

    if (results.value == plus)
    {
      cwRotation = !cwRotation;      //toggle the rotation value
      ccwRotation = false;         //no rotation in this direction
    }

    if (results.value == minus)
    {
      ccwRotation = !ccwRotation;   //toggle the rotation value
      cwRotation = false;            //no rotation in this direction
    }
  }
  if (cwRotation && (val != 175))  {
    val++;                         //for colockwise button
  }
  if (ccwRotation && (val != 0))  {
    val--;                         //for counter colockwise button
  }
  servo.write(val);
  delay(20);          //General speed
}


If someone could give me some help, that would be great.

Hello jliddell4

Welcome to worldbest Arduino forum.

This is a nice project to get started.
Keep it simple and stupid firstly.
Run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.

Have a nice day and enjoy coding in C++.

don't you simply need to define 2 additional servos, as well as 2 additional pairs of IR codes?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.