Week 9 — Input Devices
Group Assignment
Click to access the group assignmentMotion Detection with PIR Sensor
Assignment Goal
This week's objective was to measure and interpret input signals from a sensor. I chose to use a PIR (Passive Infrared) sensor to detect motion using the XIAO ESP32-C3 board. The sensor outputs a digital HIGH signal when motion is detected and LOW otherwise.

Components Used
- Seeed Studio XIAO ESP32-C3
- PIR Motion Sensor
- Breadboard
- Jumper Wires
- Custom PCB I designed during the previous week
Wiring
PIR Sensor Pin | Connected To |
---|---|
VCC | 3.3V (or 5V if sensor requires it) |
GND | GND |
OUT | D9 (GPIO 9 on XIAO ESP32-C3) |
Code
The code reads the digital output of the PIR sensor and prints a message to the serial monitor depending on whether motion is detected.

#include <Arduino.h>
const int pirPin = 9; // PIR sensor output connected to GPIO 9
void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int motionDetected = digitalRead(pirPin); // Read the PIR output
if (motionDetected == HIGH) {
Serial.println("Motion detected");
} else {
Serial.println("No motion");
}
delay(1000); // Wait 1 second before the next read
}
Result
When the PIR sensor detects motion, "Motion detected" is printed to the serial monitor. When no motion is present, it prints "No motion". The 1-second delay prevents spamming the serial output and gives the sensor time to stabilize.
Conclusion / What I Learned
This assignment helped me understand how digital input devices like the PIR sensor communicate with microcontrollers. I learned how to configure a digital input pin and interpret its state changes through serial communication. I also gained practical experience in testing and debugging sensor behavior using the serial monitor, which is essential for verifying input device functionality. Furthermore, I explored how PIR sensors detect motion based on infrared radiation and how signal stability can be influenced by timing and sensor characteristics.
Download Design Files
Here is the Edge_Cuts
Here is the F_Cu