Intruder Alarm

Start 

This project uses the light sensor as a different kind of trigger than the Robot Buddy. Here we will use some household materials to create a door activated alarm.

Modules 

Gather the following parts to complete this project.

Parts

All Parts
All Parts
Light
Piezo Buzzer
Cable
PartQuantity
Light 1
Piezo Buzzer 1
Cable 2

Light Sensor 

Take a cable and attach one end to the light sensor and the other to Analog socket A0.

All the parts you'll need
All the parts you'll need
Take a cable...
... and unwrap it
Plug one side into the light sensor socket
... and the other into Analog socket A0

Upload

Upload the code below. This tutorial uses Analog socket A0. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
//Change here if you're using a different socket
#define sensorSocket A0

int val;

void setup() {
  Serial.begin(9600);
}

void loop() {
  val = analogRead(sensorSocket);
  Serial.println(val);
}

Observe

Open up the Serial Plotter and move your hand or cardboard over the light sensor. Check out what values you can get. Look at the light value you get when the sensor is uncovered and covered. Remember those because we'll need them for the intruder alarm to work correctly.

Buzzer 

Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6.

Parts
Parts
Take a cable...
... and unwrap it
Plug one side into the buzzer socket
... and the other into Digital socket D6

Upload

Upload this code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Change here if you're using a different socket
#define buzzerSocket 6

void setup()
{
  pinMode(buzzerSocket, OUTPUT);
}

void loop()
{
  delay(2000);
  digitalWrite(buzzerSocket,HIGH);
  delay(100);
  digitalWrite(buzzerSocket,LOW);
}

Observe

The buzzer will wait for a second before playing a quick chirp.

Take a listen. It would be hard not toTake a listen. It would be hard not to

Modify

Change up the delays for a quicker or longer chirp sound.

Intruder Alarm 

Cover the light sensor before continuing.

Upload

Upload this code below. Add in your ambient or uncovered light value for the trigger.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//If you use different sockets change them below
#define buzzerSocket 6
#define lightSensorSocket A0

int lightValue;
int trigger = 250;
int alarms = 3;
int alarmCount = 0;

void setup()
{
  pinMode(buzzerSocket, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  lightValue = analogRead(lightSensorSocket);
  //Serial.println(lightValue);
  if (lightValue > trigger) {
    while (alarms > alarmCount) {
      Serial.println(alarms);
      digitalWrite(buzzerSocket, HIGH);
      delay(200);
      digitalWrite(buzzerSocket, LOW);
      delay(500);
      alarmCount++;
    }
    alarmCount = 0;
    delay(3000);
  }
}

Observe

Uncover your light sensor and listen to that beautiful music? Let's transfer over to battery power with a 9 volt battery and install it.

Covered alarm
Covered alarm
Let's check it
Yeah it works
Grab the USB cable
Unplug the USB cable
A battery with the included cable
Let's go install

Construction

Use a piece of cardboard taped to a door frame to cover the sensor. Attach the electronics to the wall. When the door is opened the sensor will move and no longer be covered. This triggers the alarm.

I've found a door
I've found a door
Cardboard? Check
Line it up with the bottom of the door
Take a piece of tape
Attach it to the cardboard
Tape it to the door
You might need more than one piece of tape
Make sure the door closes
The light sensor...
... should face the cardboard here
Just like this
Light sensor is right up against the cardboard trigger
Take the battery...
... and plug it in
Green led means the power is on
Open the door and you should hear the chirps
Closing the door resets the alarm