Click here to Skip to main content
Click here to Skip to main content

Homemade Alarm System

, 20 May 2011
Rate this:
Please Sign up or sign in to vote.
A project to provide “hardware-software” alarm device
image001_small.png

Introduction

This article describes a security software system. Suppose you have no skills or soldering equipment, but you want to provide security for the apartments. We just mount button to the door and connect it directly to the COM port of the PC (2nd and 3rd pins).

image003.png

We start the program and press the “Start” button. In case the door is opened, speakers will provide a siren sound. The project is written as some kind of “toy software”.

Background

Once as a student living in a hostel, the door lock suddenly failed. Since at that time I stayed alone in the room, I'd have to sleep with the “open” door. At this point, I got the idea to make an open door alarm tool. All I had was a piece of wire and a computer...

Using the Code

The project is written using “Borland C++ Builder 6”. The main idea of this project is in fact that if we are transmitting signals through the COM port TX line to the RX line of the same port, it is possible to catch the transmitted data. So, if contact is broken (button is unpressed, door is opened), data wouldn’t come back.

The algorithm of the program is as follows:

  • Open COM port.
  • Send byte of data to the TX line.
  • Try to receive data from the RX line.
  • Check the received data. If received data differs from the transmitted – turn on siren sound.
void __fastcall TFormMain::ButtonStartClick(TObject *Sender)
{
         FormMain->LabelStatus->Caption="Working";
         FormMain->TimerMain->Enabled=true;
 
         ComPort_PurgeCom();
 
         ComPort_PutByte(0xff);
 
         if(ComPort_GetByte(1))
         {
                 FormMain->PanelMain->Caption="All right!";
                 FormMain->Color=0x000080FF;
         }
         else
         {
                 FormMain->PanelMain->Caption="ALARM!!!";
 
                 //ALARM!!!
                 DWORD fdwSound = SND_ASYNC | SND_FILENAME;
                 PlaySound("sounds/ALARM.wav",NULL, fdwSound);
 
                 FormMain->Color=clRed;
         }
}

To avoid unauthorized access to the software, I’ve made an authorization routine.

void __fastcall TFormAutentification::ButtonCheckClick(TObject *Sender)
{
        AnsiString login="Piligrim";
        AnsiString password="1111";
 
        if(login==EditLogin->Text)
        {
                if(password==EditPassword->Text)
                {
                        FormAutentification->PanelStatus->Color=clGreen;
                        Access();
                }
                else
                {
                        FormAutentification->PanelStatus->Color=clRed;Decline();
                }
        }
        else
        {             
                 FormAutentification->PanelStatus->Color=clRed;
                 Decline();
        }
 
        FormAutentification->TimerMain->Enabled=true;
}

The default login: Piligrim

The default password: 1111

Since COM port number and the baud rate are changeable values, it was necessary to provide an additional form where the obvious values could (and should) be put on.

void __fastcall TFormSettings::ButtonCheckClick(TObject *Sender)
{        
         //checking of the edits "emptiness"
         if(EditCom->Text.IsEmpty())
         {
                 EditCom->Text="Com1";
         }
 
         if(EditBaud->Text.IsEmpty())
         {
                 EditBaud->Text="9600";
         }
 
         //to close the port
         ComPort_Close();
 
         //entering the number of the comport
         AnsiString ComPort=EditCom->Text;
         char *ComP = ComPort.c_str();
 
         //entering the baudrate of the comport
         AnsiString BaudRate=EditBaud->Text;
         unsigned long Baud = BaudRate.ToDouble();
 
         BOOL bOpened;
         ComPort_PresetParameters(Baud,8,NOPARITY,ONESTOPBIT);// optional function
         bOpened = ComPort_Open(ComP);
 
         if(bOpened!=0)
         {
                 EditStatus->Text="Ready";
 
                 //wellcome note
                 DWORD fdwSound = SND_ASYNC | SND_FILENAME;
                 PlaySound("sounds/wellcome.wav",NULL, fdwSound);
 
                 FormSettings->Close();
         }
         else
         {
                 EditStatus->Text="Bussy";
 
                 //error note
                 DWORD fdwSound = SND_ASYNC | SND_FILENAME;
                 PlaySound("sounds/error.wav",NULL, fdwSound);
         }
}

As we can see from the code, in case the chosen COM port is ready, the “welcome” sound rises, otherwise the “error” sound appears. To get the list of accessible COM ports in your PC, just type “mode” command in the “cmd.exe” shell. You will get something like:

image005.png

Points of Interest

Now we see that it is quite easy to provide a security device like that. Usage of the sound effects is pretty good, but it is not enough. A more interesting thing would be to create a report to the web server (for instance, it could be a mail report). But that will be done in a future article and it seems to me that using C# programming language would be more convenient for such kind of tasks.

History

  • 18th May, 2011: Initial version

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Viktor Signaievskyi
Software Developer Samsung SURC
Ukraine Ukraine
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberSergio Andrés Gutiérrez Rojas18-Aug-13 9:07 
GeneralMy vote of 5 Pinmemberstudent_milworm23-Jun-13 19:19 
General! brilliant Pinmemberalejandro29A24-May-11 2:13 
GeneralNice Idea! PinmemberJamesmeng22-May-11 22:00 
GeneralMy vote of 5 Pinmembereleqi22-May-11 16:22 
GeneralMy vote of 5 PinsubeditorIndivara20-May-11 13:43 
GeneralRe: My vote of 5 PinmemberP1l19r1m21-May-11 3:06 
Indivara wrote:
Short and brilliant, great method to avoid any low level port control.

Smile | :)
 

Indivara wrote:
One question though - didn't you have to wire RTS and CTS to each other?

It is not necessary...
GeneralWhat are the chances of using the extra pins to wire the alarm? Pinmemberjayelliii20-May-11 10:33 
GeneralRe: What are the chances of using the extra pins to wire the alarm? PinmemberP1l19r1m21-May-11 3:13 
GeneralMy vote of 5 PinmemberTage Lejon20-May-11 5:59 
GeneralRe: My vote of 5 PinmemberP1l19r1m20-May-11 7:51 
Generalcool PinmemberMember 386383120-May-11 3:22 
GeneralRe: cool PinmemberP1l19r1m20-May-11 7:54 
GeneralGood idea PinmemberEspiritu20-May-11 2:55 
GeneralRe: Good idea PinmemberSteve Mayfield20-May-11 7:20 
GeneralRe: Good idea PinmemberP1l19r1m20-May-11 7:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 20 May 2011
Article Copyright 2011 by Viktor Signaievskyi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid