Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

help me to interface gsm module to the rest of my project!

Status
Not open for further replies.

nitish_R

Newbie level 4
Joined
Oct 23, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
149
hello.. this is about the minor project that I have to make this semester.
I'm making a electronic keypad lock using gsm module.
the proposed working of my project is that there's a password set and we enter that password through a keypad
if the password entered is correct, a msg is displayed on the lcd "lock open".. and if a wrong password is entered. the msg displayed is "wrong password"..
and another chance of entering the password is given.. similarly there are 4 chances given to enter the correct password.. if a wrong one is entered on all 4 attempts.. msg diaplayed is "sorry no more trials"..
and a msg should den b sent to the owner of that project, which should be something like "illegal attempt"..

firstly i'm making the code of this program..
i have completed the code for the functioning of my project till entering wrong or right passwords and displaying of respective msgs on lcd.
the only thing left is to send a message to the owner on 4th wrong attempt, when the lcd displays the msg "sorrry no more trials"!

for this i need to interface a gsm modem in my circuit diagram and make corresponding changes in the code
but i have no idea of doing this!
to use a gsm module, i also have to use an IC MAX232 and RS232..
i have completed the circuit diagram.. but not able to make out what is the code that needs to be added on in my code to get this feature of gsm module added!
please provide me with the code that needs to be added on and tell me where in my code i need to make the required changes!

im attaching my code that works till where i have told u about, the circuit diagram that shows dis much of working
and the complete circuit diagram that i have prepared but dont know what code is required for it to work!

please help me asap!. im in great hurry and have very few days to complete dis on hardware as well!!
please help me with the code asap!!! :| :|
 

this the code that i'm using , but i wasnt able to attach the image of the circuit..
on attaching the image here.. its showing up some msg that it doesnt supports such format!

code-
#include<reg51.h>
#define port P3
#define dataport P2
#define key P1
#define sec 100
sbit rs = port^2;
sbit rw = port^3;
sbit en = port^4;

sbit col1=key^4;
sbit col2=key^5;
sbit col3=key^6;
sbit row1=key^0;
sbit row2=key^1;
sbit row3=key^2;
sbit row4=key^3;
sbit lock_output=P1^7;

int check=0;
int digit[4]={0,0,0,0};
int dig_one=1;
int dig_two=2;
int dig_three=3;
int dig_four=4;
int i,count=0;

void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string to LCD
{
int i=0;
while(str!='\0')
{
lcd_data(str);
i++;
//delay(10);
}
return;
}

void lcd(unsigned char str[10]) // Function to send string to LCD
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_data_string(str);
}

void ans()
{
if(check>3)
{
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_string(" LOCK OPEN");
lock_output=1;
delay(500);
}
else
{
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_string(" WRONG PASSWORD");
lock_output=0;
count++;
delay(500);
}
}

void code_check() // Function to check password
{
if(i<=3 )
{
switch((i+1))
{
case 1: {
if(dig_one==digit[0])
{
check=check+1;
}
break;
}

case 2: {
if(dig_two==digit[1])
{
check=check+1;
}
break;
}

case 3: {
if(dig_three==digit[2])
{
check=check+1;
}
break;
}

case 4: {
if(dig_four==digit[3])
{
check=check+1;
}
break;
}
}
}
if(i==3)
{
ans();
}
}


void display(int a) //Display function
{
switch(a)
{
case 1:{
lcd_data('1');
delay(30);
digit=1;
code_check();
break;
}
case 2:{
lcd_data('2');
delay(30);
digit=2;
code_check();
break;
}
case 3:{
lcd_data('3');
delay(30);
digit=3;
code_check();
break;
}
case 4:{
lcd_data('4');
delay(30);
digit=4;
code_check();
break;
}
case 5:{
lcd_data('5');
delay(30);
digit=5;
code_check();
break;
}
case 6:{
lcd_data('6');
delay(30);
digit=6;
code_check();
break;
}
case 7:{
lcd_data('7');
delay(30);
digit=7;
code_check();
break;
}
case 8:{
lcd_data('8');
delay(30);
digit=8;
code_check();
break;
}
case 9:{
lcd_data('9');
delay(30);
digit=9;
code_check();
break;
}
case 0:{
lcd_data('0');
delay(30);
digit=0;
code_check();
break;
}
}
}

