Arduino expected initializer before 'detectsMovement'

Hi!

I require your help regarding a problem I’m encountering.

i want to make a motion sensor that ked will on when detect movement and I just copy and paste the coding from the internet for reference and why there is error expected initializer before ‘detectsMovement’ ? I try it on my friends laptop it work just fine but the led is not working and not showing anything in serial monitor


#define timeSeconds 10

// Set GPIOs for LED and PIR Motion Sensor
const int led = 26;
const int motionSensor = 27;

// Timer: Auxiliary variables
unsigned long now = millis();
unsigned long lastTrigger = 0;
boolean startTimer = false;

// Checks if motion was detected, sets LED HIGH and starts a timer
void IRAM_ATTR detectsMovement() {
  Serial.println("MOTION DETECTED!!!");
  digitalWrite(led, HIGH);
  startTimer = true;
  lastTrigger = millis();
}

this is the half of coding and the error on “void IRAM_ATTR detectsMovement() {” the error is expected initializer before ‘detectsMovement’

void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  // PIR Motion Sensor mode INPUT_PULLUP
  pinMode(motionSensor, INPUT_PULLUP);
  // Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
  attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);

  // Set LED to LOW
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

void loop() {
  // Current time
  now = millis();
  // Turn off the LED after the number of seconds defined in the timeSeconds variable
  if(startTimer && (now - lastTrigger > (timeSeconds*1000))) {
    Serial.println("Motion stopped...");
    digitalWrite(led, LOW);
    startTimer = false;
  }
}

and this is the rest of the coding.
Thank you so much in advance for your help!

Hello @bert and welcome to the RobotShop community,

What microcontroller are you using?

Is there any reason you are using IRAM_ATTR ?

Have you tried simply using:

void detectsMovement() {
  Serial.println("MOTION DETECTED!!!");
  digitalWrite(led, HIGH);
  startTimer = true;
  lastTrigger = millis();
}

Regards