ESP32 C3 Super Mini - Motion Sensor

Learn how to detect motion with your ESP32 C3 Super Mini and HC-SR501 motion sensor. This beginner-friendly tutorial covers everything you need to build motion detection projects with ESP32 C3 Super Mini.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Motion Sensor

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×HC-SR501 Motion Sensor
1×Alternatively, AM312 Mini Motion Sensor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of HC-SR501 Motion Sensor

HC-SR501 Motion Sensor

The HC-SR501 is a PIR (Passive Infrared) sensor that detects motion by sensing changes in infrared radiation.

Key Features:

  • Detects human and animal movement automatically
  • Works with 5V power supply
  • Outputs digital signal (HIGH/LOW)
  • Adjustable sensitivity and time delay
  • Wide detection range (up to 7 meters)
  • Low cost and beginner-friendly

Common Applications:

  • Automatic light control systems
  • Security and intruder detection
  • Automatic door openers
  • Energy-saving devices
  • Smart home automation projects

HC-SR501 Motion Sensor Pinout

The HC-SR501 has a simple 3-pin interface for easy connections.

HC-SR501 Motion Sensor Pinout
  • VCC: Connect to 5V power supply
  • GND: Connect to ground (0V)
  • OUTPUT: Connect to ESP32 C3 Super Mini digital input pin - outputs LOW when no motion detected, HIGH when motion detected

Additional Components:

  • Detection Range Adjuster: Potentiometer to adjust sensing distance
  • Time Delay Adjuster: Potentiometer to set how long output stays HIGH after detection
  • Repeat Trigger Selector: Jumper to choose between single or repeatable trigger modes

How HC-SR501 Motion Sensor Works

The HC-SR501 detects motion by sensing changes in infrared radiation emitted by warm objects.

Detection Requirements:

  • Object must emit infrared radiation (like humans and animals)
  • Object must be moving or changing position

Detection Scenarios:

  • Detected: Person walking in sensor range
  • Detected: Animal moving nearby
  • Not Detected: Person standing completely still
  • Not Detected: Moving robot or vehicle (no infrared emission)

Important Notes:

  • The sensor detects motion, not presence directly
  • Stationary humans may not be detected even if present
  • Works best for detecting active movement

The video above demonstrates how the HC-SR501 motion sensor responds to movement in real-time.

Detecting the Presence of Humans

The HC-SR501 infers human presence based on motion detection rather than direct sensing.

Detection Logic:

  • Motion detected = Human likely present
  • No motion detected = Human likely not present

Practical Limitation:

  • If a person is present but not moving, the sensor won't detect them
  • This can cause false negatives in some applications

Why It's Still Popular:

  • Very affordable compared to other sensors
  • Works well for most practical applications
  • Good enough for automatic lighting, alarms, and energy-saving projects

ESP32 C3 Super Mini and HC-SR501 Motion Sensor

By connecting the motion sensor to ESP32 C3 Super Mini, you can create smart motion-responsive projects.

How It Works:

  • ESP32 C3 Super Mini pin reads digital input (HIGH or LOW)
  • Motion sensor OUTPUT pin sends signal to ESP32 C3 Super Mini
  • ESP32 C3 Super Mini code interprets the signal and triggers actions
  • You can control lights, alarms, or any device based on motion

Wiring Diagram

Connect the HC-SR501 motion sensor to your ESP32 C3 Super Mini following the diagram below.

  • Note: The HC-SR501 requires 5V power supply for reliable operation
The wiring diagram between ESP32 C3 Super Mini Motion Sensor

This image is created using Fritzing. Click to enlarge image

HC-SR501 Pin ESP32 C3 Super Mini Pin
VCC 5V
GND GND
OUTPUT D5

Initial Sensor Settings

Before using the HC-SR501, configure these settings for optimal performance.

ESP32 C3 Super Mini motion sensor initial setting
Setting Configuration
Detection Range Adjuster Fully screw clockwise (minimum range for testing)
Time Delay Adjuster Fully screw counter-clockwise (minimum delay)
Repeat Trigger Selector Position jumper as shown in image above

How To Program Motion Sensor

Follow these steps to read motion sensor data with ESP32 C3 Super Mini.

Step 1: Configure ESP32 C3 Super Mini Pin as Input

pinMode(PIN_TO_SENSOR, INPUT);

Step 2: Read the Sensor Output State

motion_state = digitalRead(PIN_TO_SENSOR);

