Introduction: Arduino Anti-thief System
Hey guys, today I will show you how to make an arduino anti-thief system.
Firstly, I am sorry about my grammar. I am 14 years old and I'm from Vietnam. This is my first project and instructable, too.
Step 1: Materials
- An Arduino Uno R3.
- An PIR sensor (Passive InfraRed sensor).
- A speaker (You use a small one).
- A LED light.
- A laptop to program the Arduino.
Step 2: Wire Connection
You connect like this:
- Connect GND pin of the sensor with GND pin of the Arduino.
- Connect VCC pin of the sensor with 5V pin of the Arduino.
- Connect OUT pin of the sensor with pin number 2 of the Arduino.
Step 3: Program Arduino Code
OK, you download arduino on website arduino.com then copy and paste this code:
int ledPin = 13;
int inputPin = 2;
int pirState = LOW;
int val = 0;
int pinSpeaker = 10;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
pinMode(pinSpeaker, OUTPUT);
Serial.begin(9600);
}
void loop()
{
val = digitalRead(inputPin);
if (val == HIGH)
{
digitalWrite(ledPin, HIGH);
On playTone(300, 160);
delay(150);
if (pirState == LOW)
{
Serial.println("Motion detected!");
pirState = HIGH;
}
}
else
{
digitalWrite(ledPin, LOW);
playTone(0, 0);
delay(300);
if (pirState == HIGH)
{
Serial.println("Motion ended!");
pirState = LOW;
}
}
}
void playTone(long duration, int freq)
{
duration *= 1000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
while (elapsed_time < duration)
{
digitalWrite(pinSpeaker,HIGH);
delayMicroseconds(period / 2);
digitalWrite(pinSpeaker, LOW);
delayMicroseconds(period / 2);
elapsed_time += (period);
}
}

Participated in the
Sensors Contest 2016
3 Comments
7 years ago
nice and cool one
7 years ago
good job
7 years ago
Cool security system.