PIR Motion Sensor
📖 Scenario: You want to create a simple security system that detects motion using a PIR motion sensor connected to an Arduino board. When motion is detected, an LED will turn on to alert you.
🎯 Goal: Build a program that reads input from a PIR motion sensor and turns an LED on when motion is detected, and off when no motion is detected.
📋 What You'll Learn
Use a variable called
pirPin to store the PIR sensor input pin number (2).Use a variable called
ledPin to store the LED output pin number (13).Create a variable called
motionDetected to store the PIR sensor reading.Set the LED pin as output and the PIR pin as input in the
setup() function.Read the PIR sensor value inside the
loop() function and store it in motionDetected.Turn the LED on if motion is detected (value HIGH), otherwise turn it off.
Print
"Motion detected!" or "No motion." to the Serial Monitor accordingly.💡 Why This Matters
🌍 Real World
PIR motion sensors are used in home security systems to detect movement and alert homeowners.
💼 Career
Understanding how to read sensors and control outputs is a key skill for embedded systems and IoT device programming.
Progress0 / 4 steps
