Alarm System Powered By Arduino

Dejan Nedelkovski had built an Arduino security and alarm system project that uses an ultrasonic sensor for detecting objects and a buzzer for notification.

Components needed to build this simple system are: Arduino board, LCD display, 4×4 keypad, ultrasonic sensor and buzzer. The circuit can be connected as shown in the schematics below.

In order to build the project, you have to connect the buzzer with a PWM pin and the keypad pins where 4 of the 8 pins are for rows and the rest are for columns.

“The 4×4 keypad has 8 pins, 4 of them are for the rows and 4 of them for the columns of the keypad. Each button is actually a push button switch which makes a short between one row and column when pressed. So, for example, if we set the row 1 line low, and all column lines high, when we will press, for example, the button 3, due to the short between the two lines, the column 3 line will drop to low so in such a case we can register that the button 3 has been pressed.”

For connecting the LCD display and ultrasonic sensor you can check this detailed video tutorial by Dejan Nedelkovski and to see the project in action:

We want to activate the alarm by setting the A button to activate it. B button is used to change the password, and you need to enter the preset password “1234” to be able to change it.
After activating the alarm by pressing A, a 200 milliseconds sound will be produced from the buzzer showing that the alarm is now active. A message on the LCD display will appear to saying “Alarm will be activated in” and a countdown will be running afterwards until the alarm is completely active. At the end of the countdown a ” Alarm Activated” is on the display and the sensor will start working. Comparing with the initial distance at the start, the sensor will measure the distance is smaller than the initial distance, corrected by a value of 10 cms. The buzzer will  produce a sound if an object is observed as per the condition.

Here’s the complete source code of the Arduino alarm system:

/*
* Arduino Security and Alarm System
*
* by Dejan Nedelkovski,
* www.HowToMechatronics.com
*
*/
#include <LiquidCrystal.h> // includes the LiquidCrystal Library 
#include <Keypad.h>
#define buzzer 8
#define trigPin 9
#define echoPin 10
long duration;
int distance, initialDistance, currentDistance, i;
int screenOffMsg =0;
String password="1234";
String tempPassword;
boolean activated = false; // State of the alarm
boolean isActivated;
boolean activateAlarm = false;
boolean alarmActivated = false;
boolean enteredPassword; // State of the entered password to stop the alarm
boolean passChangeMode = false;
boolean passChanged = false;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keypressed;
//define the cymbols on the buttons of the keypads
char keyMap[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {14, 15, 16, 17}; //Row pinouts of the keypad
byte colPins[COLS] = {18, 19, 20, 21}; //Column pinouts of the keypad
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, ROWS, COLS); 
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7) 
void setup() { 
  lcd.begin(16,2); 
  pinMode(buzzer, OUTPUT); // Set buzzer as an output
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}
void loop() {
  if (activateAlarm) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Alarm will be");
    lcd.setCursor(0,1);
    lcd.print("activated in");
   
    int countdown = 9; // 9 seconds count down before activating the alarm
    while (countdown != 0) {
      lcd.setCursor(13,1);
      lcd.print(countdown);
      countdown--;
      tone(buzzer, 700, 100);
      delay(1000);
    }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Alarm Activated!");
    initialDistance = getDistance();
    activateAlarm = false;
    alarmActivated = true;
  }
  if (alarmActivated == true){
      currentDistance = getDistance() + 10;
      if ( currentDistance < initialDistance) {
        tone(buzzer, 1000); // Send 1KHz sound signal 
        lcd.clear();
        enterPassword();
      }
    }
  if (!alarmActivated) {
    if (screenOffMsg == 0 ){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("A - Activate");
      lcd.setCursor(0,1);
      lcd.print("B - Change Pass");
      screenOffMsg = 1;
    }
    keypressed = myKeypad.getKey();
     if (keypressed =='A'){        //If A is pressed, activate the alarm
      tone(buzzer, 1000, 200);
      activateAlarm = true;            
    }
    else if (keypressed =='B') {
      lcd.clear();
      int i=1;
      tone(buzzer, 2000, 100);
      tempPassword = "";
      lcd.setCursor(0,0);
      lcd.print("Current Password");
      lcd.setCursor(0,1);
      lcd.print(">");
      passChangeMode = true;
      passChanged = true;   
      while(passChanged) {      
      keypressed = myKeypad.getKey();
      if (keypressed != NO_KEY){
        if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
            keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
            keypressed == '8' || keypressed == '9' ) {
         tempPassword += keypressed;
         lcd.setCursor(i,1);
         lcd.print("*");
         i++;
         tone(buzzer, 2000, 100);
        }
      }
      if (i > 5 || keypressed == '#') {
        tempPassword = "";
        i=1;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Current Password");
        lcd.setCursor(0,1);
        lcd.print(">"); 
      }
      if ( keypressed == '*') {
        i=1;
        tone(buzzer, 2000, 100);
        if (password == tempPassword) {
          tempPassword="";
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Set New Password");
          lcd.setCursor(0,1);
          lcd.print(">");
          while(passChangeMode) {
            keypressed = myKeypad.getKey();
            if (keypressed != NO_KEY){
              if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
                  keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
                  keypressed == '8' || keypressed == '9' ) {
                tempPassword += keypressed;
                lcd.setCursor(i,1);
                lcd.print("*");
                i++;
                tone(buzzer, 2000, 100);
              }
            }
            if (i > 5 || keypressed == '#') {
              tempPassword = "";
              i=1;
              tone(buzzer, 2000, 100);
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("Set New Password");
              lcd.setCursor(0,1);
              lcd.print(">");
            }
            if ( keypressed == '*') {
              i=1;
              tone(buzzer, 2000, 100);
              password = tempPassword;
              passChangeMode = false;
              passChanged = false;
              screenOffMsg = 0;
            }            
          }
        }
      }
    }
   }
 }
}
void enterPassword() {
  int k=5;
  tempPassword = "";
  activated = true;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" *** ALARM *** ");
  lcd.setCursor(0,1);
  lcd.print("Pass>");
      while(activated) {
      keypressed = myKeypad.getKey();
      if (keypressed != NO_KEY){
        if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
            keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
            keypressed == '8' || keypressed == '9' ) {
          tempPassword += keypressed;
          lcd.setCursor(k,1);
          lcd.print("*");
          k++;
        }
      }
      if (k > 9 || keypressed == '#') {
        tempPassword = "";
        k=5;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" *** ALARM *** ");
        lcd.setCursor(0,1);
        lcd.print("Pass>");
      }
      if ( keypressed == '*') {
        if ( tempPassword == password ) {
          activated = false;
          alarmActivated = false;
          noTone(buzzer);
          screenOffMsg = 0; 
        }
        else if (tempPassword != password) {
          lcd.setCursor(0,1);
          lcd.print("Wrong! Try Again");
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(" *** ALARM *** ");
          lcd.setCursor(0,1);
          lcd.print("Pass>");
        }
      }    
    }
}
// Custom function for the Ultrasonic sensor
long getDistance(){
  //int i=10;
  
  //while( i<=10 ) {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration*0.034/2;
  //sumDistance += distance;
  //}
  //int averageDistance= sumDistance/10;
  return distance;
}