void check_col1()
{
row1=row2=row3=row4=1;
row1=0;
if(col1==0)
display(1);
row1=1;
row2=0;
if(col1==0)
display(4);
row2=1;
row3=0;
if(col1==0)
display(7);
row3=1;
row4=0;
if(col1==0)
{
row4=1;
}
}

void check_col2()
{
row1=row2=row3=row4=1;
row1=0;
if(col2==0)
display(2);
row1=1;
row2=0;
if(col2==0)
display(5);
row2=1;
row3=0;
if(col2==0)
display(8);
row3=1;
row4=0;
if(col2==0)
display(0);
row4=1;
}

void check_col3()
{
row1=row2=row3=row4=1;
row1=0;
if(col3==0)
display(3);
row1=1;
row2=0;
if(col3==0)
display(6);
row2=1;
row3=0;
if(col3==0)
display(9);
row3=1;
row4=0;
if(col3==0)
{
row4=1;
}
}

void main()
{
col1=col2=col3=1;
while(1)
{
lcd_cmd(0x01); //Clear LCD screen
lock_output=0;
lcd_cmd(0x82); // Set cursor on position first of first line
lcd("ENTER PASSWORD");
check=0;
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
for(i=0;i<4;i++)
{
delay(100);
lcd_cmd(0xc4+i);
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
row1=row2=row3=row4=0;
if(col1==0)
check_col1();
else
if(col2==0)
check_col2();
else
if(col3==0)
check_col3();
if(count==4)
{
lcd_cmd(0x01);
lcd_cmd(0x86);
lcd("SORRY");
lcd_cmd(0xc1);
lcd("NO MORE TRIALS");
while(1);
}
}
}
}

- - - Updated - - -

this is the circuit diagram-

zz.png
 

first there is no need of while(1) end of your program.
second initialization of lcd function and keypad function is below the main line and above the while(1).
 

i wanted to know that how to interface gsm module with this much of coding done!
what are the changes required, what part i need to add and where to add it in my code?
 

well, you can do it at the end. i.e at last "if" condition (count==4). just add a fuction so that you write some data on to uart tx fifo, that should be generally your AT commands used by GSM modem. Just write into those tx fifo of uart and make sure txfifo does not overflow, just know the size of txfifo of uart and wait for the transmission successful interrupt , or just poll on that status.
 

Your schematic is incomplete, and from what I can tell, incorrectly wired up to the DB9 serial port connector. At minimum, you will need to have the TxD and RxD pins on the connector wired to your MAX232 chip, and likely CTS and RTS (though many modems use the DTR pin for switching between command and data mode - but if ou are just sending simple text msgs then you won't need that). And Ground,(Pin5) of course.

The modem will have a port that is configured as DCE (Data Communication Equipment), and your circuit board would have its pinout configuration as DTE (Data Terminal Equipment). So, Pin3 of DB9 connector should be your TxD (data OUT to modem) and Pin2 should be your RxD (data IN from modem). Likewise connect up the other signal pins as you need (RTS/CTS) or (DTR/DSR). Check the manual of the modem you choose to see how it can be configured for flow control - they usually support hardware and software (Xon/Xoff characters). you can reference this as a guide for your pinout on the connector.
**broken link removed**
 

Your schematic is incomplete, and from what I can tell, incorrectly wired up to the DB9 serial port connector. At minimum, you will need to have the TxD and RxD pins on the connector wired to your MAX232 chip, and likely CTS and RTS (though many modems use the DTR pin for switching between command and data mode - but if ou are just sending simple text msgs then you won't need that). And Ground,(Pin5) of course.

The modem will have a port that is configured as DCE (Data Communication Equipment), and your circuit board would have its pinout configuration as DTE (Data Terminal Equipment). So, Pin3 of DB9 connector should be your TxD (data OUT to modem) and Pin2 should be your RxD (data IN from modem). Likewise connect up the other signal pins as you need (RTS/CTS) or (DTR/DSR). Check the manual of the modem you choose to see how it can be configured for flow control - they usually support hardware and software (Xon/Xoff characters). you can reference this as a guide for your pinout on the connector.
**broken link removed**



i have modified my code and is complete according to me..
please chech and tell me that the coding for gsm modem that i have added, is it correct?
on compiling it in leil..it does not show any errors or warnings
but plz tell me that is it logically correct and will it function correctly, tha way i want it to?

#include<reg51.h>
#define port P3
#define dataport P2
#define key P1
#define sec 100
sbit rs = port^2;
sbit rw = port^3;
sbit en = port^4;

sbit col1=key^4;
sbit col2=key^5;
sbit col3=key^6;
sbit row1=key^0;
sbit row2=key^1;
sbit row3=key^2;
sbit row4=key^3;
sbit lock_output=P1^7;

int check=0;
int digit[4]={0,0,0,0};
int dig_one=1;
int dig_two=2;
int dig_three=3;
int dig_four=4;
int i,count=0;
void serial_init()
{
SCON=0x50; //setup for 8-bit data
TMOD=0x20; //setup timer 1 for auto-reload
TL1=0xFd; //setup for 9600 baud
TH1=0xfd; //Baud Rate 9600
TR1=1; //turn on timer 1
}

void send_serial(unsigned char *s)
{
while(*s!=0x0)
{
SBUF=*s;
while(!TI)
{
}
TI=0;
s++;
}
}

void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string to LCD
{
int i=0;
while(str!='\0')
{
lcd_data(str);
i++;
//delay(10);
}
return;
}

void lcd(unsigned char str[10]) // Function to send string to LCD
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_data_string(str);
}

void ans()
{
if(check>3)
{
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_string(" LOCK OPEN");
lock_output=1;
delay(500);
}
else
{
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_string(" WRONG PASSWORD");
lock_output=0;
count++;
delay(500);
}
}

void code_check() // Function to check password
{
if(i<=3 )
{
switch((i+1))
{
case 1: {
if(dig_one==digit[0])
{
check=check+1;
}
break;
}

case 2: {
if(dig_two==digit[1])
{
check=check+1;
}
break;
}

case 3: {
if(dig_three==digit[2])
{
check=check+1;
}
break;
}

case 4: {
if(dig_four==digit[3])
{
check=check+1;
}
break;
}
}
}
if(i==3)
{
ans();
}
}


void display(int a) //Display function
{
switch(a)
{
case 1:{
lcd_data('1');
delay(30);
digit=1;
code_check();
break;
}
case 2:{
lcd_data('2');
delay(30);
digit=2;
code_check();
break;
}
case 3:{
lcd_data('3');
delay(30);
digit=3;
code_check();
break;
}
case 4:{
lcd_data('4');
delay(30);
digit=4;
code_check();
break;
}
case 5:{
lcd_data('5');
delay(30);
digit=5;
code_check();
break;
}
case 6:{
lcd_data('6');
delay(30);
digit=6;
code_check();
break;
}
case 7:{
lcd_data('7');
delay(30);
digit=7;
code_check();
break;
}
case 8:{
lcd_data('8');
delay(30);
digit=8;
code_check();
break;
}
case 9:{
lcd_data('9');
delay(30);
digit=9;
code_check();
break;
}
case 0:{
lcd_data('0');
delay(30);
digit=0;
code_check();
break;
}
}
}

void check_col1()
{
row1=row2=row3=row4=1;
row1=0;
if(col1==0)
display(1);
row1=1;
row2=0;
if(col1==0)
display(4);
row2=1;
row3=0;
if(col1==0)
display(7);
row3=1;
row4=0;
if(col1==0)
{
row4=1;
}
}

void check_col2()
{
row1=row2=row3=row4=1;
row1=0;
if(col2==0)
display(2);
row1=1;
row2=0;
if(col2==0)
display(5);
row2=1;
row3=0;
if(col2==0)
display(8);
row3=1;
row4=0;
if(col2==0)
display(0);
row4=1;
}

void check_col3()
{
row1=row2=row3=row4=1;
row1=0;
if(col3==0)
display(3);
row1=1;
row2=0;
if(col3==0)
display(6);
row2=1;
row3=0;
if(col3==0)
display(9);
row3=1;
row4=0;
if(col3==0)
{
row4=1;
}
}

void main()
{
col1=col2=col3=1;
while(1)
{
lcd_cmd(0x01); //Clear LCD screen
lock_output=0;
lcd_cmd(0x82); // Set cursor on position first of first line
lcd("ENTER PASSWORD");
check=0;
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
for(i=0;i<4;i++)
{
delay(100);
lcd_cmd(0xc4+i);
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
row1=row2=row3=row4=0;
if(col1==0)
check_col1();
else
if(col2==0)
check_col2();
else
if(col3==0)
check_col3();
if(count==4)
{
lcd_cmd(0x01);
lcd_cmd(0x86);
lcd("SORRY");
lcd_cmd(0xc1);
lcd("NO MORE TRIALS");
serial_init();
for(i=1;i<=2;i++)
{
send_serial("AT\r");
delay(400);
send_serial("AT+CMGF=1\r");
delay(400);
send_serial("AT+CMGS=\"09582703501\"\r");
delay(400);
send_serial("Security Breach!\r");
delay(400);
send_serial("0x1A\r");
}
while(1);
}
}
}
}
 

i have modified my code and is complete according to me..
please check and tell me that the coding for gsm modem that i have added, is it correct?
on compiling it in keil..it does not show any errors or warnings
but plz tell me that is it logically correct and will it function correctly, tha way i want it to?

#include<reg51.h>
#define port P3
#define dataport P2
#define key P1
#define sec 100
sbit rs = port^2;
sbit rw = port^3;
sbit en = port^4;

sbit col1=key^4;
sbit col2=key^5;
sbit col3=key^6;
sbit row1=key^0;
sbit row2=key^1;
sbit row3=key^2;
sbit row4=key^3;
sbit lock_output=P1^7;

int check=0;
int digit[4]={0,0,0,0};
int dig_one=1;
int dig_two=2;
int dig_three=3;
int dig_four=4;
int i,count=0;
void serial_init()
{
SCON=0x50; //setup for 8-bit data
TMOD=0x20; //setup timer 1 for auto-reload
TL1=0xFd; //setup for 9600 baud
TH1=0xfd; //Baud Rate 9600
TR1=1; //turn on timer 1
}

void send_serial(unsigned char *s)
{
while(*s!=0x0)
{
SBUF=*s;
while(!TI)
{
}
TI=0;
s++;
}
}

void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string to LCD
{
int i=0;
while(str!='\0')
{
lcd_data(str);
i++;
//delay(10);
}
return;
}

void lcd(unsigned char str[10]) // Function to send string to LCD
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_data_string(str);
}

