/* * Ardunio Sketch for Pro Micro 32U4 linking to A6 GSM module * Some of these codes are copied from other freely available codes on the web * Feel free to use and modify, enjoy!!! * */ #include #define SMSPin 7 // this is the PIN that will send SMS when it is pulled LOW SoftwareSerial mySerial(8, 9); // Software Serial to link to A6 Module Rx, Tx char phone_no[] ="04xxxxxxxx"; // Define Mobile number that will recieve SMS char msg1[]= "The Intruder Alarm has been activated"; // Text message void setup() { // Serial.begin(115200); // Open hardware serial - leave in for debugging mySerial.begin(115200); // Open software serial pinMode(SMSPin, INPUT); // Define SMSPin as Input, use resistor to PULL UP delay(10000); // Wait for GSM module to start up after power on mySerial.println("AT"); delay(500); mySerial.println("AT+CPIN=pppppppp,PPPP"); // resetting PIN code by supplying PUK code pppppppp and the pin code PPPP, this is required for some SIM card as A6 module refused to connect delay(5000); } void loop() { if (mySerial.available()) { Serial.write(mySerial.read()); } if (Serial.available()) { mySerial.write(Serial.read()); } if (digitalRead(SMSPin) == LOW) { delay(1000); SMS();} } void SMS() { mySerial.println("AT"); delay(500); mySerial.println("AT+CMGF=1"); delay(200); mySerial.print("AT+CMGS=\""); mySerial.print(phone_no); mySerial.write(0x22); // quotation mark mySerial.write(0x0D); // CR mySerial.write(0x0A); // LF delay(500); mySerial.print(msg1); // send text message mySerial.print (char(26)); //control-z mySerial.write(0x0D); // CR mySerial.write(0x0A); // LF mySerial.println("AT"); delay(200); }