Appearance

Dark Light

Did You Know?

Conventional farmers use around 300 different pesticides to grow foods that are sold in supermarkets everyday.

Arduino Intrusion Detection System

Ever wondered if people have been snooping around your room/house while you were out? This Arduino intrusion detection system will detect people entering your space and send out a Tweet. The PIR motion sensor has a range of about 5 feet and is tripped by the presence of body heat.

Parts:


The prototype - Arduino with the Ethernet shield and PIR sensor. LED blinks when motion is detected. Also sends out a tweet. The choice of colors for the wires on the PIR is a bit confusing. The brown wire actually goes to ground, the black wire is the alarm pin. When the PIR sensor is inactive (open), the analog pin registers a value of ~ 900 on the Arduino. When it detects motion, the value is ~ 17.

Code


#include <Ethernet.h>
#include <Twitter.h>

byte mac[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
 192,168 , 0, 10 };
byte gateway[] = {
 192, 168, 0, 1 };
byte subnet[] = {
 255, 255, 255, 0 };

//your Twitter username/password
Twitter twitter("username:password"); 

char msg[32] ="Intruder Alert! ID: ";
//maps to the lowercase letters in ASCII
int lowerMin = 97;
int lowerMax = 122;

//PIR
int alarmPin = 0;
int alarmValue = 0;

int ledPin = 7;
int timer = 500;

void setup()
{ 
 Ethernet.begin(mac, ip, gateway, subnet);
 randomSeed(millis());
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
 pinMode(alarmPin, INPUT);

 digitalWrite(ledPin, LOW);
   
 delay(1000);   

 Serial.println("connecting ...");

}

void loop()
{
 //read PIR

 alarmValue = analogRead(alarmPin);
 Serial.println (alarmValue);

 if (alarmValue < 100){
   generateID();
   twitter.post(msg);
   Serial.println(msg);
   blink();

 } 
 delay(timer);
}

//generate some pseudo random ID
void generateID()
{
 for (i=20; i<=31; i++)
 {
   msg[i] = random(lowerMin, lowerMax);
 }
}

void blink() {
 for(int i=0; i<3; i++) {
   digitalWrite(ledPin,HIGH);
   delay(200);
   digitalWrite(ledPin,LOW);
   delay(200);
 }
}