#include <SoftwareSerial.h> #define phonenum_call "18,150,561,160" // preferably removable card Unicom card support is not very good SoftwareSerial softSerial1 (4,5); // soft serial RXD4, TXD5, communicating with the short message int sendMeg (String phonenum, String text) // send function information can be called directly, without modifying { softSerial1.println ( "AT"); // send AT to GSM, see response char comdata = 0; // last received is determined whether a String phone = ""; // phone numbers stored phone = "AT + CMGS = \" "+ phoneNum + '\"'; the while (softSerial1.available ()> 0) { Comdata = softSerial1.read () ; // read each time a character char, and added Delay (2); } softSerial1.println ( "AT"); // send AT to GSM, see the response delay (1000); the while (softSerial1.available() > 2){ comdata = softSerial1.read (); // every time a read character char, and adding } Serial.print (comdata); // Error Delay (2); } IF (! = Comdata 'K') is determined // not received the OK { Serial.println ( "ERROR1"); // error // return 0; } Comdata = 0; softSerial1.println ( "the AT + = CMGF. 1"); // set the text mode GSM Delay (500); the while (softSerial1.available ()> 2) { Comdata softSerial1.read = (); // each read a character char, and added Delay (2); } IF (! = Comdata 'K') // not received the OK { Serial.println ( "Error2"); // return 0; softSerial1.println (phone); // send a certain number = 0 Comdata; Delay (1000); the while (softSerial1.available ()>. 1) { Comdata softSerial1.read = (); // every time a read character char, and added Delay (2); } IF (Comdata! = '>') does not receive //> { Serial.println ( "error3"); // return 0; } Comdata = 0; softSerial1.print (text); // send the written content Delay (500); softSerial1 .write (0x1A); // end of the input text, and transmits Serial.println ( "success"); // success } void Setup () { // port hard Serial.begin (9600); // serial communication listener soft softSerial1 .begin (9600); softSerial1.listen (); Delay (5000); } Comdata String; void Loop () { IF (Serial.available ()> 0) { // Delay (. 1); // reading speed impact Comdata Serial.readString = (); sendMeg (phonenum_call, Comdata); // to 15147300333 transmission information Comdata = ""; Delay (3000); } }