Check the project post to know more information and to find detailed tutorial. You can also check other posts by Dejan using this link.

RELATED POSTS

Dual-Channel Quadrature Hall-Effect Bipolar Switch Module for Magnetic Encoder

The A1230 is a dual-channel, bipolar switch with two Hall-effect sensing elements, each providing a separate digital output for speed and direction signal processing capability. The Hall elements are photo lithographically aligned to better than 1 µm. maintaining accurate mechanical location between the two active Hall elements eliminates the major manufacturing hurdle encountered in fine-pitch detection applications. The A1230 is a highly sensitive, temperature stable magnetic sensing device ideal for use in ring magnet based, speed and direction systems located in harsh automotive and industrial environments.

The A1230 monolithic integrated circuit (IC) contains two independent Hall-effect bipolar switches located 1 mm apart. The digital outputs are out of phase so that the outputs are in quadrature when interfaced with the proper ring magnet design. This allows easy processing of speed and direction signals. Extremely low-drift amplifiers guarantee symmetry between the switches to maintain signal quadrature. The Allegro patented, high-frequency chopper-stabilization technique cancels offsets in each channel providing stable operation over the full specified temperature and voltage ranges.

Dual-Channel Quadrature Hall-Effect Bipolar Switch Module for Magnetic Encoder – [Link]

MINI PIC GPS DATA LOGGER WITH MICRO-SD CARD

Based on my first GPS data logger  I made a new version which is even smaller than the initial design and should be able to fit in any rocket, RC model etc. The new GPS data logger uses micro-SD card and 3.7v LIPO battery as power source. The board was also optimized and the new size is 20mm x 27mm – less than a standard SD card as you can see on the picture to the right.

MINI PIC GPS DATA LOGGER WITH MICRO-SD CARD – [Link]

DIY Data logging weather station under $15

A Homeschoolers Workbench @ instructables.com has build an Arduino based datalogger that reads data from a DHT22 sensor and logs them on a SD card.

In this instructable I am going to show you how to build a weather station that logs the information that it collects on a sd card.

DIY Data logging weather station under $15 – [Link]

ICStripBoard – PCB rapid prototyping tool

 

ICStripBoard is a innovative cheap tool to enable rapid prototyping of surface mount integrated circuits (IC’s) and allow their usage in prototype electronics projects.

Inline surface mount IC’s come in a Variety of packages which are different sizes and these Printed Circuit Boards (PCB’s) have been designed to accommodate the majority of IC’s. Available in the four standard IC pitches (space between IC pins) of 0.5mm, 0.65mm, 0.95mm and 1.27mm. These boards have been designed as long strips on thin (half the standard thickness) 0.8mm FR4 boards which can easily be cut to the correct amount of pins which the IC in question has. This allows the strip to be cut for multiple IC’s on multiple projects.

The cut pieces can easily be soldered and glued to other prototyping products and in conjunction with traditional through hole components can be used to create unique electronic prototypes. These boards will allow you to experiment with multiple IC’s without having to build PCB’s and is far cheaper than buying alternative break out boards due to the fact you cut them to size and the pattern repeats down the strip allowing this to be done multiple times. (more…)

