Introduction
A PIR (Passive Infrared) motion sensor alarm is a simple yet effective way to detect motion in a given area. These sensors are widely used in security systems, automatic lighting controls, and other applications where motion detection is crucial. In this tutorial, we’ll walk you through creating a PIR motion sensor alarm circuit using TinkerCAD, an online 3D modeling and circuit design tool.
Materials Needed
Before we start, make sure you have the following components in TinkerCAD:
Breadboard
Arduino Uno
PIR Motion Sensor
Buzzer
LED
Resistor (220Ω)
Jumper Wires
Step 1: Set Up the Components
Breadboard and Arduino: Open TinkerCAD and start a new circuit project. Drag and drop an Arduino Uno onto the workspace. Next, add a breadboard to the setup.
PIR Motion Sensor: Place the PIR motion sensor on the breadboard. The sensor has three pins:
VCC (Power)
GND (Ground)
OUT (Signal)
Connect the VCC pin to the 5V pin on the Arduino, the GND pin to the GND pin on the Arduino, and the OUT pin to digital pin 2 on the Arduino.
Buzzer: Add a buzzer to the breadboard. Connect the positive leg (longer leg) of the buzzer to digital pin 8 on the Arduino and the negative leg to GND.
LED and Resistor: Place an LED on the breadboard. Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino via a 220Ω resistor. The shorter leg (cathode) should be connected to GND.
Step 2: Wiring Diagram
Ensure your wiring looks like this:
PIR Sensor:
VCC → 5V on Arduino
GND → GND on Arduino
OUT → Digital Pin 2 on Arduino
Buzzer:
Positive Leg → Digital Pin 8 on Arduino
Negative Leg → GND on Arduino
LED:
Anode (long leg) → Digital Pin 13 on Arduino (through a 220Ω resistor)
Cathode (short leg) → GND on Arduino
Step 3: Writing the Code
Now that the circuit is ready, let's write the code to make the alarm work.
int pirPin = 2; // PIR motion sensor connected to pin 2
int ledPin = 13; // LED connected to pin 13
int buzzerPin = 8; // Buzzer connected to pin 8
int pirState = LOW; // Start with motion sensor off
int val = 0; // Variable to store the PIR status
void setup() {
pinMode(pirPin, INPUT); // Set PIR sensor as input
pinMode(ledPin, OUTPUT); // Set LED as output
pinMode(buzzerPin, OUTPUT);// Set Buzzer as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
val = digitalRead(pirPin); // Read PIR sensor value
if (val == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn on LED
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
if (pirState == LOW) {
Serial.println("Motion detected!"); // Print message in serial monitor
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // Turn off LED
digitalWrite(buzzerPin, LOW); // Turn off buzzer
if (pirState == HIGH) {
Serial.println("Motion ended!"); // Print message in serial monitor
pirState = LOW;
}
}
}
Step 4: Simulate the Circuit
After writing the code, click the "Start Simulation" button in TinkerCAD.
The PIR motion sensor will detect movement. When motion is detected, the LED lights up, the buzzer sounds, and a message is printed to the serial monitor.
To stop the alarm, the PIR sensor must no longer detect any movement.
Step 5: Understanding the Code
The PIR sensor continuously checks for motion. When motion is detected, it sends a HIGH signal to pin 2.
When the Arduino receives a HIGH signal, it activates the LED and buzzer.
The system prints messages to the serial monitor to notify you of the motion status.
Conclusion
Congratulations! You've successfully created a PIR motion sensor alarm using TinkerCAD. This simple project introduces you to motion detection and how it can be integrated into various applications. You can further modify this circuit by adding more features, such as using a relay to control larger devices or integrating it with a notification system.
Exploring these kinds of projects will enhance your understanding of electronics and Arduino programming. Keep experimenting and building more complex projects as you grow your skills.
Want us to guide you through your project or make the project for you ?
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Kommentare