metricmoose / sms-remote-starter Goto Github PK
View Code? Open in Web Editor NEWThe code for my Arduino-powered remote starter trigger
The code for my Arduino-powered remote starter trigger
Dear Ben,
first of all introduce my name is joko.
I had already tried your code with hardware as follow.
// SIM900 Shield Serial Pins
SoftwareSerial SIM900(2, 3);
// Set to true if you want confirmation text messages
boolean respond = true;
// Key fob pins
int lockPin = 7;
int starterPin = 6;
int unlockPin = 5;
int auxPin = 4;
// Replace with the number of the controlling phone
String myPhoneNum = "+6282132193301";
void setup()
{
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);
pinMode(lockPin, OUTPUT);
pinMode(starterPin, OUTPUT);
pinMode(unlockPin, OUTPUT);
pinMode(auxPin, OUTPUT);
Serial.begin(2400); // for serial monitor
Serial.println("Starting.");
SIM900.begin(2400); // Serial for GSM shield
SIM900poweron(); // turn on shield
//Wake up modem with an AT command
sendCommand("AT", "OK", 1000);
if(sendCommand("AT", "OK", 1000) == 1){
Serial.println("Module started");
}
if(sendCommand("AT+CNMI=0,0,0,0,0", "OK", 1000) == 1){
Serial.println("Notifications disabled");
}
if(sendCommand("AT+CMGF=1", "OK", 1000) == 1){
Serial.println("Text mode enabled");
}
if(sendCommand("AT+CSCLK=2", "OK", 1000) == 1){
Serial.println("Sleeping enabled");
}
}
void loop()
{
//Wake up modem with two AT commands
sendCommand("AT", "OK", 1000);
sendCommand("AT", "OK", 2000);
// Check if it's currently registered to Speakout
if(sendCommand("AT+CREG?","+CREG: 0,1",1000)){
Serial.println("tersambung dalam jaringan");
// Try to get the first SMS. Reply prefixed with +CMGR: if there's a new SMS
if(sendCommand("AT+CMGR=1", "+CMGR: ", 1000) == 1){
String serialContent = "";
char serialCharacter;
while(SIM900.available()) {
serialCharacter = SIM900.read();
serialContent.concat(serialCharacter);
delay(10);
}
// Dividing up the new SMS
String smsNumber = serialContent.substring(14,26);
String smsMessage = serialContent.substring(53,serialContent.length()-8);
smsMessage.trim();
smsMessage.toLowerCase();
Serial.println("New SMS Message");
Serial.println(smsNumber);
Serial.println(smsMessage);
delay(500);
// Delete all SMS messages in memory
sendCommand("AT+CMGD=1,4", "OK", 1000);
// Check if it's coming from my phone
if(smsNumber == myPhoneNum){
if(smsMessage == "start"){
carStart();
if(respond){ sendSms("Car Started"); }
}
else if(smsMessage == "lock"){
carLock();
if(respond){ sendSms("Doors Locked"); }
}
else if(smsMessage == "unlock"){
carUnlock();
if(respond){ sendSms("Doors Unlocked"); }
}
else if(smsMessage == "trunk"){
carTrunk();
if(respond){ sendSms("Trunk Popped"); }
}
else if(smsMessage == "finder"){
carStart();
if(respond){ sendSms("Finder Activated"); }
}
else if(smsMessage == "rspon"){
respond = true;
sendSms("Respond to commands: On");
}
else if(smsMessage == "rspoff"){
respond = false;
sendSms("Respond to commands: Off");
}
else{
if(respond){ sendSms("Invalid command"); }
Serial.println("Invalid command");
}
}
}
else{
Serial.println("No SMS messages");
}
}
else{
Serial.println("Not connected to home cell network");
}
}
void sendSms(String message){
Serial.println("Sending message");
char smsCommand[23];
String commandStr = "AT+CMGS="" + myPhoneNum + """;
commandStr.toCharArray(smsCommand,23);
if(sendCommand(smsCommand, ">", 1000)){
SIM900.println(message);
SIM900.println((char)26);
SIM900.println();
delay(2000);
}
}
void carLock(){
digitalWrite(lockPin, HIGH);
delay(1000);
digitalWrite(lockPin, LOW);
Serial.println("Doors locked");
}
void carUnlock(){
digitalWrite(unlockPin, HIGH);
delay(1000);
digitalWrite(unlockPin, LOW);
Serial.println("Doors unlocked");
}
void carStart(){
digitalWrite(starterPin, HIGH);
delay(1000);
digitalWrite(starterPin, LOW);
Serial.println("Car Starting");
}
void carTrunk(){
digitalWrite(auxPin, HIGH);
delay(2000);
digitalWrite(auxPin, LOW);
Serial.println("Trunk Released");
}
void carFind(){
digitalWrite(auxPin, HIGH);
digitalWrite(starterPin, HIGH);
delay(1000);
digitalWrite(auxPin, LOW);
digitalWrite(starterPin, LOW);
Serial.println("Car Finder Activated");
}
void SIM900poweron()
// Software equivalent of pressing the GSM shield "power" button
{
//Wake up modem with an AT command
sendCommand("AT", "OK", 1000);
if(sendCommand("AT", "OK", 2000) == 0){
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}
}
int sendCommand(char* ATcommand, char* expected_answer, unsigned int timeout){
int answer=0;
int responsePos=0;
char response[100];
unsigned long previous;
memset(response, '\0', 100); // Clears array
delay(100);
while( SIM900.available() > 0) SIM900.read(); // Clean the input buffer
SIM900.println(ATcommand); // Send the AT command
responsePos = 0;
previous = millis();
// this loop waits for the answer
do{
// if there are data in the UART input buffer, reads it and checks for the asnwer
if(SIM900.available() != 0){
response[responsePos] = SIM900.read();
responsePos++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer) != NULL)
{
answer = 1;
}
}
// Waits for the asnwer with time out
}while((answer == 0) && ((millis() - previous) < timeout));
return answer;
}`
When I running the code everything seems tobe right, but after i send sms to it,
in serrial monitor had stoped for few second and displyaed with header "New Message" and the next line is empty (no phone number and message are displayed) after that the program start looping again also they are no replied message to my cellular phone that i used to control the arduino.
I had already tried for several time to changed include library to find the problem but till today not solved.
is that something wrong with my modified code?
I'm Very Appreciate if you could help to resolve the problem.
Thanks in Advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.