Step 3: Detect Motion Start (LOW to HIGH)

prev_motion_state = motion_state; // store old state motion_state = digitalRead(PIN_TO_SENSOR); // read new state if (prev_motion_state == LOW && motion_state == HIGH) { // pin state change: LOW -> HIGH Serial.println("Motion detected!"); }

Step 4: Detect Motion Stop (HIGH to LOW)

prev_motion_state = motion_state; // store old state motion_state = digitalRead(PIN_TO_SENSOR); // read new state if (prev_motion_state == HIGH && motion_state == LOW) { // pin state change: HIGH -> LOW Serial.println("Motion stopped!"); }

ESP32 C3 Super Mini Code

This code monitors the HC-SR501 motion sensor and reports motion events.

What the code does:

  • Configures pin D5 as digital input for reading sensor data
  • Continuously monitors the motion sensor state
  • Detects when motion starts (LOW to HIGH transition)
  • Detects when motion stops (HIGH to LOW transition)
  • Outputs motion events to Serial Monitor
  • Ready for you to add custom actions (lights, alarms, etc.)
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-motion-sensor */ #define PIN_TO_SENSOR D5 // The ESP32 C3 Super Mini pin connected to OUTPUT pin of sensor int motion_state = LOW; // current state of pin int prev_motion_state = LOW; // previous state of pin void setup() { Serial.begin(9600); // Initialize the Serial to communicate with the Serial Monitor. pinMode(PIN_TO_SENSOR, INPUT); // set ESP32 C3 Super Mini pin to input mode to read value from OUTPUT pin of sensor } void loop() { prev_motion_state = motion_state; // store old state motion_state = digitalRead(PIN_TO_SENSOR); // read new state if (prev_motion_state == LOW && motion_state == HIGH) { // pin state change: LOW -> HIGH Serial.println("Motion detected!"); // TODO: turn on alarm, light or activate a device ... here } else if (prev_motion_state == HIGH && motion_state == LOW) { // pin state change: HIGH -> LOW Serial.println("Motion stopped!"); // TODO: turn off alarm, light or deactivate a device ... here } }

Detailed Instructions

  • New to ESP32 C3 Mini? Complete our Getting Started with ESP32 C3 Mini tutorial first to set up your development environment.
  • Upload the Code: Copy the code above and paste it into Arduino IDE
  • Select Your Board: Choose ESP32 C3 Super Mini from Tools > Board menu
  • Connect ESP32: Plug your ESP32 C3 Super Mini into your computer via USB
  • Upload: Click the Upload button in Arduino IDE to transfer the code
  • Open Serial Monitor: Click the Serial Monitor icon (top-right corner) or press Ctrl+Shift+M
  • Set Baud Rate: Select 9600 baud in Serial Monitor dropdown
  • Test Motion Detection: Wave your hand in front of the HC-SR501 sensor
  • Observe Results: Watch the Serial Monitor display motion events
  • Pro Tip: Start with minimum sensitivity and delay settings, then adjust the potentiometers to find your ideal detection range and timing.

Serial Monitor Output

When you move in front of the sensor, you'll see output like this:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Motion detected! Motion stopped! Motion detected! Motion stopped! Motion detected! Motion stopped!
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

Project Ideas

Here are some practical projects you can build with ESP32 C3 Super Mini and the HC-SR501 motion sensor.

  • Automatic Room Light: Turn lights on when motion detected, off after no motion
  • Security Alert System: Send notifications or trigger alarm when intruder detected
  • Energy Saver: Automatically power down displays or devices when no one is present
  • Smart Pet Feeder: Detect when your pet approaches and dispense food
  • Visitor Counter: Log the number of people entering a room or building
  • Halloween Props: Trigger scary sounds or moving decorations when someone approaches

Video Tutorial

Watch the video below for a visual walkthrough of this project.

Challenge Yourself

Take your ESP32 C3 Super Mini motion sensor skills to the next level with these challenges.

  • Easy: Add an LED that turns on when motion is detected and off when motion stops
  • Easy: Count and display the total number of motion events detected
  • Medium: Add a buzzer that sounds an alarm for 3 seconds when motion is detected
  • Medium: Use the sensor to control a relay that switches a desk lamp on/off
  • Advanced: Combine motion sensor with OLED display to show last detection time and date
  • Advanced: Create a smart security system that sends email alerts when motion detected at night

Language References

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!