Sense it UP!

Burglar alarm: Stage 2

You will need

This animation shows the sequence of steps for this stage

Step 2 Image

1) Connect all 3 cables to the PIR sensor using the end without the pins.

Step 2 Image

2) Connect 1 wire to another GND pin on your Arduino board. Then connect the middle wire from your PIR to an available digital pin on the Arduino numbered 2-13. Connect the last wire to the 5V pin. Your Arduino should now look like this.

3) Go back to the Arduino software. Open the burglaralarm.ino file you were using before and delete the text in the window. Copy and paste the following text (code) into your Arduino software.

int BUZZ_Pin = 12; //change to the pin your speaker is connected into
int PIR_Pin = 4; //change to the pin your PIR is connected into
int PIR_State = LOW;
int PIR_Value = 0;
				
void setup() {
    pinMode(BUZZ_Pin, OUTPUT);
    pinMode(PIR_Pin, INPUT);
    Serial.begin(9600);
}

void loop() {
    PIR_Value = digitalRead(PIR_Pin);
    if(PIR_Value == HIGH){
    Serial.println("Intruder Alert!"); //displays message when burglar is detected
      delay(1000);
    }
    else{
      Serial.println("Intruder no longer detected"); //displays message when no burglar is detected
      delay(1000);
      PIR_State = LOW;
    }
}

4) Change the BUZZ_Pin = __ number and PIR_Pin = __ number to show the correct pin numbers you plugged your cables from the speaker and PIR Sensor into on the Arduino board (ie. change the '12' and '4' to the correct value for your Arduino board).

5) Using the software, go Sketch > Verify/Compile to compile the code and File > Save and save it as “burglaralarm.ino”. Now go Sketch > Upload to send it to your Arduino board. Once this has been completed, and program should return “Done uploading.”

6) To test if the PIR sensor is working, open a Serial Monitor window (Tools > Serial Monitor) and it should tell you whether an intruder is detected or not. Wave your hand in front of the sensor for 5 seconds to see if it changes.

Not Working? Try This!

If you don’t get any words in the window, please follow these steps to find why not:

  1. Is the PIR sensor plugged into the 5V pin?
  2. Check your code.
    1. Does it compile? If not check the brackets, extra letters etc that are out of place.
    2. Is it identifying the correct BUZZ_Pin and PIR_Pin numbers?
  3. Check the connections on the breadboard.
    1. Check your breadboard looks like the picture at the end of step 1. If it does and your light is still not working, check that:
      1. All the pins are pushed in.
      2. Try using a different PIR.
      3. Try using different cables.
      4. If none of that gets your light working, ask your teacher/demonstrator for assistance.

Previous stage

Next stage