tutorialspinouttools
Sensors · ESP32-C3

HC-SR501 PIR on OLED: Motion Detection

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

What it is: The HC-SR501 is the classic passive infrared (PIR) motion sensor — the white-dome sensor in burglar alarms and automatic lights. It detects the moving body heat of people and animals up to ~7 m. How it works: It watches for changes in infrared across its lens. When a warm body moves, OUT goes HIGH for a set hold time. It's purely digital — no analog reading. Wiring: PIR OUT -> GPIO10 (digital) PIR VCC -> 5V (needs 5V for its regulator) PIR GND -> GND OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5 Libraries: only "Adafruit SSD1306" and "Adafruit GFX Library". On screen / Serial: "MOTION!" while triggered, "idle" otherwise. Walk in front of it to trip it. Gotchas: The two orange trimmers set sensitivity (range) and time-delay (how long OUT stays HIGH); start both around mid-travel. Give it 30–60 seconds to settle after power-on. Its OUT is a clean 3.3V-safe HIGH. Set the jumper to "repeat/H" mode so it re-triggers while motion continues.

Circuit Diagram

HC-SR501 PIR on OLED: Motion Detection wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);

#define PIR 10                // OUT on GPIO10 (digital)

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  pinMode(PIR, INPUT);
}

void loop() {
  bool motion = digitalRead(PIR) == HIGH;

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("HC-SR501 PIR");
  display.setTextSize(2);
  display.setCursor(0, 26);
  display.println(motion ? "MOTION!" : "idle");
  display.display();

  Serial.println(motion ? "MOTION" : "idle");
  delay(120);
}
Browse all tutorials ESP32-C3 pinout Calculators