okay great thanks for the help, it's for a school computer science project here is the code I have so far..
#include <SoftwareSerial.h> // include the library SoftwareSerial.h to allow another serial connection
SoftwareSerial GPRS(7, 8); //RX, TX serial connections to SMS module
boolean MagSwitch; // Pin 2
boolean MomentButton; // Pin 3
boolean Relay; // Pin 4
const int MagSwitchPin = 2;
const int MomentButtonPin = 3;
const int RelayPin = 4;
String AdminNumber; // admin mobile no.
struct User // standard phone used to unlock the lock, not able to add new users
{
static String Name; // user name
static String Number; // user mobile no.
static boolean Temporary; // will the user have full access or a single use code? 1 = single use
};
new User[] = User1;
void setup() // runs through this function once after power up, used to set pin values etc.
{
pinMode(MagSwitchPin, INPUT); // MagSwitch
pinMode(MomentButtonPin, INPUT); // MomentButton
pinMode(RelayPin, OUTPUT); // Relay
GPRS.begin(9600); // Starts a serial communication with the SMS module
Serial.begin(9600); // Starts a serial communication with the connected USB COM port
GPRS.println("AT + CMGF = 1"); // checks to see if the connected modem supports SMS if true the modem returns OK
delay(1000); // wait 1000ms
//GPRS.println("AT + CPIN = "0000" "); // unlocks SIM if protected by a PIN code otherwise comment this line
delay(1000); // wait 1000ms
}
void loop() // consecutively run this function over and over hence the identifier "loop"
{
}
static void PairNewAdmin() // Puts the program in a state where it scans the last recieved message for 30 seconds and if the SMS content is PAIR then sets the sender as Admin
{
boolean Changed = 0; // if 1 a new device has been paired
{
sendSMS(AdminNumber, "request to pair new device"); // tels the existing admin the lock is being paired to a new device
}
do
{
int i = 0; // temporary variable to store count
delay(1000); // wait 1000ms
i++; // i + 1
if (Content == "PAIR")
{
AdminNumber = Sender;
Changed = 1;
i = 30;
sendSMS(AdminNumber, "DEVICE PAIRED TO LOCK"); // tell the requester that they have been successfull
Serial.println("New device paired - " + Sender); // inform the serial moniter of the new admin
}
}while(i < 30); // loops for 30 seconds unless i is changed by anything other than i++
}
static void CommandRecieved(String Sender, String Content)
{
String Command = Content.Substring(0,3);
String Number = Content.Substring(4,16);
String Temporary = Content.Substring(17);
if
if (Sender == AdminNumber || Sender == User[1].Number || Sender == User[2].Number || Sender == User[3].Number || Sender == User[4].Number)
{
if (Command == OPEN)
{
Unlock();
if (User);
}
else if (Command ==
}
else
{
sendSMS(Sender, "Sorry, your number has not been recognised by the lock please contact your system admin.");
sendSMS(AdminNumber, "An unrecognised number (" + Sender + ") tried to access the lock with the content " + Content); // inform the admin of another number trying to access lock
}
}
static void sendSMS(String SendTo, String Content) // the function that will be used to send an SMS to the number given in parameter "SendTo" with the content in parameter "Content"
{
GPRS.println("AT + CMGF = 1"); // Puts the modem in a mode ready to send an SMS
GPRS.println("AT & CMGS = " + SendTo + "+"); // tells the modem who to send the SMS to, should return >
GPRS.println(Content); // Sends the content of the SMS to the modem
GPRS.write( 0x1a ); // Hexadecimal ctrl+Z character used to send an SMS
}
static void recieveSMS(byte MessageLocation) // the function that will be used to view incoming and recieved SMS messages with "MessageLocation" being the address on the SIM card where the desired message is stored
{
GPRS.println("AT + CMGF = 1"); // Puts the modem in a mode ready to recieve an SMS
GPRS.println("AT + CPMS = "SM""); // sets the default storage location for new messages as the SIM card, usually SIM cards can store upto 15 messages
GPRS.println("AT & CMGL = "ALL""); // lists all of the messages found on the default storage device
GPRS.println("AT CMGR + " + MessageLocation);
}
static void ClearSIM(byte SIMAddress) // the function that wil be used to remove the content from address X on the SIM card with "SIMAddress being location X"
{
GPRS.println("AT CMGR + " + SIMAddress + " ="); // removes the message from "SIMAddress" on the SIM card
Serial.println("Cleared message from address " + SIMAddress + " on the primary storage device"); // prints a new line on the serial monitor to confirm that address X has been cleared
}
static void Unlock(String User) // this function opens the lock and sends a notification to the admin stating which user unlocked the lock
{
delay(1000); // wait 1000ms
Serial.println("System unlocking"); // prints into the serial monitor for debugging purposes
delay(100); // wait 100ms
digitalWrite(RelayPin, HIGH); // apply 5v to the relay causing the solonoid to activate releasing the lock
delay(2000); // leave the door unlocked for 2000ms
digitalWrite(RelayPin, LOW); // stop applying 5v to the relay
sendSMS(Admin[Number], "The lock was opened by " + User); // send an SMS to Admin informing which user unlocked door
}
Is there anything significant that you can spot that you would change?
Also why not use a string?
Again Thanks, This forum is a great resource to have especially with such a friendly helpful community!!!