EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / HOME AUTOMATION USING GSM WITH PIC16f877a

HOME AUTOMATION USING GSM WITH PIC16f877a

|

Microcontroller › PIC › HOME AUTOMATION USING GSM WITH PIC16f877a

  • This topic has 33 replies, 10 voices, and was last updated 10 years, 5 months ago by sreeja devashisa.
Viewing 15 posts - 1 through 15 (of 34 total)
1 2 3 →
  • Author
    Posts
  • January 16, 2013 at 2:03 pm #2074
    Amy
    Participant

    hi sir… we are doing a project that concerns home automation using gsm and pic just the turning on/off of lights and some appilances . but we are just beginners in programming the pic.. should we use AT commands?? we will directly connect the gsm’s rx and tx to the pic. how will b ethe program then?? thank you..

    January 18, 2013 at 11:49 am #8977
    nidhin.k
    Participant

     

    #include<pic.h>
     
    #define First_Line 0x80
    #define Second_Line 0xc0
    #define Curser_On  0x0f
    #define Curser_Off 0x0c
    #define Clear_Display 0x01
    #define Data_Port PORTD
     
    static bit   Lcd_rs  @((unsigned) &PORTC*8+4); 
    static bit   Lcd_en  @((unsigned) &PORTC*8+5);
     
    #define appl1 RB7
    #define appl2 RB6
    #define appl3 RB5
    #define appl4 RB4
     
    void gsm_init();
    void Lcd8_Init();
    void Lcd8_Command(unsigned char);
    void Lcd8_Write(unsigned char,unsigned char);
    void Lcd8_Display(unsigned char,const unsigned char*,unsigned int);
    void Delay(unsigned int);
     
    void Serial_Init(unsigned long int);
    void Serial_Out(unsigned char);
    void Serial_Conout(const unsigned char *,unsigned char);
    void Baudrate(unsigned long int);
    void Receive(unsigned char);
     
    unsigned char c[5],j;
    void main()
    {
    TRISB=0x00;
    TRISC=0xC0;
    TRISD=0x00;
    Lcd8_Init();
    Lcd8_Display(0x80,”HOME APPLIANCES:”,16);
    Lcd8_Display(0xC0,”    CONTROL:    “,16);
    Delay(65000);Delay(65000);
    Lcd8_Display(0xC0,”                “,16);
    Serial_Init(9600);
    gsm_init();
    Receive(1);
    while(1)
    {
    if(j>=2)
    {
    Receive(0);
    if(c[1]==’a’){appl1=0;Lcd8_Display(0xC0,”APPLIANCES 1:ON “,16);}
    if(c[1]==’b’){appl2=0;Lcd8_Display(0xC0,”APPLIANCES 2:ON “,16);}
    if(c[1]==’c’){appl3=0;Lcd8_Display(0xC0,”APPLIANCES 3:ON “,16);}
    if(c[1]==’d’){appl4=0;Lcd8_Display(0xC0,”APPLIANCES 4:ON “,16);}
    if(c[1]==’c’){appl1=1;Lcd8_Display(0xC0,”APPLIANCES 1:OFF”,16);}
    if(c[1]==’d’){appl2=1;Lcd8_Display(0xC0,”APPLIANCES 2:OFF”,16);}
    if(c[1]==’e’){appl3=1;Lcd8_Display(0xC0,”APPLIANCES 3:OFF”,16);}
    if(c[1]==’f’){appl4=1;Lcd8_Display(0xC0,”APPLIANCES 4:OFF”,16);}
    j=0;
    Receive(1);
    }
    }
    }
     
    void interrupt  timer1(void)
    {
     if(RCIF)
     {
    RCIF=0;
    c[j]=RCREG;
    if(c[0]==’*’)j++;
    else j=0;
     }
    }
    void gsm_init()
    {
    Serial_Conout(“AT”,2);
    Serial_Out(0x0d);Serial_Out(0x0a);
    Delay(65000);Delay(65000);
    Serial_Conout(“AT+CMGF=1”,9);  
    Serial_Out(0x0d);Serial_Out(0x0a);
    Delay(65000);Delay(65000);
    Serial_Conout(“AT+CNMI=2,2,0,0,0”,17);  
    Serial_Out(0x0d);Serial_Out(0x0a);
    Delay(65000);Delay(65000);
    }
     
    void Lcd8_Init()
    {
    Lcd8_Command(0x38); //to select function set
    Lcd8_Command(0x06); //entry mode set
    Lcd8_Command(0x0c); //display on
    Lcd8_Command(0x01); //clear display
    }
     
    void Lcd8_Command(unsigned char com)
    {
    Data_Port=com;
    Lcd_en=1;
    Lcd_rs=0;
    Delay(125);
    Lcd_en=0;
    Delay(125);
    }
     
    void Lcd8_Write(unsigned char com,unsigned char lr)
    {
    Lcd8_Command(com);
     
    Data_Port=lr; // Data 
    Lcd_en=1;
    Lcd_rs=1;
    Delay(125);
    Lcd_en=0;
    Delay(125);
    }
     
    void Lcd8_Display(unsigned char com,const unsigned char *word,unsigned int n)
    {
    unsigned char Lcd_i;
     
    for(Lcd_i=0;Lcd_i<n;Lcd_i++)
    { 
    Lcd8_Write(com+Lcd_i,word[Lcd_i]);
      }
    }
     
    void Delay(unsigned int del)
    {
    while(del–);
    }     
     
    void Serial_Init(unsigned long int baud)
    {  
    Baudrate(baud);
    SYNC = 0;     // asynchronous mode
    SPEN = 1;     // serial port enable
    TXEN = 1;     // tx enable
    GIE=1;
    PEIE=1;
    RCIE = 1; // interrupt set
    CREN = 1;     // rx enable
    }
     
    void Serial_Out(unsigned char val)
    {
    TXREG =val;
    while(!TXIF);
    TXIF = 0;
    }
     
     
    void Serial_Conout(const unsigned char *data,unsigned char n)
    {
    unsigned char ser_j;
    for(ser_j=0;ser_j<n;ser_j++)
    {
    Serial_Out(data[ser_j]);
    }
    }
     
    void Baudrate(unsigned long int baud)
    {
    if(baud==110) //Crystal Freq 1 Mhz
    {
    SPBRG = 141;          // for 110 baud rate
    BRGH = 0;     // baud rate low
    }
    else if(baud==1200) //Crystal Freq 4 Mhz
    {
    SPBRG = 51;          // for 1200 baud rate
    BRGH = 0;     // baud rate high
    }
    else if(baud==2400)
    {
    SPBRG = 25;          // for 2400 baud rate
    BRGH = 0;     // baud rate high
    }
    else if(baud==4800)
    {
    SPBRG = 12;          // for 4800 baud rate
    BRGH = 0;     // baud rate high
    }
    else if(baud==9600)
    {
    SPBRG = 25;          // for 9600 baud rate
    BRGH = 1;     // baud rate high
    }
    else if(baud==57600)
    {
    SPBRG = 20;          // for 57600 baud rate
    BRGH = 1;     // baud rate high
    }
    else if(baud==115200)
    {
    SPBRG = 10;          // for 115200 baud rate
    BRGH = 1;     // baud rate high
    }
    }
     
     
    void Receive(unsigned char rece)
    {
    if(rece==1)
    {
    RCIE = 1; // interrupt set
    CREN = 1;     // rx enable
    }
    else
    {
    RCIE = 0; // interrupt set
    CREN = 0;     // rx enable
    }
    }
     
    January 19, 2013 at 1:27 pm #8985
    M.Khalil Anwar Nizami
    Participant

    hi amy,would you like to share your project detail with me?

    January 19, 2013 at 1:46 pm #8987
    M.Khalil Anwar Nizami
    Participant

    nidhin.k brother,why use if(c[1]==’a’){appl1=0;Lcd8_Display(0xC0,”APPLIANCES 1:ON “,16);}

    purpose you can justify?

    and 16 is what?

    please share

    January 19, 2013 at 1:50 pm #8988
    M.Khalil Anwar Nizami
    Participant

    code is perfectly ok?

    where i can test it on software?proteous,multisim,etc…?

    January 19, 2013 at 2:47 pm #8990
    Amy
    Participant

    hi M. Khalil,, our project is to control the on/off of ligths and appliances. we will send message to the gsm modem an then the gsm is the one that is connected to the PIC16f877a. after that the PIC is connected to the relays that is connected to the appliances or ligths. after that the gsm will send a message to the phone that the command has been executed. its as if it will upadate the phone that this particular applaince is turned on… we will not use lcd. just the phone, GSM modem and the PIC…

     

    we are having a difficult time in the programming part :(

     

    January 19, 2013 at 2:49 pm #8991
    Amy
    Participant

    nidhin.k,, thank you for the codes :) what if we will not use LCD??

    January 21, 2013 at 5:43 am #8998
    nidhin.k
    Participant

    hai kalil…

     

     

     

     i’m sending sms like -*a,*b,*c,*d,*e,*f,*g,*h

     

     

    while receiving sms, it is easy for identifying our msg.

    on receiving a msg we will get +cmg:- +mobile number+etc…

     

    in my code

     

     

    if(RCIF)

     

    {

    c=RCREG;

    if(c[0]==’*’)i++;

    else i=0;

    RCIF=0;

     

    }

     

    the array will increment only when ur msg starts with “*”

     

    msg format:-

     

    *a- appliance 1 ON

    *b- appliance 2 ON

    *c- appliance 3 ON

    *d- appliance 4 ON

     

    *e- appliance 1 OFF

    *f- appliance 2 OFF

    *g- appliance 3 OFF

    *h- appliance 4 OFF

     

     

    Lcd8_Display(0xC0,”APPLIANCE 1 ON  “,16);

     

    please check that function… u can understand it easily.

     

    In that function, i’m sending 16 character string to LCD display. strating location 0xC0

     

    January 21, 2013 at 5:47 am #8999
    nidhin.k
    Participant

    hai kalil…..

     

    u can test it on both software and proteus

    January 21, 2013 at 3:02 pm #9022
    Amy
    Participant

    where can i create this program? MPLAB or Micro C? thanks :)

    January 22, 2013 at 4:36 am #9026
    nidhin.k
    Participant

    hi amy….

     

     

     i create this code in mp lab…..

    January 23, 2013 at 2:02 pm #9036
    Amy
    Participant

    hi nidhin.k,, is this program for PIC16f877a and what if we will not use LCD?? just the PIC and GSM.. thanks you very much :)

    January 24, 2013 at 4:26 am #9039
    nidhin.k
    Participant

    hai amy….

     

     

    if u are not using lcd… u can remove all the function and function call that is started with LCD….

    January 24, 2013 at 4:27 am #9040
    nidhin.k
    Participant

    hai amy….

     

     

    if u are not using lcd… u can remove all the function and function call that is started with “Lcd”….

     

     

    all the best….

    January 24, 2013 at 5:45 am #9041
    Maxwell Ogos
    Participant

    hello sir, im making a project named, GSM based motion detector. i did some research on how to make the program code but i didnt found any. so maybe you guys could help me out with the program code?

    i am using a  PIR sensor with 2×16 LCD and a Wavecom GSM on PIC18F4550. i am a MPLab v8.66 user. 

    thank your for your cooperation.

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 34 total)
1 2 3 →
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy | Advertising

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise