Pushbutton wont work in my project?

Hello, I am using a servo to turn a light switch on and off with the help of a IR Remote, but i tired to add a pushbutton as an OR option so im not stuck using just the IR Remote incase I lose it. The code compiles but does not work. I can control with the IR Remote but not the buttons.

Here is the code:

#include <IRremote.h> //must copy IRremote library to arduino libraries
#include <Servo.h>
#define on 0xffa25d //clockwise rotation button
#define off 0xff629d //counter clockwise rotation button

int RECV_PIN = 2; //IR receiver pin
Servo servo;
int val; //rotation angle
bool cwRotation, ccwRotation; //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
servo.attach(9); //servo pin
pinMode(4, INPUT);
pinMode(5, INPUT);
}

void loop()
{

if (irrecv.decode(&results)) {
String s = String(results.value, HEX);
if(s != "ffffffff"){
Serial.println(s);
}
irrecv.resume(); // Receive the next value

if (results.value == on || digitalRead(4) == LOW)
{
cwRotation = !cwRotation; //toggle the rotation value
ccwRotation = false; //no rotation in this direction

}

if (results.value == off || digitalRead(5) == LOW)
{
ccwRotation = !ccwRotation; //toggle the rotation value
cwRotation = false; //no rotation in this direction
}

}
if (cwRotation && (val != 135)) {
val++; //for colockwise button
}
if (ccwRotation && (val != 0)) {
val--; //for counter colockwise button
}
servo.write(val);
delay(2); //General speed

}

Do you have pull-up resistors on those inputs? If not, try INPUT_PULLUP as the mode.

Do you have a wiring diagram of your setup?

Sadly I don't have a wiring diagram. It a regular resistor. I just tried what you said and it gave me the same result. I will make a diagram now

Actually, I think I see the problem. This is where posting code with code tags helps clarify things.

You've got your button checks embedded within the logic for receiving an IR message.

If you don't receive an IR message, you don't check the buttons.

how can I fix that? I'm new to Arduino. I can do basic things but have never tried anything like this lol

Here is the wiring diagram

x3xplosiiv3x_:
how can I fix that? I'm new to Arduino. I can do basic things but have never tried anything like this lol

Have a look at the code here. I can't vouch for your logic and it appears there may be some "gotchyas" in there, such as pressing a button twice may have unintended consequences because you just '!' a variable upon a button press. I didn't devote a lot of time to digging into it. So keep that in mind. But this basically separates out the IR and button press functions.

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define on 0xffa25d   //clockwise rotation button
#define off 0xff629d //counter clockwise rotation button

#define ON_BUTTON               4   //pin 4 is 'on' input
#define OFF_BUTTON              5   //pin 5 is 'off' input
#define MOTOR_INTERVAL          2   //mS
#define BUTTON_CHECK_INTERVAL   20  //mS

int RECV_PIN = 2;       //IR receiver pin
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(9);     //servo pin
  pinMode(ON_BUTTON, INPUT);
  pinMode(OFF_BUTTON, INPUT);
}

IR_Receive()
{
    if (irrecv.decode(&results)) 
    {
        String s = String(results.value, HEX); 
        if(s != "ffffffff")
        {
            Serial.println(s);
        }//if
        
        irrecv.resume(); // Receive the next value

        if( results.value == on )
        {
            cwRotation = !cwRotation;      //toggle the rotation value
            ccwRotation = false;         //no rotation in this direction
      
        }//if

        if (results.value == off)
        {
            ccwRotation = !ccwRotation;   //toggle the rotation value
            cwRotation = false;            //no rotation in this direction
        }//if
    
    }//if
    
}//IR_Receive

void Check_Buttons()
{
    static unsigned long
        buttoncheckTime = millis() + BUTTON_CHECK_INTERVAL;

    if( millis() < buttoncheckTime )
        return;

    buttoncheckTime = millis() + BUTTON_CHECK_INTERVAL;
    if( digitalRead(ON_BUTTON) == LOW )
    {
        cwRotation = !cwRotation;      //toggle the rotation value
        ccwRotation = false;         //no rotation in this direction
      
    }//if

    if( digitalRead(OFF_BUTTON) == LOW)
    {
        ccwRotation = !ccwRotation;   //toggle the rotation value
        cwRotation = false;            //no rotation in this direction
    
    }//if
    
}//Check_Buttons

void ProcessMotor( void )
{
    static unsigned long
        motorInterval = millis() + MOTOR_INTERVAL;

    if( millis() < motorInterval )
        return;

    motorInterval = millis() + MOTOR_INTERVAL;
    
    if (cwRotation && (val != 135))  
    {
        val++;                         //for colockwise button
    }
    
    if (ccwRotation && (val != 0))  
    {
        val--;                         //for counter colockwise button
    }
    servo.write(val);
    
}//ProcessMotor

void loop() 
{
    IR_Receive();
    CheckButtons();
    ProcessMotor();

}//loop

ok, thank you!