IR sensor, interrupts and arduinos

I'm trying to make my arduino sleep till I receive an IR input. I followed this great post:

It works perfectly on my arduino uno.
The arduino sleeps and wakes up only when I hit the remote.
I used pin 12 in the UNO for the IR sensor.

On my arduino pro mini it wakes up every second (the same sensor ! not just the same sensor model, but the sensor itself is the same.)

If I block the ambient light from the sensor it stops waking up. so it is not some wiring bug.
I used pin 2 on the pro mini.

Is it possible that the pro mini is more sensitive ?
Or maybe pin 2 is more sensitive ?

Any ideas ?
I use the vs1838b sensor

As you didn't specify which pro mini you have (there are 5V and 3V3 versions of it, clocked differently) I guess you have the 3V3 version.

I use the vs1838b sensor

This sensor has a built-in 38kHz filter so ambient light shouldn't affect the sensor's output.

Do you have the possibility to attach a scope to the sensor's output?

Please post the code you used for the two Arduinos (it cannot be the same).

Unfortunately I do not have a scope.
Maybe because pin 2 is close to the tx-tr pins from some strange reason the communication with the computer makes him wake up ?

The code :

#include <IRremote.h>
#include <IRremoteInt.h>
#include <avr/sleep.h>
#include <avr/power.h>

#if defined(ARDUINO_AVR_UNO)
  int RECV_PIN = 12;
  
  const int motor_1_control_1 = 2;
  const int motor_1_control_2 = 3;
  const int motor_1_enabled = 4;
  
  const int motor_2_control_1 = 5;
  const int motor_2_control_2 = 6;
  const int motor_2_enabled = 7;
  
  #define INTERUPT_PIN PCINT4
  #define INTERUPT_PIN_RANGE_F PCIF0
  #define INTERUPT_PIN_RANGE_C PCIE0
  #define INTERUPT_MASK PCMSK0
  
  EMPTY_INTERRUPT (PCINT0_vect);
#endif

#if defined(ARDUINO_AVR_PRO)
  int RECV_PIN = 2;
  
  const int motor_1_control_1 = 10;
  const int motor_1_control_2 = 11;
  const int motor_1_enabled = 12;
  
  const int motor_2_control_1 = 9;
  const int motor_2_control_2 = 8;
  const int motor_2_enabled = 7;
  
  #define INTERUPT_PIN PCINT19
  #define INTERUPT_PIN_RANGE_F PCIF2
  #define INTERUPT_PIN_RANGE_C PCIE2
  #define INTERUPT_MASK PCMSK2
  
  EMPTY_INTERRUPT (PCINT2_vect);
#endif

const unsigned long NO_ACTIVITY_TIMEOUT = 1000;  // milliseconds

unsigned long lastActivity = 0;  // when we last woke

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  pinMode(motor_1_control_1, OUTPUT);
  pinMode(motor_1_control_2, OUTPUT);
  pinMode(motor_1_enabled, OUTPUT);
  
  pinMode(motor_2_control_1, OUTPUT);
  pinMode(motor_2_control_2, OUTPUT);
  pinMode(motor_2_enabled, OUTPUT);
  
  Serial.begin(9600);
  Serial.println("Starting");
  Serial.println(RECV_PIN);
  irrecv.enableIRIn(); // Start the receiver
}

unsigned long totalWakeTime = 0;
unsigned long totalSleepTime = 0;
unsigned long lastTime = 0;

void sleepFunc()
{
  // sleep if no activity for a while
  if (millis () - lastActivity >= NO_ACTIVITY_TIMEOUT)
  {
    Serial.print("Going to sleep, slept ");
    Serial.print(totalSleepTime);
    Serial.print(" Been awake ");
    Serial.println(totalWakeTime);
    
    Serial.flush ();  // wait for Serial to finish outputting
    Serial.end ();    // shut down Serial
    noInterrupts ();  // timed sequence coming up
    
 
    INTERUPT_MASK |= bit (INTERUPT_PIN); 
    PCIFR  |= bit (INTERUPT_PIN_RANGE_F);   // clear any outstanding interrupts
    PCICR  |= bit (INTERUPT_PIN_RANGE_C);   // enable pin change interrupts 
    
    totalWakeTime += millis() - lastTime;
    lastTime = millis();
    set_sleep_mode (SLEEP_MODE_STANDBY);  
    sleep_enable();
    
    byte old_ADCSRA = ADCSRA;
    // disable ADC to save power
    ADCSRA = 0;  
    power_all_disable ();  // turn off various modules
    interrupts ();
    sleep_cpu (); 
   
    totalSleepTime += millis() - lastTime;
    lastTime = millis();
    
    sleep_disable();
    power_all_enable ();   // enable modules again
    ADCSRA = old_ADCSRA;   // re-enable ADC conversion
    Serial.begin(9600);
    Serial.println("Waking up");
    lastActivity = millis ();
  }  // end of no activity for a couple of seconds
}

void loop()
{

  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    delay(50);
    irrecv.resume(); // Receive the next value
  }
  
  sleepFunc();
}

from some strange reason the communication with the computer makes him wake up ?

Any interrupt, including communication from the computer, will wake the Arduino.

jremington:
Any interrupt, including communication from the computer, will wake the Arduino.

As you can see above, the same code runs on the arduino uno and pro mini.
The arduino uno sleeps till I press a button on the remote.
The pro mini always wakes up.

I've tested them both while they are connected to the computer.

It took me several hours, but I found the problem.
Pin 2 is not PCINT19, It is PCINT18

Is there a good way to convert between pin number and the PCINT** thing ?

tautau123:
Is there a good way to convert between pin number and the PCINT** thing ?

There is a beautiful pinout diagram of the Atmega328 with signed Arduino pins.