onboard LED and motion detector

I need some code for a motion detector to turn on the onboard LED.

Here you go:

void loop()
{
   if (getMotionState() == DETECTED) {
      turnLEDOn();
   } else {
      turnLEDOff();
   }
}

I'm new to arduino the does not work.

I'm testing a HC-SR501 motion detector.

If I upload to a nodemcu v3 it randomly kernel panics my macbook air. If does not turn on the onboard LED or print to the serial monitor.

It work on my Uno.

int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;
int val;

/////////////////////////////

//SETUP
void setup(){
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}

////////////////////////////
//LOOP
void loop(){

  val = digitalRead(pirPin);
  
  if(val == HIGH)
  {
    Serial.println(" HIGH");
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else
  {
    digitalWrite(LED_BUILTIN, LOW);
    Serial.println(" LOW");
  }

  delay(2000);

}

Have a look at How to use the forum. We are NOT a code writing service!

If you want the code written for you, go here. But don't be surprised people want to get some money for it.