in my project i have to send sms from gsm to arduino, so will anybody please tell me that which pins of the gsm shield should i connect with aruino board, or which pins of sim 900 should i connect with atmega 328 microcontroller ???
actually i have connected vin and ground pin of gsm shield with vin and ground , and 2,3 pin of gsm shield with 2 n 3 pin of arduino board with jumper wires,through these four connections i am recieving sms through gsm, now in my program am facing a problem , here is my whole program,
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
#include <Wire.h>
#include <DS1307RTC.h>
unsigned long start_time;
char data = 0;
#include <GSM.h>
#define PINNUMBER ""
GSM gsmAccess;
GSM_SMS sms;
#include <Time.h>
#include <TimeAlarms.h>
#define PJG_DATA 5
#define INT_SLAVE 'I'
byte hourStart1 = 0;
byte minuteStart1 = 0;
AlarmID_t alarmStart1; //ID for interval Slave 1
int led=13;
char senderNumber[20];
void setup()
{
Serial.begin(9600);
Wire.begin();
while (!Serial) ; // wait until Arduino Serial Monitor opens
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS Messages Receiver");
// connection state
boolean notConnected = true;
// Start GSM connection
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
alarmStart1 = Alarm.alarmRepeat(8, 1, 00, Start1); //==start alarm mode interval slave 1
}
void loop() {
char c;
if (timeStatus() == timeSet) {
digitalClockDisplay();
} else {
Serial.println("The time has not been set. Please run the Time");
Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
Serial.println();
delay(4000);
}
delay(1000);
if (sms.available())
{ Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
if(c=sms.read())
Serial.print(c);
Serial.println("\nEND OF MESSAGE");
if (c == INT_SLAVE)
Interval1();
sms.flush();
}
else if (Serial.available())
{
char header = Serial.read();
if (header == INT_SLAVE)
Interval2();
}
Serial.print("Current Date / Time: ");
digitalClockDisplay();
Alarm.delay(1000);
}
void Interval1()
{ int hourStart1 = Serial.parseInt();
int minuteStart1 = Serial.parseInt();
time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
Alarm.free(alarmStart1); // remove the old alarm
alarmStart1 = Alarm.alarmRepeat( newStart1,Start1); // create the new alarm
Serial.print("New alarm set for ");
Serial.print(hourStart1);
Serial.print(":");
Serial.println(minuteStart1);
}
void Interval2()
{
int hourStart1 = Serial.parseInt();
int minuteStart1 = Serial.parseInt();
time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
Alarm.free(alarmStart1); // remove the old alarm
alarmStart1 = Alarm.alarmRepeat( newStart1,Start1); // create the new alarm
Serial.print("New alarm set for ");
Serial.print(hourStart1);
Serial.print(":");
Serial.println(minuteStart1);
}
void Start1() {
Serial.println("alarm has set to this point");
}
void digitalClockDisplay()
{
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
now the problem is that when the connection of gsm and arduino is disturbed due to some reason , like anyone of the pin is disconnected , then the program execution is stopped , becoz nothing is displayed on my bluetrem app(which i am using as serial monitor ,which display allthe statements and the data which can be displayed by serial monitor)and when the connection is again established again i get nothing on my blueterm app, but if at this point i open the serial monitor it will start the program execution from the 1st line of the program. this all happens becoz of these lines
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
alarmStart1 = Alarm.alarmRepeat(8, 1, 00, Start1); //==start alarm mode interval slave 1
}
if i remove these lines from the program then the program works perfectly fine , it means becoz of these statements my gprs shield should have to work properly all the time , no connection should be lost otherwise the program execution will stop...will anybody please help me out in this that what should i do next to overcome this problem
mem_Sent.ino (3.36 KB)