Need help with my code (about ir remote stuff)

Hello everyone, pretty new to the forum so excuse me if i do something wrong. i am trying to make a security system in which if someone goes over the fence the alarm goes off. i want to be able to turn it on and off with an ir remote, i got all the stuff working except one thing. The turning on and off. If i press the key on the ir remote it only does the cycle for the security code once, and then it stops, i cant think of anything to fix it. The attachment is the code. And here is also my code

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
#include <IRremote.h>
int sensorIR = 4;
IRrecv irrecv(sensorIR);
decode_results codigo;
#define Button1 0xFFA25D
#define Button2 0xFF629D
#define Button3 0xFFE21D
const int relayPin = 2;
const int buzzPin = 3;
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distance;
void(* resetFunc) (void) = 0;
int IRstate;
int currentIR;
int lastIR;

void setup() {
pinMode(relayPin, OUTPUT);
long duration;
int distance;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzPin, OUTPUT);
pinMode(sensorIR, INPUT);
u8g2.begin();
Serial.begin(9600);
Serial.begin(9600);
irrecv.enableIRIn();

}

void loop() {
lastIR = currentIR;
Serial.println(codigo.value);
delay(1000);
if (irrecv.decode(&codigo)) {
currentIR = codigo.value;
Serial.println(codigo.value, HEX) ;
irrecv.resume();
Serial.println(codigo.value);

if (codigo.value == Button2 && lastIR == Button1) {
IRstate = 0;
}
if (codigo.value == Button1 && lastIR == Button1) {
IRstate = 1;
}

if (IRstate = 0) {
//lcd scherm gedeelte (doen met ir remote dat ie dan aan gaat en op het scherm laat zien dat ie aan is
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso28_tr); // choose a suitable font at fntlistall · olikraus/u8g2 Wiki · GitHub
u8g2.drawStr(45, 28, “OFF”); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display

}

//lcd scherm gedeelte (doen met ir remote dat ie dan aan gaat en op het scherm laat zien dat ie aan is
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso28_tr); // choose a suitable font at fntlistall · olikraus/u8g2 Wiki · GitHub
u8g2.drawStr(45, 32, “ON”); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display

if (IRstate == 1) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print(“Distance: “);
Serial.print(distance);
Serial.println(” centimeter”);
if (distance < 20) {
digitalWrite(relayPin, LOW);
noTone(buzzPin);
delay(50);
digitalWrite(relayPin, HIGH);
tone(buzzPin, 2000);
delay(50);
digitalWrite(relayPin, LOW);
delay(50);
digitalWrite(relayPin, HIGH);
delay(50);
digitalWrite(relayPin, LOW);
delay(50);
digitalWrite(relayPin, HIGH);
delay(50);
digitalWrite(relayPin, LOW);
delay(50);
digitalWrite(relayPin, HIGH);
delay(50);
digitalWrite(relayPin, LOW);
delay(50);
digitalWrite(relayPin, HIGH);
delay(50);
digitalWrite(relayPin, LOW);
delay(50);
digitalWrite(relayPin, HIGH);
delay(50);
delay(500);
}
if (distance > 20) {
digitalWrite(relayPin, HIGH);
noTone(buzzPin);
delay(1000);
}
}
}
}

security_metlamp_3.ino (3.41 KB)

Welcome to the forums. Please take a couple of moments and read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you. After you do that, you can go back and edit your post and insert those code tags around your code.

As for your code, the value from the IR needs to be of type 'long', not 'int' since an int can only hold up to 0xFFFF and your button values are much larger than that.