PDA

View Full Version : SMS via pic



kenandere
- 7th November 2009, 12:02
Hi friends,

I am trying to prepare a common project for checking and controlling some stuff in my village house; Sensor -> Pic -> Mobile Phone and Mobile Phone -> Pic -> Actuator by using SMS.

But already I spent a considerable time and still I could not succeed. In fact I already checked the forum, but unfortunately still could not succeed.

And as a general information;
Mobile phone is T630 sony ericsson, which supports txt mode.
I use 16F877 (20/P), MAX232, 4 MHz Crystal,
I use pic basic pro,

Below I put some info about my latest situation:

(1) I can communicate between pic to hyper terminal and hyper terminal to pic without problem.
I used a USB1.1 to RS232 converter cable, because I don’t have serial port on my notebook.
Schematic is as shown:
http://i578.photobucket.com/albums/ss223/coldydaturk/scheme_test001.jpg
PBP code is as shown:
' Initialization
TRISB=%00000000
PORTB=%00000000

'Definitions
DEFINE OSC 4
DEFINE HSER_TXSTA 20h
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25

BEGIN:
PORTB = 0
HIGH PORTB.7
PAUSE 1000
LOW PORTB.7
HIGH PORTB.6
HSerout ["AT",13,10] 'TEST COMMUNICATION
HSERIN 5000,begin,[WAIT("OK")]
HIGH PORTB.5
PAUSE 500
GOTO begin

'END
End

Hyper Terminal Settings are as below:
Bits per second:2400 / Data Bits:8 / Parity : None / Stop Bits:1 / Flow Control :None

Both simulation and real test are succeeded;
(2) I can communicate between pc to mobile and mobile to pc without problem. Below you can see some of commands and answers.
Again I used a USB1.1 to RS232 converter cable.

AT
OK
AT+CMGF=?
+CMGF: (0,1)

OK
AT+CMGF=1
OK
AT+CMGS="0XXXXXXXXXX",129 ‘ ”0XXXXXXXXXX” – TEL NO ‘
> "SELAM DENEME MESAJIDIR"
+CMGS: 0

OK

(3) Test Communication between pic and mobile phone,

The same
- pic basic pro program same as above,
- 16f877, 4Mhz, 2400 8-N-1 baud rates.
- the same connections as:
RS232 pins 1-4-6 interconnected, pins 7 and 8 interconnected, pin 5 earth,
RS232 pin2(RX) to leg7(T2OUT) of max232
RS232 pin3(TX) to leg8(R2IN) of max232
PIC RC6/TX to leg10(T2IN) of max232
PIC RC7/RX to leg9(R2OUT) of max232

But this time I can not see the 3rd led, wait 5 seconds and return back to loop. 
This is where I stop, My biggest concerns are :
- baud rate,
- crystal 4Mhz may be not enough,

May I have you kind suggestions?

Most probably one these main problems i have:
- maybe pic can not receive "OK" message from mobile phone
- maybe mobile phone can not receive "AT" command from the pic

:confused:

aratti
- 7th November 2009, 18:08
RS232 pin2(RX) to leg7(T2OUT) of max232
RS232 pin3(TX) to leg8(R2IN) of max232


Since the phone is a DCE device you must change your connection:



RS232 pin3(TX) to leg7(T2OUT) of max232
RS232 pin2(RX) to leg8(R2IN) of max232


Al.

kenandere
- 8th November 2009, 07:06
Thanks aratti for the information,

Frankly speaking i did not have any idea what is DCE device, so i checked the internet and found that:

Typically, one is called DTE (Data Terminal Equipment) and the
other is called DCE (Data Circuit-Terminating Equipment). For instance, in EIA-
232 communications, DTE devices (terminals, PCs, mini-computers) are quite
stubborn and only want to talk to DCE devices (modems, multiplexers), and vice
versa. For this reason, you may connect a PC COM port to a modem using a
"straight through" EIA-232 cable. However, when you must connect a PC COM
port to another PC COM port, you must use a "null-modem" cable. The function
of the null modem cable is to "trick" the DTE device into believing that it is
talking to a DCE device by cross-wiring the data and control pins in the cable.
Ethernet AUI (Attachment Unit Interface) also uses the DTE/DCE convention,
However, itÕs not as simple as it is with EIA-232.

So in this case i think you meant: Microcontroller and mobile phone are both DCE device, so i need to cross-over RX and TX cables of the serial port.

I will try this asap and inform back the result, thanks a lot.

kenandere
- 8th November 2009, 08:18
Hi again,

in normal connection;
* RC6/TX -> T2IN AND T2OUT -> PIN2 RXD
* RC7/RX -> R2OUT AND R2IN -> PIN3 TXD

i tried also cross-over connection, but no success ;
* RC6/TX -> T2IN AND T2OUT -> PIN3 TXD
* RC7/RX -> R2OUT AND R2IN -> PIN2 RXD

