Embedded Electronics Tutorials, Coding and lot more

PC based home security system

This system can provide all data like temperature, gas , door status of your home on PC screen. All data of parameters like temperature etc are stored in database and can generate Excel file so that you can view data of any day in history you want. This system is very useful in modern houses. Here for demo i am taking 2 sensors: Gas Sensor and a Temperature sensor LM35.  The heart of the system is PIC16F887 microcontroller. It monitors both our digital and anolog sensors. Then sends this data to the serial port via UART module. Hence we need to desing a GUI based software which can understand this incoming data and then dispay the appropriate values on screen. I am using Microsoft Visual BASIC 6.0 as my platform. I can easily interface COM port using the MSComm Port  in components list.


Analog sensor measurement:

PIC16F887 has 10 bit ADC. It has 14 channels available. Result formats are shown below. The 10-bit A/D conversion result can be supplied in two formats, left justified or right justified. The ADFM bit of the ADCON0 register controls the output format.

This is an example procedure for using the ADC to perform an Analog-to-Digital conversion:
1. Configure Port:
• Disable pin output driver (See TRIS register)
• Configure pin as analog
2. Configure the ADC module:
• Select ADC conversion clock
• Configure voltage reference
• Select ADC input channel
• Select result format
• Turn on ADC module
3. Wait the required acquisition time(2).
4. Start conversion by setting the GO/DONE bit.
5. Wait for ADC conversion to complete by one of
the following:
• Polling the GO/DONE bit
6. Read ADC Result
ADC REGISTER DEFINITIONS: The following registers are used to control the operation of the ADC.

ADCON0 register:


ADCON1 register


Bit patterns for ADFM bit  = 1 or 0 :


 LM35 Sensor:

The LM35 temperature sensor provides an output of 10mV per degree Celsius, with an accuracy of 0.5°C at 25°C. It can be powered by any DC voltage in the range 4 – 30v. The operating range is –55°C to +150°c.

 Gas sensor:

Now Gas sensor modules are available from so many vendors in the market at electronics shops or online. Here i am showing one of them. You can use any one. but once you need to check if it is working on +ve logic or -ve logic. I am showing one +ve logic sensor that is availabe here from parallax. Click here . Gas Sensor Module is designed to detect the presence of a dangerous LPG leak in your Home, car or in a service station, storage tank environment by interfacing with Microcontroller without ADC Channels and programming. In this version of LPG Gas sensor module two pots are included, one for trigger level setting and the other for setting sensitivity of the sensor. It allows to determine when a preset LPG gas level has been reached or exceeded. The module uses MQ-6 sensor to sense LPG leak. The MQ-6 can detect gas concentrations anywhere from 200 to 10000 ppm.

GAS                                                         LM35_500x500_1_

A high on OUT pin indicates  LPG presence. This pin can be  connected to the Digital I/O pin of the  microcontroller.

The code is written in Mplab X IDE:

#define SENSOR0 RB0
#define SENSOR1 RB1
#define SENSOR2 RB2
#define SENSOR3 RB3
#define GAS_SENSOR RB4
#define Buzzer RD0
//#define SENSOR1 RB1

void main()
unsigned int dig1, dig2, dig3, dig4;

//Initialize USART with baud rate 9600
// ANSELbits.ANS0 = 1;
ANSELH = 0x00;
TRISDbits.TRISD0 = 0;
Buzzer = 0;
TRISAbits.TRISA0 = 1;
unsigned long ADC_val = 0;


while(GAS_SENSOR) //GAS sensor detected
Buzzer = 1;

Buzzer = 0;