void ans()
{
if(check>3)
{
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_string(" LOCK OPEN");
lock_output=1;
delay(500);
}
else
{
lcd_cmd(0x01);
lcd_cmd(0x82);
lcd_data_string(" WRONG PASSWORD");
lock_output=0;
count++;
delay(500);
}
}

void code_check() // Function to check password
{
if(i<=3 )
{
switch((i+1))
{
case 1: {
if(dig_one==digit[0])
{
check=check+1;
}
break;
}

case 2: {
if(dig_two==digit[1])
{
check=check+1;
}
break;
}

case 3: {
if(dig_three==digit[2])
{
check=check+1;
}
break;
}

case 4: {
if(dig_four==digit[3])
{
check=check+1;
}
break;
}
}
}
if(i==3)
{
ans();
}
}


void display(int a) //Display function
{
switch(a)
{
case 1:{
lcd_data('1');
delay(30);
digit=1;
code_check();
break;
}
case 2:{
lcd_data('2');
delay(30);
digit=2;
code_check();
break;
}
case 3:{
lcd_data('3');
delay(30);
digit=3;
code_check();
break;
}
case 4:{
lcd_data('4');
delay(30);
digit=4;
code_check();
break;
}
case 5:{
lcd_data('5');
delay(30);
digit=5;
code_check();
break;
}
case 6:{
lcd_data('6');
delay(30);
digit=6;
code_check();
break;
}
case 7:{
lcd_data('7');
delay(30);
digit=7;
code_check();
break;
}
case 8:{
lcd_data('8');
delay(30);
digit=8;
code_check();
break;
}
case 9:{
lcd_data('9');
delay(30);
digit=9;
code_check();
break;
}
case 0:{
lcd_data('0');
delay(30);
digit=0;
code_check();
break;
}
}
}

