Programming problem for remote control

Hi, I’m making a humanoid robot and I can move it by remote control.
But I find that pressing any key it is put into operation, and I want it to be a specific key!
Here’s the program I’ve done so far:


#include <Servo.h>
#include <IRremote.h>

Servo pA;
Servo pB;
Servo cA;
Servo cB;
Servo mA;
Servo mB;
Servo bA;
Servo bB;

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

int g90 = 90;
int posIN;

void setup()
{
  pA.attach(7);
  pB.attach(8);
  cA.attach(3);
  cB.attach(4);
  mA.attach(5);
  mB.attach(6);
  bA.attach(9);
  bB.attach(10);
  
  posIN = g90;
  
  Serial.begin(9600);
  
  irrecv.enableIRIn();
  
  Serial.println("HU 2");
  Serial.println("2012");
}

void loop()
{
  mB.write(30);
  pA.write(150);
  mA.write(150);
  if (irrecv.decode(&results))
  {
  Serial.println(results.value, DEC);
    irrecv.resume(); // Receive the next value
  //action of greeting
  //1
    pA.write(150);
    pB.write(90);
    cA.write(90);
    cB.write(90);
    mA.write(150);
    mB.write(30);
    bA.write(90);
    bB.write(90);
    delay(300);

//2  
    //pA.write(0);
    //pB.write(0);
    //cA.write(0);
    //cB.write(0);
    //mA.write(0);
    mB.write(60);
    //bA.write(0);
    bB.write(170);
    delay(1000);
    
  //3  
    //pA.write(0);
    //pB.write(0);
    //cA.write(0);
    //cB.write(0);
    //mA.write(0);
    mB.write(0);
    //bA.write(0);
    //bB.write(0);
    delay(1000);
  
  //4  
    //pA.write(0);
    //pB.write(0);
    //cA.write(0);
    //cB.write(0);
    //mA.write(0);
    mB.write(90);
    //bA.write(0);
    //bB.write(0);
    delay(1000); 
  }
}

__________________________________-

Thanks, Andreu

Moderator edit: [code][/code] tags added. (Nick Gammon)

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

You are printing some values, but then performing the action based on any key.

Add some if statements, to act only on a specific key. It would be easier if you used HEX, instead of DEC, to print the numbers - the values are shorter that way. Then, use 0xNNNNNNNN in the if statements.

PaulS,
I changed the DEC HEX, but I do not understand it 0xNNNNNNNN, you can specify it please!
I've tried other ways, but I fail ... =(
Thanks for helping hand XD

I changed the DEC HEX, but I do not understand it 0xNNNNNNNN, you can specify it please!

Not really, since you won't show any serial output.

Suppose, when you press button 4 on the remote, this shows up in the Serial Monitor:

A4B294F1

Then, you would add something like this to your code:

if(results.value == 0xA4B294F1)
{
   // Do whatever button 4 is supposed to trigger
}

Suppose button 5 output

36D1F4E7

Then, you could have code like:

if(results.value == 0xA4B294F1)
{
   // Do whatever button 4 is supposed to trigger
}
else if(results.value == 0x36D1F4E7)
{
   // Do the button 5 stuff
}

Paul thanks for the help! As I have arreclar!
Now is perfect XD
Thus as has been:

#include <Servo.h>
#include <IRremote.h>

Servo servo1A;
Servo servo1B;
Servo servo1C;

int receiver = 11;
IRrecv irrecv(receiver);
decode_results results;

int g90 = 90;
int posIN;

void setup()
{
  servo1A.attach(4);
  servo1B.attach(5);
  servo1C.attach(6);
  
  posIN = g90;
  
  Serial.begin(9600);
  
  irrecv.enableIRIn();
  
  Serial.println("AH-AX/22:");
  Serial.println("clicar 2 per iniciar seq. pota 1");
}

void loop()
{
  if (irrecv.decode(&results))
  {
       
  if(results.value == 0xFFF906)
  {
      servo1A.write(90);
      servo1B.write(90);
      servo1C.write(90);
      delay(300);
  
      //servo1A.write(90);
      servo1B.write(65);
      servo1C.write(25);
      delay(300);
  
      //servo1A.write(90);
      servo1B.write(25);
      servo1C.write(65);
      delay(300);
  }
  
  else
  {
  Serial.println("no hi ha ordre");
  }
  
  irrecv.resume(); // receive the next value
  }
}