Click here to Skip to main content
13,254,754 members (54,238 online)
Click here to Skip to main content
Add your own
alternative version


46 bookmarked
Posted 20 May 2011

Homemade Alarm System

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


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).


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”.


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->PanelMain->Caption="All right!";
                 DWORD fdwSound = SND_ASYNC | SND_FILENAME;
                 PlaySound("sounds/ALARM.wav",NULL, fdwSound);

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";

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"
         //to close the port
         //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);
                 //wellcome note
                 DWORD fdwSound = SND_ASYNC | SND_FILENAME;
                 PlaySound("sounds/wellcome.wav",NULL, fdwSound);
                 //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:


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.


  • 18th May, 2011: Initial version


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

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Sergio Andrés Gutiérrez Rojas18-Aug-13 10:07
memberSergio Andrés Gutiérrez Rojas18-Aug-13 10:07 
GeneralMy vote of 5 Pin
student_milworm23-Jun-13 20:19
memberstudent_milworm23-Jun-13 20:19 
General! brilliant Pin
alejandro29A24-May-11 3:13
memberalejandro29A24-May-11 3:13 
GeneralNice Idea! Pin
Jamesmeng22-May-11 23:00
memberJamesmeng22-May-11 23:00 
GeneralMy vote of 5 Pin
eleqi22-May-11 17:22
membereleqi22-May-11 17:22 
GeneralMy vote of 5 Pin
Indivara20-May-11 14:43
subeditorIndivara20-May-11 14:43 
GeneralRe: My vote of 5 Pin
P1l19r1m21-May-11 4:06
memberP1l19r1m21-May-11 4:06 
GeneralWhat are the chances of using the extra pins to wire the alarm? Pin
jayelliii20-May-11 11:33
memberjayelliii20-May-11 11:33 
GeneralRe: What are the chances of using the extra pins to wire the alarm? Pin
P1l19r1m21-May-11 4:13
memberP1l19r1m21-May-11 4:13 
GeneralMy vote of 5 Pin
Tage Lejon20-May-11 6:59
memberTage Lejon20-May-11 6:59 
GeneralRe: My vote of 5 Pin
P1l19r1m20-May-11 8:51
memberP1l19r1m20-May-11 8:51 
Generalcool Pin
Member 386383120-May-11 4:22
memberMember 386383120-May-11 4:22 
GeneralRe: cool Pin
P1l19r1m20-May-11 8:54
memberP1l19r1m20-May-11 8:54 
GeneralGood idea Pin
Espiritu20-May-11 3:55
memberEspiritu20-May-11 3:55 
GeneralRe: Good idea Pin
Steve Mayfield20-May-11 8:20
memberSteve Mayfield20-May-11 8:20 
The two wires from the COMM port are connected to the two contacts of a push button switch. When the door is closed, the switch is "ON", creating a loopback connection between the TX (transmit) and RX (receive) COMM lines. This allows tranmitted characters to be returned to the receive input where they are compared by the software. When the door is open, the switch goes OFF, breaking the loopback connection so no transmitted characters are returned to the receive side.
I C(++) therefore I am

GeneralRe: Good idea Pin
P1l19r1m20-May-11 8:50
memberP1l19r1m20-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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 20 May 2011
Article Copyright 2011 by Viktor Signaievskyi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid