Hack star
Published © MIT

ESP32 – PIR motion sensor project on Wokwi - 2022

Wwitching to ESP32 won't be hard. ESP32 is almost 10 times more powerful than Arduino UNO #Arduino2022. Wokwi Emebdded systems Simulator

BeginnerProtip1 hour10,284
ESP32 – PIR motion sensor project on Wokwi - 2022

Things used in this project

Story

Read more

Schematics

ESP32 connection diagram for PIR sensor project

Code

ESP32 PIR sensor

Arduino
/*
   PIR sensor tester
*/

int ledPin = 12;                // choose the pin for the LED
int inputPin = 14;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

Credits

Hack star

Hack star

75 projects • 99 followers
an Arduino enthusiast and an electronic hobbyist

Comments