ADC_val = (ADC_Read(0)/2);
dig1 = (unsigned int)(ADC_val/1000); // Calculate digit1 of ADC_value
dig2 = (unsigned int)((ADC_val – dig1*1000)/100); // Calculate digit2 of ADC_value
dig3 = (unsigned int)((ADC_val – (dig1*1000+dig2*100))/10); // Calculate digit3 of ADC_value
dig4 = (unsigned int)(ADC_val – (dig1*1000+dig2*100+dig3*10)); // Calculate digit4 of ADC_value
USARTWriteString(“tt”); // Display digit2 of ADC_value on UART
USARTWriteChar(dig3+0x30); // Display digit3 of ADC_value on UART
USARTWriteChar(dig4+0x30); // Display digit4 of ADC_value on UART




Visual BASIC Application :


At loading time of the form we initialize the serial port as follows:

‘ Fire Rx Event Every single Bytes
MSComm1.RThreshold = 4

‘ When Inputting Data, Input 1 Byte at a time
MSComm1.InputLen = 4

‘ 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = “9600,N,8,1”
‘ Disable DTR
MSComm1.DTREnable = False

‘ Open COM1
MSComm1.CommPort = 1
MSComm1.PortOpen = True

The program code for MSComm1 component is as:

Private Sub MSComm1_OnComm()
Dim sData As String

Dim Data As String
Dim ID As String
Dim MSB As String
Dim quantity As String

‘ If comEvReceive Event then get data and display

If MSComm1.CommEvent = comEvReceive Then
sData = MSComm1.Input ‘ Get data
Data = Mid$(sData, 3, 2) ‘ get 2nd and 3rd byte
MSB = Mid$(sData, 1, 1) ‘ Get LSB
ID = Mid$(sData, 1, 2) ‘ Get MSB
quantity = Mid$(sData, 2, 3) ‘ Get MSB
Text8.Text = sData
Text5.Text = ID
Text7.Text = Data
Text9.Text = MSB
If ID = “SG” Then
If Data = “00” Then
Text6.Text = “Absent”
Text6.Text = “Present”
End If
End If

End Sub

For generating the database the timer2 is fired with some interval.

Private Sub Timer2_Timer()
Text10.Text = Label8.Caption
Text11.Text = Label12.Caption
Text12.Text = Label13.Caption
Text13.Text = Label14.Caption
Text2.Text = Label2.Caption
Text3.Text = Label3.Caption
Text14.Text = Text6.Text
Text15.Text = Text1.Text

End sub

While simulation i am creating a pair of COM1 and COM2 in my PC as virtual serial port. For tutorial on this virtual serial port, read my post here

You can see the whole video of simulation.

