Click here to Skip to main content
15,512,747 members
Articles / Programming Languages / C++
Article
Posted 20 May 2011

Tagged as

Stats

52.3K views
8.3K downloads
46 bookmarked

Homemade Alarm System

Rate me:
Please Sign up or sign in to vote.
4.84/5 (22 votes)
20 May 2011GPL32 min read
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.
C++
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.

C++
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.

C++
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)


Written By
Software Developer Samsung SURC
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Sergio Andrés Gutiérrez Rojas18-Aug-13 10:07
Sergio Andrés Gutiérrez Rojas18-Aug-13 10:07 
GeneralMy vote of 5 Pin
student_milworm23-Jun-13 20:19
student_milworm23-Jun-13 20:19 
General! brilliant Pin
alejandro29A24-May-11 3:13
alejandro29A24-May-11 3:13 
very cool! simplicity is beauty!
Dios existe pero duerme...
Sus pesadillas son nuestra existencia.
(Ernesto Sabato)

GeneralNice Idea! Pin
Jamesmeng22-May-11 23:00
Jamesmeng22-May-11 23:00 
GeneralMy vote of 5 Pin
eleqi22-May-11 17:22
eleqi22-May-11 17:22 
GeneralMy vote of 5 Pin
Indivara20-May-11 14:43
professionalIndivara20-May-11 14:43 
GeneralRe: My vote of 5 Pin
Viktor Signaievskyi21-May-11 4:06
Viktor Signaievskyi21-May-11 4:06 
GeneralWhat are the chances of using the extra pins to wire the alarm? Pin
jayelliii20-May-11 11:33
jayelliii20-May-11 11:33 
GeneralRe: What are the chances of using the extra pins to wire the alarm? Pin
Viktor Signaievskyi21-May-11 4:13
Viktor Signaievskyi21-May-11 4:13 
GeneralMy vote of 5 Pin
Tage Lejon20-May-11 6:59
Tage Lejon20-May-11 6:59 
GeneralRe: My vote of 5 Pin
Viktor Signaievskyi20-May-11 8:51
Viktor Signaievskyi20-May-11 8:51 
Generalcool Pin
Member 386383120-May-11 4:22
Member 386383120-May-11 4:22 
GeneralRe: cool Pin
Viktor Signaievskyi20-May-11 8:54
Viktor Signaievskyi20-May-11 8:54 
GeneralGood idea Pin
Espiritu20-May-11 3:55
Espiritu20-May-11 3:55 
GeneralRe: Good idea Pin
Steve Mayfield20-May-11 8:20
Steve Mayfield20-May-11 8:20 
GeneralRe: Good idea Pin
Viktor Signaievskyi20-May-11 8:50
Viktor Signaievskyi20-May-11 8:50 

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

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