Arduino debug simple setup

Job ID: 38015830

Budget: $2 – $8 USD

The problem: The solonoid valve does not turn off. The voltage on mosfet module output goes from 4.2 V to 4.8 V when motion is detected. It does not goes to 0V and thereby closes the valve.
What have i done wrong?

I have a simple setup:
- Pir sensor AM312
- Nodemcu /ESP (powered by usb)
- Mosfet module IRF520
- Solonoid valve 4.5V
- External power supply connected to Mosfet 5V, 1A

I'm using the following code:

const int pirPin = D5; // PIR sensor pin
const int mosfetPin = D6; // Connect to the IN/Input terminal on the MOSFET module

void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
pinMode(mosfetPin, OUTPUT);
Serial.println("PIR Motion Sensor with Solenoid Valve Control");
}

void loop() {
int motionDetected = digitalRead(pirPin);

if (motionDetected == HIGH) {
Serial.println("Motion Detected - Activating Solenoid");
digitalWrite(mosfetPin, HIGH); // Send signal to the MOSFET module to activate the solenoid
delay(2000); // Keep solenoid active for 2 seconds
digitalWrite(mosfetPin, LOW); // Deactivate the solenoid
} else {
Serial.println("No Motion Detected");
}

delay(10000); // Wait for 10 seconds before rechecking
}