Sharing is caring


  1. soft dentures

    I think this is among the most vital info for me. And i’m glad reading your article. But wanna remark on few general things, The website style is wonderful, the articles is really excellent : D. Good job, cheers|

  2. kta

    I like what you guys are up also. Such intelligent work and reporting! Carry on the excellent works guys I¡¦ve incorporated you guys to my blogroll. I think it’ll improve the value of my site 🙂

  3. Sheila Goldsby

    Thanks , I’ve recently been searching for info about this topic for a long time and yours is the greatest I have found out till now. But, what in regards to the bottom line? Are you sure concerning the supply?

  4. Dishnet

    I need to to thank you for this good read!! I certainly loved every bit of it. I have you book-marked to look at new stuff you post…|

  5. agen judi online

    I intended to post you this bit of word just to give thanks the moment again on your pleasing tricks you’ve featured on this site. It is simply tremendously open-handed of you to give without restraint precisely what a few people might have distributed for an e book to end up making some profit on their own, specifically considering that you could have tried it in case you desired. These creative ideas additionally acted as the fantastic way to be aware that many people have the identical interest the same as mine to understand lots more in terms of this issue. I believe there are numerous more enjoyable sessions up front for those who read your blog.

  6. Jena Pelletiu

    Pretty great post. I just came across your weblog and wanted to say that I have truly enjoyed searching your blog posts. Whatever the case I am going to be subscribing for your feed and I am hoping you’re posting yet again soon!

  7. Roxana Kruszewski

    My spouse and I really wish to inform you you in which I am certain inexperienced to online blogging and undeniably enjoyed your work. More than likely I am likely to save your site post . You truly have impressive posting writing. Delight In it for sharing with our company your url page.

  8. Angel Slomka

    I intended to post you one little word to finally say thank you as before regarding the fantastic secrets you have featured on this site.

  9. rak supermarket

    Hey are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any html coding knowledge to make your own blog? Any help would be greatly appreciated!

  10. free dentist

    WOW just what I was looking for. Came here by searching for %meta_keyword%|

  11. maximum shred

    Perfect website write-up. could you make sure you tell me what topic are you working with? thanks

  12. Alec Magathan

    Interesting posting you authored. Certainly with bulk of it. I’m likely to begin following your blogging site.

  13. alexandria va water damage repair

    Hi! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My blog looks weird when viewing from my apple iphone. I’m trying to find a template or plugin that might be able to resolve this issue. If you have any suggestions, please share. With thanks!|

  14. plano tx flood damage repair

    Hey! Someone in my Myspace group shared this website with us so I came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers! Exceptional blog and brilliant style and design.|

  15. Sztachety Plastikowe

    Hello would you mind letting me know which web host you’re using? I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot faster then most. Can you suggest a good web hosting provider at a fair price? Cheers, I appreciate it!

  16. ogrodzenie dla koni

    I loved as much as you will receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this increase.

  17. Sztachety Plastikowe

    Fantastic goods from you, man. I’ve take into accout your stuff prior to and you’re simply too fantastic. I really like what you have got right here, certainly like what you’re stating and the way in which by which you say it. You make it enjoyable and you continue to take care of to stay it sensible. I can not wait to read far more from you. This is actually a great site.

  18. plastikowe sztachety

    You completed certain good points there. I did a search on the theme and found the majority of folks will have the same opinion with your blog.

  19. Emeline Montayes

    My spouse and I loved as much as you will obtain performed right here. The content is neat, your own written material is ideal.

    • Taral Shah

      Thank you so much both of you. Sorry for late reply. I was away a long time for some reasons. Thanks for valuable support.

  20. Sztachety Plastikowe

    I am not really great with English but I find this real easy to read .

  21. ploty plastikowe

    Hello my friend! I wish to say that this article is awesome, nice written and include almost all important infos. I would like to peer more posts like this.

  22. Ogrodzenia winylowe

    excellent post, very informative. I wonder why the other specialists of this sector do not notice this. You must continue your writing. I am confident, you have a great readers’ base already!

  23. ploty plastikowe

    I like this post, enjoyed this one appreciate it for posting .

    • Taral Shah

      Thank you so much. Sorry for late reply. I was away a long time for some reasons. Thanks for valuable support.

  24. sztachety PCV

    With havin so much content and articles do you ever run into any problems of plagorism or copyright violation? My blog has a lot of completely unique content I’ve either written myself or outsourced but it seems a lot of it is popping it up all over the web without my authorization. Do you know any ways to help prevent content from being stolen? I’d really appreciate it.

  25. ogrodzenie z pvc

    Howdy would you mind sharing which blog platform you’re working with? I’m planning to start my own blog soon but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S Apologies for being off-topic but I had to ask!

  26. ploty plastikowe

    Thank you, I have recently been searching for info about this topic for a while and yours is the best I’ve discovered so far. But, what about the bottom line? Are you certain about the source?

  27. my company

    I simply want to tell you that I am just all new to weblog and actually loved your website. Most likely I’m want to bookmark your blog . You amazingly come with very good article content. Thank you for revealing your website page.

  28. my web

    I simply want to mention I am just beginner to weblog and actually loved this web blog. Likely I’m likely to bookmark your site . You absolutely have exceptional well written articles. Thanks a lot for sharing with us your webpage.

Leave a Reply

Your email address will not be published. Required fields are marked *


Theme by Anders NorenUp ↑

Follow Me

Get the latest posts right delivered in you mailbox

%d bloggers like this: