Solución
Solo estoy publicando la solución si alguien la necesita. Todo el mundo parece rechazar el problema en lugar de dar soluciones.
- En primer lugar, quite todos los puentes [ver la imagen]
LuegoagreguedoscablesmachoahembraalS-TXyalS-RX[AquíSsignificaSIM900,puedeencontrarlospinesdespuésdequitarlospuentes.]
CortalosmotivosdelosmódulosarduinoyATK-SIM900A
S-TXdebeestarconectadoalarduinoRXyS-RXdebeestarconectadoalarduinoTX.
Normalmenteenciendaelmódulo[NoseolvidedepresionarPWRKey
después]
Código
#include<SoftwareSerial.h>#defineBAUD9600#defineRX10#defineTX11SoftwareSerialgsm(RX,TX);int8_tsendATcommand(char*ATcommand,char*expected_answer,unsignedinttimeout){uint8_tx=0,answer=0;charresponse[100];unsignedlongprevious;memset(response,'#include<SoftwareSerial.h>#defineBAUD9600#defineRX10#defineTX11SoftwareSerialgsm(RX,TX);int8_tsendATcommand(char*ATcommand,char*expected_answer,unsignedinttimeout){uint8_tx=0,answer=0;charresponse[100];unsignedlongprevious;memset(response,'%pre%',100);//Initializethestringdelay(100);while(gsm.available()>0)gsm.read();//Cleantheinputbuffergsm.println(ATcommand);//SendtheATcommandx=0;previous=millis();//thisloopwaitsfortheanswerdo{//iftherearedataintheUARTinputbuffer,readsitandchecksfortheasnwerif(gsm.available()!=0){response[x]=gsm.read();x++;Serial.println(response);//checkifthedesiredanswerisintheresponseofthemoduleif(strstr(response,expected_answer)!=NULL){answer=1;}}//Waitsfortheasnwerwithtimeout}while((answer==0)&&((millis()-previous)<timeout));returnanswer;}voidsetup(){//putyoursetupcodehere,torunonce:Serial.begin(BAUD);gsm.begin(BAUD);}//Codeforsendingsms,replacethestarsandcountrycodewithyourcorrespondingphonenumbervoidloop(){sendATcommand("AT+CMGF=1\r\n", "OK", 500);
sendATcommand("AT+CMGS=\"+880******582\"\r", "OK", 500);
delay(500);
gsm.println("Hello world"); //The message to be sent
delay(500);
gsm.println((char)26); // Done
delay(500);
}
', 100); // Initialize the string
delay(100);
while ( gsm.available() > 0) gsm.read(); // Clean the input buffer
gsm.println(ATcommand); // Send the AT command
x = 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 (gsm.available() != 0) {
response[x] = gsm.read();
x++;
Serial.println(response);
// 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;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(BAUD);
gsm.begin(BAUD);
}
//Code for sending sms, replace the stars and country code with your corresponding phone number
void loop()
{
sendATcommand("AT+CMGF=1\r\n", "OK", 500);
sendATcommand("AT+CMGS=\"+880******582\"\r", "OK", 500);
delay(500);
gsm.println("Hello world"); //The message to be sent
delay(500);
gsm.println((char)26); // Done
delay(500);
}
Gracias a todos.