Make some NOISE!

Burglar alarm: Stage 3

The working (and annoying) burglar catcher!

1) To get your sensor to work with your speaker, you need to tell the speaker to turn on when the PIR sensor detects an intruder. How? It’s easy just update the code since both the speaker and the PIR sensor are already working. Go back to the Arduino software, and open the nightlight.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){ digitalWrite(BUZZ_Pin, HIGH); //turns speaker alarm on delay(50); digitalWrite(BUZZ_Pin, LOW); //turns speaker alarm off delay(50); if(PIR_State == LOW){ Serial.println("Intruder Alert!"); //displays message when burglar is detected PIR_State = HIGH; } } else{ if(PIR_State = HIGH){ Serial.println("Intruder no longer detected"); //displays message when no burglar is detected PIR_State = LOW; } } }

2) Remember to change the BUZZ_Pin = __ and PIR_Pin = __ numbers to show the correct pin you plugged your cable from the speaker and PID Sensor into on the Arduino board

3) Using the software, go Sketch > Verify/Compile to compile the code and File > Save and save it as “burglaralarm.ino”. Next go Sketch > Upload to send it to your Arduino board. Once this has been completed, and program should return “Done uploading.” The alarm should now sound when an intruder is detected, and you have a working burglar alarm! Wave your hand in front of the sensor for 5 seconds to see if it turns on, and then stay very still to see if it turns off.

Not Working? Try This!

  1. 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?
  2. Check the connections on the breadboard.
    1. Check your breadboard looks like the picture at the end of step 1. If it does and you still do not get words in the window, 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