Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Remote Start via SMS for smartkey-equipped Flex
- * XirallicBolts
- *
- * v1.0 - Initial version
- *
- * v1.1 - Responds to sender instead of hardcoded number
- * Added PATS programming procedure
- * 'Send SMS' moved to a separate function (to allow for immediate PATS message)
- * Corrected serial messages
- * Added support for an 'Always send confirmation messages' switch/wire
- *
- * v1.2 Fixed: No longer gets stuck in a loop, reacting off the outgoing messages
- * Fixed: A disconnected pin is apparently HIGH for confirmations.
- * Connect pin 11 to GND to recieve confirmation texts automatically
- * v1.2.1 Removed: Resistor is unnecessary. No issues running over a week on main battery power.
- */
- #include <SoftwareSerial.h>
- // Create SoftwareSerial object for the SIM800L
- SoftwareSerial SIM800(2, 3); // RX on 2, TX on 3
- // Set a couple names so we don't have to remember which pin is the 'Start' button
- #define CONFIRM_TEXT 11 // Connect pin 11 to Ground to recieve a confirmation text
- #define FOB_BATTERY 6 // originally 8, reversed the glued-in leads like an idiot
- #define BUTTON_LOCK 7
- #define BUTTON_START 8 // 6, still an idiot
- String incomingText = "";
- String incomingNumber = "";
- String messageHeader = "";
- String outgoingText = "";
- void setup(){
- pinMode(CONFIRM_TEXT, INPUT_PULLUP);
- pinMode(FOB_BATTERY, OUTPUT);
- pinMode(BUTTON_LOCK, OUTPUT);
- pinMode(BUTTON_START, OUTPUT);
- // Make sure the relays are all shut off.
- // Relays behave backwards. HIGH is off, LOW is on.
- digitalWrite(FOB_BATTERY, HIGH);
- digitalWrite(BUTTON_LOCK, HIGH);
- digitalWrite(BUTTON_START, HIGH);
- // Wait a few seconds, then start talking to both the laptop (Serial)
- // and GSM module (SIM800). Give the GSM time to connect to cell towers
- delay(5000);
- Serial.begin(19200);
- SIM800.begin(19200);
- SIM800.setTimeout(5000);
- Serial.println("Waiting 10 seconds for cell to connect...");
- delay(10000);
- SIM800.print("AT+CMGF=1\r"); // Set SIM800 to SMS mode
- delay(100);
- SIM800.print("AT+CNMI=2,2,0,0,0\r"); // Set SIM800 to send incoming messages to the Nano
- delay(100);
- Serial.println("You should now be connected to the cell towers");
- //TODO: Actually parse the response to see if it's connected
- }
- void loop() {
- // Check for a new text message, convert it to uppercase, and let the laptop know.
- if(SIM800.available()>0) {
- incomingText = SIM800.readString();
- delay(250);
- incomingNumber = "";
- incomingText.toUpperCase();
- messageHeader = incomingText.substring(2,6); // Extract the first five characters to ensure it's an incoming text
- incomingNumber = incomingText.substring(9,21); // Extract the phone number to text back
- Serial.println("Incoming message: " + incomingText);
- delay(10);
- }
- // If the text contains the keyword LOCK, lock the doors
- if(incomingText.indexOf("LOCK")>=0 && messageHeader == "+CMT"){
- Serial.println("Attempting to Lock doors");
- digitalWrite(FOB_BATTERY, LOW); // Battery ON
- delay(1000);
- digitalWrite(BUTTON_LOCK, LOW); // Lock PRESSED
- delay(250);
- digitalWrite(BUTTON_LOCK, HIGH); // Lock RELEASED
- delay(500);
- digitalWrite(FOB_BATTERY, HIGH); // Battery OFF
- Serial.println("Doors locked");
- // If the text contains the word CONFIRM, or the Always Confirm switch is on, send a text back
- if(incomingText.indexOf("CONFIRM")>=0 || digitalRead(CONFIRM_TEXT) == LOW){
- outgoingText = "Doors Locked";
- SendText(incomingNumber, outgoingText);
- }
- incomingText = ""; // Clear the incoming and outgoing strings so
- outgoingText = ""; // you can't trigger both START and STOP (etc) in one message
- }
- if(incomingText.indexOf("START")>=0 && messageHeader == "+CMT"){
- Serial.println("Attempting to Remote Start");
- digitalWrite(FOB_BATTERY, LOW); // Battery ON
- delay(1000);
- digitalWrite(BUTTON_LOCK, LOW); // Lock PRESSED
- delay(250);
- digitalWrite(BUTTON_LOCK, HIGH); // Lock RELEASED
- delay(500);
- digitalWrite(BUTTON_START, LOW); // Start PRESSED
- delay(250);
- digitalWrite(BUTTON_START, HIGH); // Start RELEASED
- delay(500);
- digitalWrite(BUTTON_START, LOW); // Start PRESSED
- delay(250);
- digitalWrite(BUTTON_START, HIGH); // Start RELEASED
- delay(500);
- digitalWrite(FOB_BATTERY, HIGH); // Battery OFF
- Serial.println("Car Started");
- if(incomingText.indexOf("CONFIRM")>=0 || digitalRead(CONFIRM_TEXT) == LOW){
- outgoingText = "Remote Started";
- SendText(incomingNumber, outgoingText);
- }
- incomingText = "";
- outgoingText = "";
- }
- if(incomingText.indexOf("STOP")>=0 && messageHeader == "+CMT"){
- Serial.println("Attempting to Stop");
- digitalWrite(FOB_BATTERY, LOW); // Battery ON
- delay(1000);
- digitalWrite(BUTTON_START, LOW); // Lock PRESSED
- delay(3000);
- digitalWrite(BUTTON_START, HIGH); // Lock RELEASED
- delay(500);
- digitalWrite(FOB_BATTERY, HIGH); // Battery OFF
- Serial.println("Remote Start Cancelled");
- if(incomingText.indexOf("CONFIRM")>=0 || digitalRead(CONFIRM_TEXT) == LOW){
- outgoingText = "Engine Stopped";
- SendText(incomingNumber, outgoingText);
- }
- incomingText = "";
- outgoingText = "";
- }
- if(incomingText.indexOf("PATSPROGRAMMING")>=0 && messageHeader == "+CMT"){
- Serial.println("Turning on remote for PATS programming...");
- outgoingText = "Key is ON for 60 seconds. Begin PATS procedure now!";
- SendText(incomingNumber, outgoingText);
- digitalWrite(FOB_BATTERY, LOW); // Battery ON
- delay(70000);
- digitalWrite(FOB_BATTERY, HIGH); // Battery OFF
- Serial.println("PATS timer complete");
- incomingText = "";
- outgoingText = "";
- }
- if(incomingText.indexOf("STATUS")>=0 && messageHeader == "+CMT"){
- outgoingText = "I'm awake! v1.2";
- SendText(incomingNumber, outgoingText);
- incomingText = "";
- outgoingText = "";
- }
- delay(100);
- }
- void SendText(String incomingNumber, String outgoingText){
- Serial.println("Preparing to send a text ... ");
- SIM800.println("AT+CMGF=1");
- delay(100);
- //SIM800.println("AT+CMGS=\"+01xxxxxxxxxx\""); // Depreciated, now responds to sender.
- SIM800.println("AT+CMGS=\"" + incomingNumber + "\"");
- delay(100);
- SIM800.println(outgoingText);
- delay(100);
- SIM800.println((char)26);
- delay(5000);
- incomingText = "";
- }
Add Comment
Please, Sign In to add comment