Burglar alarm

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

I put together a burglar alarm that would make noise whenever a hand enters the house. The tone of the alarm is also controlled by the proximity of the intruder.

 

//Burglar alarm

//Created By: Anuj Tewari

//Date: 7th October, 2009

 

int potPin = 0;    // select the input pin for the potentiometer

int speakerPin = 7;

int maxVal = 700;

int val = 0;

 

void setup() {

pinMode(speakerPin, OUTPUT);

Serial.begin(9600);

Serial.println("ready");

}

 

void loop() {

digitalWrite(speakerPin, LOW);

 

val = analogRead(potPin);    // read value from the sensor

Serial.println(val);

 

if(val < maxVal)

{

for( int i=0; i<500; i++ ) {  // play it for 50 cycles

digitalWrite(speakerPin, HIGH);

delayMicroseconds(val);

digitalWrite(speakerPin, LOW);

delayMicroseconds(val);

}

}

}