Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

GSM Based security.please help me on the following thread as i am new to microcontrol

Status
Not open for further replies.

Marabe

Newbie level 4
Joined
Nov 24, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
hello everyone.

i am working on a project called GSM Based home security alarm.i am using pic16f887 and a m-q6 gas sensor and a pir motion sensor.i have build a motion sensor circuit on breadboard without the gas sensor and it works perfectly well.now i wanted to connect the gsm module which is the siemens TC35 module to the motion sensor circuit,i have used max232 as the level shifter.the problem i have is,i cant get the sms on my fone when using pic16f887 but i can send and make a call using the gsm modem on the hype terminal.i have attached the my c code and the manual of the modem i am using.please help me as i am left with two days before the presentations. below is my c code.

unsigned int motion_rd, gas_rd;

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

char top[] = "GSM BASED";
char bottom[]="SECURITY SYSTEM";
char txt1[] = "0";
unsigned int alarmCounter = 0;

void SendMessage();
void main()
{
uart1_init(9600);
delay_ms(100);

ansel=0x03;
anselh=0;
c1on_bit=0;
c2on_bit=0;

TRISA = 0XFF;
TRISD = 0;
PORTD = 0;
Sound_Init(&PORTB,6);
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); //clearing display
Lcd_Cmd(_LCD_CURSOR_OFF); // turning off the cursor
Lcd_Out(1,4,top);
Lcd_Out(2,1,bottom);
adc_init();

do
{
// detect motion
motion_rd = ADC_read(2);
gas_rd = ADC_read(3);

if( gas_rd < 5)
{
IntToStr(gas_rd,txt1);
Lcd_Cmd(_LCD_CLEAR); //clearing display
Lcd_Out(1,2,"SYSTEM ENGAGED");
Lcd_Out(2,1,txt1);
//Lcd_Out(2,1,"GAS LEAKAGE");
// Lcd_Out(2,1,"GAS LEAKAGE");
alarmCounter ++;
//gas_rd = 0;
Delay_ms(300);
}


if(motion_rd > 1)
{
IntToStr(motion_rd,txt1);
Lcd_Cmd(_LCD_CLEAR); //clearing display
Lcd_Out(1,2,"SYSTEM ENGAGED");
// Lcd_Out(2,1,txt1);
Lcd_Out(2,1,"MOTION DETECTED");
Lcd_Out(2,1,"MOTION DETECTED");
alarmCounter ++;
motion_rd = 0;
Delay_ms(300);
}
if(alarmCounter != 0)
{
SendMessage();
PORTD = 0x01;
alarmCounter ++;
Delay_ms(100);

if(alarmCounter == 20)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,top);
Lcd_Out(2,1,bottom);
alarmCounter = 0;
PORTD = 0x00;
}
}



}
while(1);
}

//Send a GSM message if there is any security bridge.
void SendMessage()

{
uart1_write("AT");
uart1_write(13);
delay_ms(10);


uart1_write("AT+CMGF=1"); //set to massage mode and text mode
uart1_write(13);
delay_ms(10);

uart1_write("AT+CSCA=+26655820088"); // set the simcard/phone massage center number
uart1_write(13);
delay_ms(10);

uart1_write("AT+CMGS=+26662050052"); //set the phone number which the sms will be send to.
uart1_write(13);
//uart1_write_text("AT+CMGS=+26662050052");
delay_ms(10);

//uart1_write("\r");
UART1_Write_Text("WARNING!!Motion detected"); // my text
UART1_Write(0x1A); //(CR) means Enter
UART1_Write(0x0D); //(CR) means Enter
Delay_ms(100);
}
 

Attachments


GSM Man

Banned
Joined
Apr 15, 2009
Messages
671
Helped
168
Reputation
338
Reaction score
94
Trophy points
1,308
Location
New Jersey, USA
Activity points
0
Using delays between commands is going to get you in trouble at some point in your development - it's the number 2 problem I see with people using GSM modules. You should retrieve the response from the module and determine what you should send based on what it returns. In your case you may be sending the text before the module is ready for it. When you use Hyper Terminal it takes you longer to type the response than the 10mS you are waiting in your code

uart1_write("AT+CMGS=+26662050052"); //set the phone number which the sms will be send to.
uart1_write(13);
delay_ms(10);

You need to wait here for the module to return a ">" character indicating that it is ready for the text message

UART1_Write_Text("WARNING!!Motion detected"); // my text
UART1_Write(0x1A); //(CR) means Enter
UART1_Write(0x0D); //(CR) means Enter
 
  • Like
Reactions: msj121

    msj121

    points: 2
    Helpful Answer Positive Rating

Marabe

Newbie level 4
Joined
Nov 24, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
thanks GSM Man.so how much delay should i use atleast?
 

GSM Man

Banned
Joined
Apr 15, 2009
Messages
671
Helped
168
Reputation
338
Reaction score
94
Trophy points
1,308
Location
New Jersey, USA
Activity points
0
That's the problem with using delays -there's no way of telling! You may test it with a delay of x Ms and everything works just fine, then when you get your device in out in the field it stops working because the time between command and response has become longer than your delay. There are a lot of factors that can effect the response time, and if you put a delay in there that is long enough to cover all cases, your communications becomes very slow. I'd recommend you put the effort in to developing a driver that waits for the response to the command.

I recently helped someone with just a such a problem. They had units in the field that started failing and it turned out that with some SIM cards it took longer for the module to become ready to accept commands then it did during their testing.
 

Marabe

Newbie level 4
Joined
Nov 24, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
but with putty,it doesnt take long to respond.

- - - Updated - - -

but with putty,it doesnt take long to respond.
 

GSM Man

Banned
Joined
Apr 15, 2009
Messages
671
Helped
168
Reputation
338
Reaction score
94
Trophy points
1,308
Location
New Jersey, USA
Activity points
0
The fastest typist in the world can type about 185 words/minute which is about 50mS between characters.
 

Marabe

Newbie level 4
Joined
Nov 24, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
thanks,i am going to try to change the delays until maybe it works.what might be other problems that may cause it not to respond so that i can look at all possible problems?
 

GSM Man

Banned
Joined
Apr 15, 2009
Messages
671
Helped
168
Reputation
338
Reaction score
94
Trophy points
1,308
Location
New Jersey, USA
Activity points
0
Look at what the module sends back in response to the command - is it returning an error? The module will tell you what the problem is.
 

Marabe

Newbie level 4
Joined
Nov 24, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
how should i check that with the code inside the microcontroller?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,860
Helped
14,119
Reputation
28,495
Reaction score
12,800
Trophy points
1,393
Location
Bochum, Germany
Activity points
277,784
A good designed GSM communication application would process the modem response for each command, possibly repeat the command if the network is temprarily unavailable and things like this. I guess rewriting to your application isn#t an actual option, so you should make the present "poor man's" code work somehow. The best way to debug code operation is to connect a PC as RS232 sniffer, preferably connecting separate ports for RX and TX with a software tool like Docklight. Displaying modem responses only with Hyperterminal should be sufficient if you have modem echo enabled (the default setting).

I presume that you are aware of the UART connection requirements, logic level at GSM module and processor, RS232 at PC, and handshake signals that have to connected to enable the GSM module.
 
  • Like
Reactions: tpetar

    tpetar

    points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top