loading

This hands on Instructable steps you through building and programming a person detector alarm with lcd message using:

- An arduino microcontroller

- A simple breadboard with black and red wires

- A speaker or 5v buzzer

- A PIR (infra red) motion sensor

- A 1602 LCD shield w/button input

Step 1: Test for LED Light Blink

What:

Before you build anything or do any real programming, you need to first verify that your computer and the installed arduino software is properly configured to talk to your microcontroller. This process simply compiles and uploads code to the Arduino microcontroller for execution and blinks a light when it succeeds. It's the easiest and fastest test method to verify you can talk to your arduino. There is a small LED (the light) connected to pin 13 of the Arduino. When that pin is 'high' (meaning +5 volts for this Arduino clone), the LED lights.


How:

Select appropriate port: “Tools / Serial port.

Select Arduino Uno: “Tools / Board / Arduino Uno”.

Load blink onto the arduino: “File / Examples / Basics / Blink” (see right).

Click on the upload icon to compile and upload your program.

Several lights will blink during the upload, then your program runs.


If Failure:

If you can not write to the arduino, get some error, or the serial port is ghosted:

  • Verify the correct serial port
  • Unplug Arduino and list serial ports, then plug up Arduino and list serial ports again.
  • An additional serial port should appear.
  • That new serial port should be the Arduino port.
  • Try plugging Arduino into a different port USB port
  • Test with a different cable and Arduino board.
  • Try running the arduino program as root (gets around all permission errors. Usually for testing only)

Step 2: Connect Buzzer and Write an Alarm Sound Program

What:

This step of our project is learn how to make sounds. In our final design, we need to eventually sound an alarm so let's hook up and program with a 5V buzzer.


Setup:

  • Connect the black wire from the black side of the speaker connector to the ground hole on the Arduino.
  • Connect the red wire from the red side of the speaker connector to DIGITAL pin 5.


Upload Program:

  • Create a new file
  • Copy the code from the buzzer program listed below
  • Save the copied program and call it soundAlarm
  • Upload the soundAlarm program to Arduino microcontroller


Buzzer Program:

// VARIABLES
int buzzerPin = 3; // the alarm buzzer pin

int x = 0; // variable used for counting

///////////////SETUP//////////////

void setup() { // this section just runs once.

pinMode(buzzerPin, OUTPUT);

}

/////////// soundAlarm() ////////////

void soundAlarm(int cnt) { // this function just makes an alarm sound

for (x=0 ; x<cnt; c++) { //This controls the number of times it sounds

tone(buzzerPin, 1000, 1000); // High tone (arduino pin, the tone, how long)

delay(1000); // delay for 1 second

tone(buzzerPin, 800, 1000); // Low tone (arduino pin, the tone, how long)

delay(1000); //delay for 1 second

}

}

//////////// loop() //////////////

void loop() { // This is the main program loop

soundAlarm(3); // Sound alarm (n) times

delay(10000); // wait for ten seconds, then go to top of the loop

}

Step 3: Motion Sensor to Detect People

What:

The motion sensor passively detects body heat (or change in the temperature profile) in a visible space for up to 20ft away. Its operation is very simple and cheap to employ, and is commonly used in burglar alarms and outdoor motion activated lights.


How:

The sensor is very simple to operate. It has only three pins. One power (+5V) pin, one ground (GND) pin and one active high OUT signal pin. Once the module powers up and averages out its field of view (this takes between 15-30 seconds), then the OUT pin will go HIGH when there is motion and low a short time after the motion subsides.

Motion Sensor Program:

Here's the code for simply turning on and off a light with your motion sensor

/////////////////////////////

//VARIABLES

int calibrationTime = 20; //the time we give the sensor to calibrate (20-30sec)

int pirPin = 2; //the digital pin connected to the sensor's output

int ledPin = 13; // the built in LED pin
/////////////////////////////

void setup(){

Serial.begin(9600);

pinMode(pirPin, INPUT); // Set up the various I/O pins

pinMode(ledPin, OUTPUT);

digitalWrite(pirPin, LOW);

//give the sensor some time to calibrate (monitor state on the serial port)

Serial.print("calibrating sensor ");

for(int i = 0; i < calibrationTime; i++) {

Serial.print(".");

delay(1000);

}

Serial.println(" done");

Serial.println("SENSOR ACTIVE");

delay(50);

}

////////////////////////////

void loop() {

if(digitalRead(pirPin) == HIGH) { // If the sensor is HIGH

digitalWrite(ledPin, HIGH); // then turn on the LED pin and

Serial.println("HIGH (motion)"); // print "HIGH (motion)" on serial port

}

else {

digitalWrite(ledPin, LOW); // else, make the LED pin low and

Serial.println("LOW (no motion)"); // print "LOW (no motion)" on serial port

}

delay(250); // 250mS delay

}

Step 4: Basic Alarm by Combining Your Alarm & PIR Sensor Code

What:

You now have everything you need to make a basic alarm.

How:

You need to now load up both your alarm code as well as your PIR motion code in separate windows, along withe a new program and copy/paste content from each of the variable, setup and loop sections into one new program you should call “Simple_Person_Alarm”.

Tips: The motion sensor calibration time gives you enough time to exit the room before the alarm arms itself and tiggers on you. Once uploaded and running, you can hit the small “reset” switch on the arduino board to start the program over, giving you that calibration time delay to get out of the room without setting off the alarm yourself!

NOTE: If you have at least an hour remaining, try the more complicated LCD display with keypad buttons! It can really make your sibling detector something to be proud of!

Step 5: The LCD Keypad

What:

By itself the Arduino has limited capability for interacting with humans but with the help from the LCD it provides a simple way to display information.

How:

Hardware setup for shields is extremely easy – just power off/unplug the arduino, then carefully line up the shield pins and plug in the shield!

Lining up and Connecting/Disconnecting a Shield: There are fewer pins on the shield than there are holes in some Arduinos. To line up the pins correctly, hold the Arduino with the USB connection to your left and the shield with the buttons below the display in your right hand. Line up the farthest right shield pins with the farthest right Arduino holes. Carefully make sure all the remaining pins are aligned with the corresponding holes.

Whenever you use any shield, it's important to understand what pins the shield actually use, both for being able to communicate with it and for knowing any conflicts which could occur if you want to stack shields. Above is a table of the pins used by the LCD shield.

Program to Display LCD:

Here's a simple program setting up and displaying a custom message.

#include<LiquidCrystal.h>

// Create the LiquidCrystal object and define the pins used on the LCD shield

// The parameters are: rs, rw, enable, d4, d5, d6, d7

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() { // Start the library, telling it we have a 16 column x 2 row display

lcd.begin(16, 2); // Put the cursor on the first column of the first row

lcd.setCursor(0, 0); lcd.print("Custom Message");


void loop()

{

lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over

lcd.print(millis()/1000); // display seconds elapsed since powerup

}

Step 6: Conclusion

Combine the alarm, motion sensor, and LCD code into one file and upload to arduino. The final product will have a motion sensor that when triggered create a buzz noise and display a message on the LCD screen.

About This Instructable

828views

26favorites

License:

More by tannerwilliams24:Motion Detector With Alarm & Message Using Arduino Microcontroller 
Add instructable to: