View Full Version : How to control servo motor with handphone through GSM modem?
supertyx
- 14th May 2008, 06:58
Hi all,
I am currently doing a mini project of controlling the servo motor using easypic4.
I managed to control the direction the servo turns by using the pushbuttons on the board to make it turn clockwise or counter-clockwise.
However, I would like to control the servo by sending a message using handphone to the GSM modem which is connected to the RS232 com port of the easypic4 and make the servo turns accordingly.
What are the additional codes which I need to control using handphone?
Any help would be appreciated. Thanks. =)
skimask
- 14th May 2008, 12:56
I am currently doing a mini project of controlling the servo motor using easypic4.
I managed to control the direction the servo turns by using the pushbuttons on the board to make it turn clockwise or counter-clockwise.
However, I would like to control the servo by sending a message using handphone to the GSM modem which is connected to the RS232 com port of the easypic4 and make the servo turns accordingly.
What are the additional codes which I need to control using handphone?
Wow.........
Ioannis
- 14th May 2008, 13:41
I could say a lot of additional code...
In this special category on GSM there are many examples... Just search through. I warn you it is not an easy project...
Ioannis
supertyx
- 15th May 2008, 05:34
First I wrote a couple of codes to test the AT commands with SEROUT2 and Tx Command between my PC and the PIC16F77A (CPU) on the easypic4 using hyperterminal.
These are the codes:
INCLUDE "modedefs.bas"
'PIC16F877A specific
@ __CONFIG _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
'This is a simple program to drive a servo using easypic4 and pushbuttons.
'PORTB.0 - Set to drive the servo clockwise to the center.
'PORTB.1 - Set to drive the servo clockwise to the end.
'PORTB.3 - Set to drive the servo counter-clockwise to the end.
'Connections:
'PIC-PIN : Servo
'PortC.1 : Control wire
'Vcc(5V) : Power Wire(Red wire)
'Gnd(0V) : Black wire
'************************************************* *********************
'Defines
Define LOADER_USED 1 'Use tiny boot loader
DEFINE USE_LFSR 1
DEFINE OSC 20
' LCD Defines
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 4 ' LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTD ' LCD register select port
DEFINE LCD_RSBIT 2 ' LCD register select bit
DEFINE LCD_EREG PORTD ' LCD enable port
DEFINE LCD_EBIT 3 ' LCD enable bit
DEFINE LCD_RWREG PORTD ' LCD read/write port
DEFINE LCD_RWBIT 2 ' LCD read/write bit
DEFINE LCD_BITS 4 ' LCD bus size 4 or 8
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
'Set tris & system registers
TRISA=%00000000 ' Set Port A pins as Output
TRISB=%11111111 ' Set Port B pins as Input
TRISC=%00000000 ' Set Port C pins as Output
TRISD=%00000000 ' Set Port D pins as Output
TRISE=%00000000 ' Set Port E pins as output
'Program variables
position var byte
'Input/output port assignments
PB_UP VAR PORTB.3 'Push button to move servo up
PB_center VAR PORTB.0 'Push button to move servo to center
PB_down VAR PORTB.1 'Push button to move servo down
Tx var PORTC.6 ' Tx Rs232 to Terminal
Rx var PORTC.7 ' Rx Rs232 from Terminal
'Main program
PORTC.1 = 0
InitModem:
pause 1000
lcdout $Fe,01,"Init Modem"
gosub init
pause 1000
lcdout $Fe,01,"Modem Init Done"
pause 1000
lcdout $FE, 01, "Ready to start"
'Read input
Read_input:
if PORTB.0 = 1 then
position = 0
endif
if PORTB.1 = 1 then
position = 1
endif
if PORTB.3 = 1 then
position = 2
endif
if position = 0 then
pulsout PORTC.1, 750
endif
if position =1 then
pulsout PORTC.1, 300
endif
if position =2 then
pulsout PORTC.1, 1150
endif
pause 50
goto Read_input
'SMS subroutines
Init:
' Subroutine to initialise the GSM modem
Serout2 Tx,84,["AT+CLIP=1",13] ' CLIP command
Pause 500
Serout2 Tx,84,["AT+CNMI=3,0",13] ' SMS now not polled
Pause 500
Serout2 Tx,84,["AT+CMGF=1",13] ' Set Text Mode
Pause 500
SERout2 Tx,84,["AT+CMGS=",34,"+6598755989", 34,13]
'Preferred Message Storage: ME on Phone
Serout2 Tx,84,["AT+CPMS=",34,"ME",34,13] ' Changed for GR47
Pause 4000
'Set the storage to SIM
Serout2 Tx,84,["AT+CPBS=",34,"SM",34,13]' Otherwise cannot read memory location
Pause 1000
'SERIN2 Tx,84,5000,Problem,[Wait ("OK")] ' Loopback to NotReady
'Select Character Set “UTF-8” : Universal text format, 8 bits
PAUSE 1000
Serout2 Tx,84,["AT+CSCS=",34,"UTF-8",34,13] ' for @ sign problem
pause 1000
Serout2 Tx,84,["AT&W",13] 'Store User Profile to non volatile memory
pause 1000
Serout2 Tx,84,["AT+CMGD=1,4",13]
pause 3000
Return
Next I need to change the above codes to SERIN and Rx and "additional codes" so that my GSM modem can receive an sms from a handphone in order to trigger the servo motor.
This is where my problem comes in. Any help would be appreciated. Thanks.
Ioannis
- 15th May 2008, 08:23
I would strongly suggest to use hardware USART and if possible interrupts like Darrels Instant Interrupts. It will assure you no lost characters.
Secondly, I see that you are not checking if the modem has replied with OK or an error, except once. Not all commands have the same processing time. So it is a good practise to confirm that the device has accepted succesfully the command by monitoring its response.
Ioannis
supertyx
- 21st May 2008, 03:41
I would strongly suggest to use hardware USART and if possible interrupts like Darrels Instant Interrupts. It will assure you no lost characters.
Secondly, I see that you are not checking if the modem has replied with OK or an error, except once. Not all commands have the same processing time. So it is a good practise to confirm that the device has accepted succesfully the command by monitoring its response.
Ioannis
I've used an open source software called " real term" to test out the serial cable
The following are the codes i used to test:
Serout2 Tx,84,["Ready:",13]
pause 500
Serin2 rx,84,[wait("A="),B0]
Pause 500
Serout2 PORTC.6,84,["Got: ",B0,13]
pause 500
goto init
It's working. Now I need to test the GSM modem using SEROUT2 and SERIN2 commands. Anyone knows how?
Ioannis
- 21st May 2008, 10:36
Any special need to use Serin2/Serout2 instead of Hseri/Hserout?
Ioannis
supertyx
- 21st May 2008, 15:23
Any special need to use Serin2/Serout2 instead of Hseri/Hserout?
Ioannis
What are the differences between serin2/serout2 and hserin/hserout?
How can I use either set of commands to capture sms message?
skimask
- 21st May 2008, 15:34
What are the differences between serin2/serout2 and hserin/hserout?
How can I use either set of commands to capture sms message?
Guess where the answer is?
(could be in post #8, but it's not!)
EDIT: Looks like the post I was referring to (i.e. spam) got deleted (Thx admins).
Let me change that to:
See post #10...
Ioannis
- 21st May 2008, 22:21
1. Software vs Hardware. Is that clear enough?
2. If you do not know how to use these commands, then sorry, I cannot teach you PicBasic Pro lanquage. You have to do it yourself, and if you face a problem, then come here to show your code and be sure many will help you debug it.
3. The GSM thread has many resources for the matter. Just read...
Ioannis
supertyx
- 26th May 2008, 07:00
I can send sms using at commands:
pause 1000
LCDOUT $Fe,01, "Sending Now.."
PAUSE 2000
serout2 Tx,84,["AT+CMGS=",34,"Put hp number here",34,13]
pause 1000
serout2 TX,84,["How are you?",26]
'pause 1000
lcdout $Fe,01, "Message sent"
PAUSE 2000
LCDOUT $Fe,01, "STOP"
stop
Now i want to write a program to receive sms. What are the codes needed to be edited/added?
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.