I am running the code below to sent an SMS to a GSM Shield and control a Relay or get some values from some sensors. The code is running with no problems with the UNO but I cannot run it with a MEGA. The connections I am using with the MEGA are: D0 at Shield to RX1 (19) to Mega D1 at Shield to TX1 (18) to Mega Ground connection Between them
The GSM shiled is (SIM900 V2.2 Wireless Module GSM GPRS Shield Arduino (with SIM card holder) M91) bought in ebay. It is powered up with 2A power with no issues (It works with the UNO with no problems)
The Library that I am using is the ITEADLIB_Arduino_SIMCom-master
I am testing the hardware serial connection between the two boards with a simple sketch and the communicate properly (AT replies OK), but when I run my sketch they seem not to communicate. Can you please give me any input on that? I have made the changes needed for the Mega in the Libraries (GSM.h file to define Mega instead of UNO and HWSerial.h to define Mega).
What Am I missing please?
[#include <SIM900.h>
#include <sms.h>
int ThermistorPin = 5;
int Vo;
float R1 = 10000; //resistor 10K
float logR2, R2, T1, Tc;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
SMSGSM sms;
int rel1 = 10; // Pin 10 for relay 1
int ledrel1 = 4; // Pin 12 for relay 1 led
int ledgsm = 6; // Pin 6 for GSM status LED
int humidity_sensor1_pin = A0;
byte humidity_sensor1_vcc = 13;
int sensor1value;
boolean started=false;
char smsbuffer[160];
char Sender[20];
void setup()
{
Serial.begin(9600);
Serial.println("OPERATING RELAYS WITH GSM MODULE");
pinMode(rel1, OUTPUT); // set pin 10 OUTPUT.
pinMode(ledrel1, OUTPUT); // set pin 4 OUTPUT.
digitalWrite(rel1, HIGH); // initialise the rel
digitalWrite(ledrel1, LOW); // set Relay 1 LED off
pinMode(ledgsm, OUTPUT); // set pin 6 OUTPUT for GSM led.
pinMode(humidity_sensor1_vcc, OUTPUT); // Initialize the humidity sensor board
digitalWrite(humidity_sensor1_vcc, LOW);
// Initiallise GSM connection by setting the baud rate, To use HTTP 4800 or less should be used
if ( gsm.begin(2400) )
{
Serial.println("STATUS of GSM Module = IDLE");
started=true;
digitalWrite(ledgsm, HIGH); //set GSM LED ON
}
else
Serial.println("STATUS of GSM Module = INACTIVE");
} //end of void setup
int read_humidity_sensor1() {
digitalWrite(humidity_sensor1_vcc, HIGH);
delay(2000);
int value1 = analogRead(humidity_sensor1_pin);
digitalWrite(humidity_sensor1_vcc, LOW);
return value1;
}
float read_temp(){
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T1 = (1.0 / (c1 + c2logR2 + c3logR2logR2logR2));
Tc = T1 - 273.15;
return Tc;
}
void loop()
{
char inSerial[50]; //for GSM
char position; //for SMS
char relon [3]= "ON";
char reloff [5]= "OFF";
read_temp(); //read the thermistor
Serial.print("Thermistor temperature: ");
Serial.print(Tc);
Serial.println(" C");
if (started) {
position = sms.IsSMSPresent(SMS_ALL); // Check SMS in sim from 1..20
if (position)
{
// Read SMS and determine the sender
sms.GetSMS(position, Sender, smsbuffer, 160);
if ((strcmp(Sender,"+306932239171")==0) //change the number to authorise to open
|| (strcmp(Sender,"+306908500553")==0))
{
Serial.print("Command Received [tel. "+String(Sender)+String("]: ") + String(smsbuffer));
if (strcmp(smsbuffer,"P1-ON")==0){
digitalWrite(rel1, LOW);
digitalWrite(ledrel1, HIGH); // set Relay 1 LED ON
Serial.println(" => Pump 1 is ON");
}
else if (strcmp(smsbuffer,"P1-OFF")==0){
digitalWrite(rel1, HIGH);
digitalWrite(ledrel1, LOW); // set Relay 1 LED OFF
Serial.println(" => Pump 1 is OFF");
}
else if (strcmp(smsbuffer,"STATUS")==0)
{
int r1=digitalRead(10);
char str[12] ={'\0'};
char str1[20] ={'\0'};
char str2[35] ={'\0'};
char str4[5] ={'\0'};
char str5[5] ={'\0'}; //array for temp
if (r1==1)
sprintf(str4,"%s ",reloff);
else
sprintf(str4,"%s ",relon);
read_temp(); //read the thermistor
sensor1value=read_humidity_sensor1();
sprintf(str, "Sensor1: %d", sensor1value);
sprintf(str1, "%s, Relay is: %s",str, str4);
dtostrf(Tc, 3, 1, str5);
sprintf(str2, "%s, Temp now: %s",str1, str5);
(sms.SendSMS("+306932239171", str2));
Serial.println(str2);
Serial.println("\nThe reply SMS for the humidity sensors and Relay statuses was sent to the number");
}
}
else
Serial.println(" => The sender number was NOT Recognized!!!!!");
sms.DeleteSMS(position); // Delete the SMS that was just analysed
}
delay(2000);
} //if started
} //void loop]