Hi dears I'm trying to do project to control app base gsm control by arduino mega 2560 gsm module SIM900A
To send SMS to open Led than reply SMS to give as the status I mean send SMS then I received SMS from GSM module by this code same time work but same time not work also same time send SMS1111 received SMS2222 status. I hope it is clear.
#include <SoftwareSerial.h>
#include <string.h>
#include "SIM900.h"
#include <TinyGPS.h>
#include "sms.h"
SoftwareSerial GSMSerial(12, 13);
byte buffer[128];
int count = 0;
const int Led4 = 43;
const int Led1 = 44;
const int Led2 = 45;
const int Led3 = 50;
void SIM900power()
{
}
void setup() {
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
pinMode(Led4, OUTPUT);
GSMSerial.begin(19200); // the SIM900 baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
Sim900_Inti();
}
void loop() {
GSMSerial.listen();
if (GSMSerial.available()) // If date is comming from from GSM shield)
{
while (GSMSerial.available()) // reading data into char array
{
buffer[count++] = GSMSerial.read(); // writing data into array
if (count == 128)break;
}
Serial.write(buffer, count); // if no data transmission ends, write buffer to hardware serial port
Cmd_Read_Act(); //Read the 'COMMAND' sent to SIM900 through SMS
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
GSMSerial.println(Serial.read()); // write it to the GPRS shield
}
void clearBufferArray() // function to clear buffer array
{
delay(1000);
for (int i = 0; i < count; i++)
{
buffer[i] = NULL; // clear all index of array with command NULL
delay(100);
}
for (int n = 0; n < count; n++)
{
buffer[n] = NULL; // clear all index of array with command NULL
delay(100);
}
for (int m = 0; m < count; m++)
{
buffer[m] = NULL; // clear all index of array with command NULL
delay(100);
}
for (int p = 0; p < count; p++)
{
buffer[p] = NULL; // clear all index of array with command NULL
delay(100);
}
}
void Sim900_Inti(void)
{
GSMSerial.println("AT+CMGF=1"); // Set GSM shield to sms mode
Serial.println("AT+CMGF=1");
delay(500);
GSMSerial.println("AT+CNMI=2,2");
Serial.println("AT CMGF=1");
delay(500);
}
void Cmd_Read_Act(void) //Function reads the SMS sent to SIM900 shield.
{
char buffer_i[128];
for (int i = 0; i < count; i++)
{
buffer_i[i] = char(buffer[i]);
}
if (strstr(buffer_i, "1111")) //Comparing password entered with password stored in program
{
digitalWrite(Led1, HIGH);
SMS_1111();
}
char buffer_n[128];
for (int n = 0; n < count; n++)
{
buffer_n[n] = char(buffer[n]);
}
if (strstr(buffer_n, "2222")) //Comparing password entered with password stored in program
{
digitalWrite(Led2, HIGH);
SMS_2222();
}
char buffer_m[128];
for (int m = 0; m < count; m++)
{
buffer[m] = char(buffer[m]);
}
if (strstr(buffer_m, "3333")) //Comparing password entered with password stored in program
{
digitalWrite(Led3, HIGH);
SMS_3333();
}
char buffer_p[128];
for (int p = 0; p < count; p++)
{
buffer[p] = char(buffer[p]);
}
if (strstr(buffer_p, "4444")) //Comparing password entered with password stored in program
{
digitalWrite(Led4, HIGH);
SMS_4444();
}
}
void SMS_1111() // complet liter Replay SMS TO Know Led1 Is ON
{
}
void SMS_2222()// complet liter
{
}
void SMS_3333()// complet liter
{
}
void SMS_4444()// complet liter
{
}>
-
1Why are you using software serial on an Arduino Mega?gre_gor– gre_gor2017年09月12日 16:50:21 +00:00Commented Sep 12, 2017 at 16:50
-
Sorry I used Arduino Uno before now my problem when I send 1111 or 2222 I received SMS from gsm module but when I send 3333 or 4444 not received any thingMoosa– Moosa2017年09月12日 17:58:02 +00:00Commented Sep 12, 2017 at 17:58
1 Answer 1
For the 3333
and 4444
you are doing
buffer[m] = char(buffer[m]);
and
buffer[p] = char(buffer[p]);
which does nothing.
You probably meant
buffer_m[m] = char(buffer[m]);
and
buffer_p[p] = char(buffer[p]);
answered Sep 12, 2017 at 18:12
-
@Moosa Don't forget to accept the answer if it solved your problem.gre_gor– gre_gor2017年09月12日 21:20:32 +00:00Commented Sep 12, 2017 at 21:20
default