MOTION ALARM RCWL-0516

Motion sensor RCWL

int speaker = 11;

#define wait 1

#define time 100

int freq = 0;

int ip = 8;

int val = 0;

int led = 13;

void setup()

{

Serial.begin(9600);

pinMode(speaker, OUTPUT);

pinMode (ip, INPUT);

pinMode (led, OUTPUT);

}

void loop()

{

val = digitalRead(ip);

Serial.println(val, DEC);

if(val >0)

{

digitalWrite(led, HIGH);

digitalWrite(speaker, HIGH);

for (freq = 500; freq < 3000; freq += 10)

{

tone(speaker, freq, time);

delay(wait);

}

for (freq = 3000; freq > 500; freq -= 10)

{

tone(speaker, freq, time);

delay(wait);

}

for (freq = 500;

freq < 3000;

freq += 10) //

{

tone(speaker, freq, time);

delay(wait);

}

for (freq = 3000;

freq > 500; freq -= 10)

{

tone(speaker, freq, time);

delay(wait);

}

for (freq = 500;

freq < 3000;

freq += 10) //

{

tone(speaker,

freq, time);

delay(wait);

}

for (freq = 3000;

freq > 500;

freq -= 10)

{

tone(speaker, freq, time);

delay(wait);

}

for (freq = 500; freq < 3000; freq += 10)

{

tone(speaker, freq, time);

delay(wait);

}

for (freq = 3000;

freq > 500; freq -= 10)

{

tone(speaker, freq, time);

delay(wait);

}

}

else

{

digitalWrite(led, LOW);

digitalWrite(speaker, LOW);

}

delay(100);

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s