Need help with programming motion sensor (PIR) arduino project

Hello!
I need help with one of my arduino projects. I want to fade LED by using 3 PIR sensors. FIRST PIR sensor lights the LED up, SECOND PIR sensor fades the LED brightness to 50% and the LAST PIR sensor fades the LED 25%. I tryed to use val = digitalRead(inputpin) and then made if statment if(val=HIGH) analogWrite(led, test(50%)). It works but not correctly it won't change it instantly it starts to flick between 100% and 50% and then suddenly it changes to 50%.

Post your complete code!

And circuit diagram, and sketch of how these sensors are aligned and which is triggered when (especially overlapping areas can cause trouble if not accounted for).

int led = 11;
int sensorPin = 2;
int sensorPin2 = 4;
int val = 0;
int val2= 0;
int pirState = LOW;

void setup() {

pinMode(led, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(sensorPin, INPUT);
digitalWrite(led, LOW);
Serial.begin(9600);
}

void loop() {

val= digitalRead(sensorPin);
if (val == HIGH) { // check if the input is HIGH
digitalWrite(led, HIGH);
Serial.print("sensor: ");Serial.println(val);

}
val2= digitalRead(sensorPin2);

if (val2 == HIGH)

{
analogWrite(led, 64);
Serial.print("sensor2: ");Serial.println(val2);
}

}

You have two sensors that do something with your led independently and without taking the other sensor into account. That's a recipe for weird effects when both sensors are triggered at the same time.

so i need to save old value and with other sensor i need to save new value? or what?

Something like that - whatever you want to do with it.

Just start writing down for yourself what you want to happen when sensor 1 is activated while sensor 2 is not activated, when sensor 1 is activated while sensor 2 is activated already, etc.

Then based on that write your code - probably a series of if/else if statements.

Learn to use code tags! (that's the </> button in the editor)

pinMode(sensorPin, INPUT);
 pinMode(sensorPin, INPUT);

Setting the pinMode twice was probably not your intention.

You shouldn't mix digitalWrite() and analogWrrite() on the same pin. Although it works technically it's often misleading for the beginner to understand what happens behind.