Send Texts or Make Calls With This Tiny GSM Board

@ blog.tindie.com

This quad band GSM board is claimed to be the worlds smallest of its kind. We have no way to verify this bold claim but let’s all agree that this is a pretty small board that lets you send texts and make calls. The GSM feature is an addition to the OLEDiUNO Cube range that we have mentioned previously on the blog.

Send Texts or Make Calls With This Tiny GSM Board – [Link]

The Next-Generation Semiconductor for Power Electronics

Researchers have demonstrated the high-performance potential of an experimental transistor made of a semiconductor called beta gallium oxide, which could bring new ultra-efficient switches for applications such as the power grid, military ships and aircraft.

The semiconductor is promising for next-generation “power electronics,” or devices needed to control the flow of electrical energy in circuits. Such a technology could help to reduce global energy use and greenhouse gas emissions by replacing less efficient and bulky power electronics switches now in use.

The schematic at left shows the design for an experimental transistor made of a semiconductor called beta gallium oxide, which could bring new ultra-efficient switches for applications such as the power grid, military ships and aircraft. At right is an atomic force microscope image of the semiconductor. (Purdue University image/Peide Ye)

 

The schematic at left shows the design for an experimental transistor made of a semiconductor called beta gallium oxide, which could bring new ultra-efficient switches for applications such as the power grid, military ships and aircraft. At right is an atomic force microscope image of the semiconductor. (Purdue University image/Peide Ye)The transistor, called a gallium oxide on insulator field effect transistor, or GOOI, is especially promising because it possesses an “ultra-wide bandgap,” a trait needed for switches in high-voltage applications.

Compared to other semiconductors thought to be promising for the transistors, devices made from beta gallium oxide have a higher “breakdown voltage,” or the voltage at which the device fails, said Peide Ye, Purdue University’s Richard J. and Mary Jo Schwartz Professor of Electrical and Computer Engineering.

Findings are detailed in a research paper published this month in IEEE Electron Device Letters. Graduate student Hong Zhou performed much of the research.

The team also developed a new low-cost method using adhesive tape to peel off layers of the semiconductor from a single crystal, representing a far less expensive alternative to a laboratory technique called epitaxy. The market price for a 1-centimeter-by-1.5-centimeter piece of beta gallium oxide produced using epitaxy is about $6,000. In comparison, the “Scotch-tape” approach costs pennies and it can be used to cut films of the beta gallium oxide material into belts or “nano-membranes,” which can then be transferred to a conventional silicon disc and manufactured into devices, Ye said.

The technique was found to yield extremely smooth films, having a surface roughness of 0.3 nano-meters, which is another factor that bodes well for its use in electronic devices, said Ye, who is affiliated with the NEPTUNE Center for Power and Energy Research, funded by the U.S. Office of Naval Research and based at Purdue’s Discovery Park. Related research was supported by the center.

The Purdue team achieved electrical currents 10 to 100 times greater than other research groups working with the semiconductor, Ye said.

One drawback to the material is that it possesses poor thermal properties. To help solve the problem, future research may include work to attach the material to a substrate of diamond or aluminum nitride.

The research was based at Discovery Park’s Birck Nanotechnology Center.
Source: Purdue University

LASER TRIGGER FOR CHRONOGRAPH

I finished this laser wall trigger for my HIGH RESOLUTION AND ACCURACY CHRONOGRAPH. The purpose of this device is to generate the trigger start and stop impulses for my chronograph as soon as an object disrupts any of the laser beams.

LASER TRIGGER FOR CHRONOGRAPH – [Link]

A 400W (1kW Peak) 100A Electronic Load Using Linear MOSFETs

Kerry Wong built a 400W/100A electronic load using linear MOSFETs. He writes:

I bought a couple of IXYS linear MOSFETs (IXTK90N25L2) a while ago to test their capabilities when used as electronic load, and the result was quite impressive. So I decided to build another electronic load using both MOSFETs. As you can see in the video towards the end, this electronic load can sink more than 100 Amps of current while dissipating more than 400W continuously and can withstand more than 1kW of power dissipation in pulsed operation mode.

A 400W (1kW Peak) 100A Electronic Load Using Linear MOSFETs – [Link]

Digital Potentiometer using Optical Encoder – 10KOhms

The primary application of the project is to replace the mechanical potentiometer with optical encoder which is long life, accurate, smooth in operation. The simple project has been designed around LS7184 quadrature clock converter IC from LSI semiconductor, AD5220-10 Digital potentiometer from Analog Devices, and optical encoder from Burns.

Quadrature clocks derived from optical encoder, when applied to the A and B inputs of the LS7184, are converted to strings of Clock and an Up/down direction control. These outputs interfaced directly to AD5220-10 Digital Potentiometer IC.

The AD5220-10 contains a single channel, 128 positions, and digitally-controlled 10K ohms variable resistor (VR) device. This device performs the same electronic adjustment function as a potentiometer.

Digital Potentiometer using Optical Encoder – 10KOhms – [Link]