void check_col1()
{
row1=row2=row3=row4=1;
row1=0;
if(col1==0)
display(1);
row1=1;
row2=0;
if(col1==0)
display(4);
row2=1;
row3=0;
if(col1==0)
display(7);
row3=1;
row4=0;
if(col1==0)
{
row4=1;
}
}

void check_col2()
{
row1=row2=row3=row4=1;
row1=0;
if(col2==0)
display(2);
row1=1;
row2=0;
if(col2==0)
display(5);
row2=1;
row3=0;
if(col2==0)
display(8);
row3=1;
row4=0;
if(col2==0)
display(0);
row4=1;
}

void check_col3()
{
row1=row2=row3=row4=1;
row1=0;
if(col3==0)
display(3);
row1=1;
row2=0;
if(col3==0)
display(6);
row2=1;
row3=0;
if(col3==0)
display(9);
row3=1;
row4=0;
if(col3==0)
{
row4=1;
}
}

void main()
{
col1=col2=col3=1;
while(1)
{
lcd_cmd(0x01); //Clear LCD screen
lock_output=0;
lcd_cmd(0x82); // Set cursor on position first of first line
lcd("ENTER PASSWORD");
check=0;
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
for(i=0;i<4;i++)
{
delay(100);
lcd_cmd(0xc4+i);
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
row1=row2=row3=row4=0;
if(col1==0)
check_col1();
else
if(col2==0)
check_col2();
else
if(col3==0)
check_col3();
if(count==4)
{
lcd_cmd(0x01);
lcd_cmd(0x86);
lcd("SORRY");
lcd_cmd(0xc1);
lcd("NO MORE TRIALS");
serial_init();
for(i=1;i<=2;i++)
{
send_serial("AT\r");
delay(400);
send_serial("AT+CMGF=1\r");
delay(400);
send_serial("AT+CMGS=\"09582703501\"\r");
delay(400);
send_serial("Security Breach!\r");
delay(400);
send_serial("0x1A\r");
}
while(1);
}
}
}
}

- - - Updated - - -

please reply to my query!
i have also made the change in my circuit diagram as told by you and will soon paste the picture of my modified circuit diagram here
but for now plz tell abt the code!
 

Remove this line


Code C - [expand]
1
TL1=0xFd; //setup for 9600 baud



Add these lines


Code C - [expand]
1
2
EA = 1;
ES = 1;




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void send_serial(unsigned char *s)
{
    while(*s)
        sendByte(*s++);
}
 
void sendByte(unsigned char Byte){
    SBUF = Byte;
    while(!TI); 
    TI = 0;
 
}
 
// if attempt == 4
send_serial("AT\r\n");
delay(400);
send_serial("AT+CMGF=1\r\n");
// 2 sec delay
send_serial("AT+CMGS=\"09582703501\"\r\n");
// 1 sec delay
delay(400);
send_serial("Security Breach!\r");
// 100 ms delay
sendByte(0x1A);
sendByte(0x0D);
// attempt = 0

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top