You are on page 1of 8

SMS based device controller

BY BINU JUNE 2, 2014

This project is used to control 4 devices through SMS. Atmega8 is


used here to interact with the GSM Modem. The modem used in
this project is based on SIM300 module with TTL interface. The
modem is controlled through the AT commands. The system is
protected by a password and the person who knows the password
can control the devices. The code is written in Bascom Basic.
Circuit Diagram:

Operation:
The circuit will take around 30 to 40 seconds to initialize the
modem. The status of the devices before the power failure is
restored. Then it will wait for the sms commands from the user.
The user has to send the password first to register his mobile
number. The default password is microcontroller the
microcontroller will send a password accepted message to the
sender. It also store the mobile number in its eeprom. So the user
dont need to send the password everytime. The various
commands to control the devices are given below.
To switch on the device 1: light on

To switch off the device 1:light off


To switch on the device 2: fan on
To switch off the device 2: fan off
To switch on the device 3: ac on
To switch off the device 3: ac off
To switch on the device 4: tv on
To switch off the device 4:tv off
Modem used in this project

Source code:
'----------------------------------------------------------------------------------------'copyright

: (c) 2012, avrprojects.info

'purpose

: SMS controller

'----------------------------------------------------------------------------------------$regfile = "m8def.dat"
$crystal = 3686400
$baud = 9600
$hwstack = 64
$swstack = 64
$framesize = 64
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
Config Portb.3 = Output
Config Portb.4 = Output
Config Portb.5 = Output

Declare Sub Getline


Declare Sub Send_sms
Declare Sub Sms_check

Relay1 Alias Portb.5


Relay2 Alias Portb.4
Relay3 Alias Portb.3
Relay4 Alias Portb.2
Rled Alias Portb.0
Gled Alias Portb.1
####################################
Dim Status1 As Eram Byte At 5
Dim Status2 As Eram Byte At 6
Dim Status3 As Eram Byte At 7
Dim Status4 As Eram Byte At 8
Dim Number As Eram String * 13 At 10
'------------ Variables and constants for GSM --------------------------------- -----Dim Num As String * 80
Dim Msg As String * 160
Dim Inmsg As String * 160
Dim Gstmp As Byte
Dim Ar(10) As String * 20
Dim Sender As String * 25
Dim Engine As Byte
Dim Alarms As Byte
Dim Icnt As Byte
Dim A_armed As Byte
Dim Gps As Byte
Dim Stmp As Byte
Dim Pass_stored As String * 13

'Print Pass_stored
Relay1 = 0
Relay2 = 0
Relay3 = 0
Relay4 = 0

Pass_stored = Number
Gps = Status1
If Gps = 0 Then
Relay1 = 0
Else
Relay1 = 1
End If
Gps = Status2
If Gps = 0 Then
Relay2 = 0
Else
Relay2 = 1
End If
Gps = Status3
If Gps = 0 Then
Relay3 = 0
Else
Relay3 = 1
End If
Gps = Status4
If Gps = 0 Then
Relay4 = 0
Else
Relay4 = 1
End If

Wait 1
Rled = 1
Gled = 0
Wait 20

' give some time for gsm modem


' give some time for gsm modem

Print "AT"
Wait 2
Print "AT+CMGD=1"
Wait 2
Print "AT+CREG?"
Wait 2
Print "ATE0"
Wait 2
Print "AT+CNMI=1,1,0,0,0"
Wait 2

'new message indication off


'Third command TEXT MODE

Print "AT+CMGF=1"
Wait 2
'Print #2 , "AT+CSQ"

'signal strength

'Wait 2

Rled = 0
Gled = 1
Do
Print "AT"
Wait 2
Print "AT+CMGF=1"
Print "AT+CMGR=1"

' Change to text mode

Getline
If Inmsg <> "OK" Then
Rled = 1
Gled = 1
Num = Inmsg
Getline
Gps = Split(num , Ar(1) , ",")
Num = Ar(2)
Gps = Len(num)
Gps = Gps - 2
Num = Mid(num , 2 , Gps)
Inmsg = Lcase(inmsg)
'

Print Num ; "Msg:" ; Inmsg


If Inmsg = "microcontroller" Then
Pass_stored = Num
Number = Pass_stored
Msg = "Password Accepted"
Send_sms
Elseif Num = Pass_stored Then
If Inmsg = "light on" Then
Relay1 = 1
Status1 = 1
Num = Pass_stored
Msg = "Light Switched ON"
Send_sms
Elseif Inmsg = "light off" Then
Relay1 = 0
Status1 = 0

Wait 2

' get the message

'other numbers

Num = Pass_stored
Msg = "Light Switched OFF"
Send_sms
Elseif Inmsg = "fan on" Then
Relay2 = 1
Status2 = 1
Num = Pass_stored
Msg = "Fan Switched ON"
Send_sms
Elseif Inmsg = "fan off" Then
Relay2 = 0
Status2 = 0
Num = Pass_stored
Msg = "Fan Switched OFF"
Send_sms
Elseif Inmsg = "ac on" Then
Relay3 = 1
Status3 = 1
Num = Pass_stored
Msg = "AC Switched ON"
Send_sms
Elseif Inmsg = "ac off" Then
Relay3 = 0
Status3 = 0
Num = Pass_stored
Msg = "AC Switched OFF"
Send_sms
Elseif Inmsg = "tv on" Then
Relay4 = 1
Status4 = 1
Num = Pass_stored
Msg = "AC Switched ON"
Send_sms
Elseif Inmsg = "tv off" Then
Relay4 = 0
Status4 = 0
Num = Pass_stored
Msg = "AC Switched OFF"
Send_sms
Else
Num = Pass_stored
Msg = "Invalid Command.."
Send_sms
End If
End If
Wait 2

Print "AT+CMGD=1"
Wait 3
Rled = 0
Gled = 1
End If
Gled = 0
Waitms 1
Gled = 1

Wait 8
Gled = 0
Waitms 1
Gled = 1
Loop

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'

SEND SMS

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Send_sms
Rled = 1
Wait 3
Print "AT+CMGS=" ; Chr(34) ; Num ; Chr(34)

'send sms

Waitms 200
Print Msg ; Chr(26)
Wait 5
Print "AT"
Wait 2
Rled = 0
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'

Read gsm modem

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Getline
Inmsg = ""
Do
Gps = Inkey()
If Gps > 0 Then
Select Case Gps

Case 13 : If Inmsg <> "" Then Exit Do

' if we have received something

Case 10 : If Inmsg <> "" Then Exit Do

' if we have received something

Case Else
Inmsg = Inmsg + Chr(gps)
End Select
End If
Loop
End Sub
End

' build string

You might also like