i tried both connections again but still no success :(

any idea or suggestion is really appreciated , thanks...

kenandere
- 8th November 2009, 08:36
Hi Everybody;

Let me tell you, one of my observation;
i checked the voltage levels at RXD and TXD pins of the mobile phone in both normal and cross-over connections:

in normal connection:

* RC6/TX -> T2IN AND T2OUT -> PIN2 RXD;
PIN2 has negative voltage around 7 or 8 Volts,
When signal comes from pic , it makes a sudden change

* RC7/RX -> R2OUT AND R2IN -> PIN3 TXD
PIN3 has 0 voltage,
When signal comes from pic , it does not make a sudden change


i tried also cross-over connection;

* RC6/TX -> T2IN AND T2OUT -> PIN3 TXD
PIN3 has negative voltage around 6 or 7 Volts,
When signal comes from pic , it makes a sudden change

* RC7/RX -> R2OUT AND R2IN -> PIN2 RXD
PIN2 has negative voltage around 5 or 6 Volts,
When signal comes from pic , it does not make a sudden change

Do you have any idea, what is going on ? :confused:

kenandere
- 8th November 2009, 13:54
Hi people, try-outs continue :(

I started to try different baud rates with different crystals as below:
4Mhz/2400 - 4Mhz/4800 - 8Mhz/4800 - 8Mhz/9600

But during these changes, of course I need to make some different definitions about serial communication:


'Definitions
DEFINE OSC 4 'for 4 Mhz
'DEFINE OSC 8 'for 8 Mhz

DEFINE HSER_TXSTA 20h 'I wonder shall I define as DEFINE HSER_TXSTA 24h???
DEFINE HSER_RCSTA 90h 'same for all

DEFINE HSER_BAUD 2400 'for 2400 Baud rate
'DEFINE HSER_BAUD 4800 'for 4800 Baud rate
'DEFINE HSER_BAUD 9600 'for 9600 Baud rate

DEFINE HSER_SPBRG 25 'for 4Mhz/2400 & 8Mhz/4800 with an error %0.16
'DEFINE HSER_SPBRG 12 'for 4Mhz/4800 & 8Mhz/9600 with an error %0.16

DEFINE HSER_CLROERR 1 'same for all

'Initialization
TRISB=%00000000
PORTB=%00000000

'Program Starts
BEGIN:
PORTB = 0
HIGH PORTB.7
PAUSE 1000
LOW PORTB.7
HIGH PORTB.6
HSEROUT ["AT",13] 'send AT to modem followed by a CR and line feed
HSERIN 5000, BEGIN, [WAIT("OK")] 'now wait for 5secs until OK is received however
HIGH PORTB.5
PAUSE 500
GOTO BEGIN 'if it is not then goto the SMS routine again

'END
End

Unfortunately none of above succeeded :(

kenandere
- 8th November 2009, 21:11
Btw i would like to show you setup; maybe i have a simple mistake :(.

Thanks for your time and attention,

Regards,

aratti
- 8th November 2009, 22:14
Tray to connect your system as per the attached schematic.This works for me.

With MAX232 you should not use electrolytic capacitors. See the datasheet.

Make sure you have proper contacts in your layout.

.

Al.

kenandere
- 9th November 2009, 16:20
Thanks to your kind suggestions all, especially aratti;

In fact, Ajay Bhargav from 8051projects.net forum, I really appreciate his latest comment .

The solution is; making some additional connections at GSM serial port, as below;
http://i578.photobucket.com/albums/ss223/coldydaturk/GSMserialportconnetion.jpg


Before I only connected, RX,TX and GRND pins of the GSM serial port.

And below you can see the general connection latest I made:
http://i578.photobucket.com/albums/ss223/coldydaturk/scheme_test006.jpg


And a program to send sms and or call a phone number is as follows:

'Definitions
DEFINE OSC 4 'for 4 Mhz
'DEFINE OSC 8 'for 8 Mhz

DEFINE HSER_TXSTA 20h 'I wonder shall I define as DEFINE HSER_TXSTA 24h???
DEFINE HSER_RCSTA 90h 'same for all

DEFINE HSER_BAUD 2400 'for 2400 Baud rate
'DEFINE HSER_BAUD 4800 'for 4800 Baud rate
'DEFINE HSER_BAUD 9600 'for 9600 Baud rate

DEFINE HSER_SPBRG 25 'for 4Mhz/2400 & 8Mhz/4800 with an error %0.16
'DEFINE HSER_SPBRG 12 'for 4Mhz/4800 & 8Mhz/9600 with an error %0.16

DEFINE HSER_CLROERR 1 'same for all

' Initialization & Declaration
i var byte
TRISB=%00000000
PORTB=%00000000
TRISD=%00001111
PORTD=%00000000

' CHECK
FIRSTCHECK:
HIGH PORTB.7
PAUSE 500
HIGH PORTB.6
PAUSE 500
HIGH PORTB.5
PAUSE 500
HIGH PORTB.4
PAUSE 500
PORTB=%00000000

GSM_CHECK:
HSEROUT ["AT",13] 'Send AT to modem followed by a CR
HSERIN 5000, GSM_CHECK, [WAIT("OK")] 'Check OK reply, wait 5sec max.
HIGH PORTB.7
PAUSE 1000

HSEROUT ["AT+GMM",13] 'Ask model name
HSERIN 5000, GSM_CHECK, [WAIT("T610 series")] 'Check model name
HIGH PORTB.6
PAUSE 1000

HSEROUT ["AT+IPR=2400",13] 'Set transfer speed
HSERIN 5000, GSM_CHECK, [WAIT("OK")]'Check OK reply, wait 5sec max.
HIGH PORTB.5
PAUSE 1000

HSEROUT ["AT+CMGF=1",13] 'send AT to modem followed by a CR and line feed
HSERIN 5000, GSM_CHECK, [WAIT("OK")]'Check OK reply, wait 5sec max.
HIGH PORTB.4
PAUSE 1000

PORTB=%00000000

BEGIN:
IF PORTB.5=1 THEN ERROR_CALL
IF PORTB.6=1 THEN ERROR_SMS
HIGH PORTB.7
pause 1000
LOW PORTB.7
if PORTD.2 = 0 then SEND_SMS
IF PORTD.3 = 0 THEN CALL_PHONE
PAUSE 1000
GOTO BEGIN

SEND_SMS:
HIGH PORTB.6
HSEROUT ["at+cmgs=",34,"XXXXX",34,13]
PAUSE 1000
HSEROUT ["this is a test message",26]
HSERIN 10000, BEGIN, [WAIT("OK")]'Check OK reply, wait 5sec max.
LOW PORTB.6
GOTO BEGIN

CALL_PHONE:
HIGH PORTB.5
HSEROUT ["atd[XXXXX];",13]
HSERIN 5000, BEGIN, [WAIT("OK")]'Check OK reply, wait 5sec max.
PAUSE 2000
LOW PORTB.5
GOTO BEGIN

ERROR_CALL:
FOR i = 1 to 5
HIGH PORTB.4
PAUSE 500
LOW PORTB.4
PAUSE 500
next i
PORTB=%00000000
GOTO BEGIN

ERROR_SMS:
FOR i = 1 to 5
HIGH PORTB.4
PAUSE 500
LOW PORTB.4
PAUSE 500
next i
PORTB=%00000000
GOTO BEGIN

' END
End

Thanks again for your attention and time, I will continue with :
- Improving the program to a real case scenario,
- Think more about the real case scenario, because at first stage I would like to use this as an alarm system for my garden house. I will need some sensors for unexpected visitors or animals.

Do you have any idea, what kind of sensors I can use to detect unexpected visitors?

Regards,

aratti
- 9th November 2009, 16:31
Glad to know you have finally your gsm system at work.


- Think more about the real case scenario, because at first stage I would like to use this as an alarm system for my garden house. I will need some sensors for unexpected visitors or animals.

Do you have any idea, what kind of sensors I can use to detect unexpected visitors?


Just take a look at one of my project @ http://techni.caliti.es/blog/2008/12/sms-io-controller.html

Al.

ScaleRobotics
- 9th November 2009, 16:42
Do you have any idea, what kind of sensors I can use to detect unexpected visitors?
Regards,

Most (inexpensive) motion sensors use an infra red sensor with a fresnel lense on it. The heat of the human/animal is above background, so as it moves, the fresnel lense makes the heat hit and miss the sensor. This gives quick varying temperatures, where normal heating and cooling of the room, or outdoors, occurs slowly.

You can go to the hardware store and buy a cheap outdoor light and steal the parts out of it like this:
http://www.acehardware.com/product/index.jsp?productId=2467595&CAWELAID=109386813

Or buy the parts:
http://www.futurlec.com/PIR_Sensors.shtml

Byte_Butcher
- 9th November 2009, 21:30
Do you have any idea, what kind of sensors I can use to detect unexpected visitors?


These are nice little IR sensors. They even have serial interface. For outdoor use they'll obviously need some protection...

http://www.zilog.com/docs/devtools/PS0284.pdf
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=269-4710-ND


steve

Dennis
- 26th November 2009, 02:07
Hi all

As input sensors you could use security lights that have a PIR that have a 12Volt buzzer output and use that as the input trigger for your pic.
Is there any possiblity of using the mobile phone's camera to take a pic and send that as an MMS ?

Kind regards

Dennis

suwanggoh
- 7th March 2010, 06:50
hi kenandere,

i just want to confirm the connections of rs232 on the GSM side.

you short the pin 1,4,6 and short pin 7,8?

i succeed in sending sms from PIC, but i couldnt get any response from the phone t630.

thank

suwang

kenandere
- 8th March 2010, 05:32
Hello Suwang,

Yeah as say, 1-4-6 and 7-8.

Regards,

dumato52
- 10th March 2010, 10:00
Hullo every one thankyou for ur help;
I am doing project related to the one of kenandere above, but am not using the sensors, am using +5V to act as an interrupt to PIC16F84 microcontroller which is connected to the phone, the pic16f84 should send an SMS to the programmed number after receiving an interrupt;
My questions are;
How do i know whether my phone supports AT commands?
Can program above work on pic16f84?
Components i have so far
-pic16f84
-2330 nokia
-max232
pliz help me, i will be glad, thankyou in advance