Atomatic lihght

#define PIR_PIN D2


#define RELAY_PIN D1

void setup() {
  pinMode(PIR_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);   // relay OFF
}

void loop() {
  if (digitalRead(PIR_PIN) == HIGH) {
    digitalWrite(RELAY_PIN, H

IGH); // ON
} else {
digitalWrite(RELAY_PIN, LOW); // OFF
}
delay(300);
}

Welcome to the forum

Please confirm exactly which Arduino board you have

Do you have a question about the code ?

Pleased edit your first post and put all of the code in code tags

Good questions get good answers.

That's how your post should have appeared; thank you for trying, at least! Welcome to the forum!

Now, since you've asked no question, I have two:

  1. Is your posting in the correct forum category? Because it's pretty simple, needs nothing specific to an ESP32, and you're a newbie, I suspect this belongs in the programming category, but I may be wrong; so tell me,

  2. Do you have a question about your code? Or the circuit you didn't show us?

Thanks