Getting false reads with an IR sensor

Hi All,
I’ve built a very basic robot for a party, and for periods of time I want it to appear as though it doesn’t move (I’ve called this ‘Stealth mode’ in my code to make it sound cool), before being activated by a remote control which brings it back to life (it doesn’t matter which button is pressed). If a button isn’t pressed, then eventually ‘Stealth Mode’ times-out and we return to the main loop. I’ve written a function for this ‘Stealth mode’ and it largely works as intended, but it’s sometimes registering button presses that haven’t been made and interrupting the ForLoop. Code for the function below:

void stealth () {
  delay (100);
  Serial.println("Stealth Mode Started");
  for (int d = 0; d < stealthpausetime; d++) {
    if (irrecv.decode(&results)) // have we received an IR signal?
      Serial.println(results.value, HEX);
      irrecv.resume(); // Receive the next value
      Serial.println("Button Pressed!...");
  Serial.println("Stealth Mode Time Over");
  delay (10);

Does anyone have any thoughts on how to stop these ‘phantom presses’, or any idea what might be causing them?

Make a tiny sketch that only works with the IR receiver in order to verify that function.

We do not know how your button is wired up.

We do not have your complete code.

Also, post the entire code.

Apologies - complete code attached. The robot has two moving arms, a moving head and then LEDs for the eyes and mouth. It also has a passive buzzer to make robot type sounds. Not sure any of this is useful, but might help make sense of code. First section is just the robot initialising and finding end stops for the stepper motors.

IR code.txt (16.8 KB)

... probably of little value, but this is a video of the robot in action with some slightly older code, but principle is the same:

Video of the robot