SENDING MESSAGE WITH ARDUINO WITH ORDINARY GSM MODULE (NO GSM SHIELD) WITH AT COMMANDS
Using a GSM module with arduino for sending message ..
1. Find your GSM modules Baud rate
2. Connecting to Arduino .. You need to connect only 3 pins from GSM to Arduino
* RX from Arduino to TX of GSM
* TX from Arduino to RX of GSM module
* GND pin from GSM to GND of Arduino..
MAKE SURE THAT U HAVE CONNECTED ALL PINS CORRECTLY !!
If yes ! .. your hardware interfacing is Over .. !
Now , about the Arduino program. We have a library already in Arduino called GSM.h .
Here , we are not using that because we are not using GSM shield so there is a chance of error..
This method is simple though . we use simple "Serial" function and "String" function.
Program for sending a message ..follows ..
////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(9600); // Baud rate of the GSM Module
}
void loop()
{
SendTextMessage();
delay(2000);
}
void SendTextMessage()
{
Serial.println("AT"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGF=1"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGS=\"+91******\"\r"); // change to the phone number you using
delay(100);
Serial.println("A test message!");//the content of the message
delay(100);
Serial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
}
////////////////////////////////////////////////////////////////////////////////////////////////
{
Serial.begin(9600); // Baud rate of the GSM Module
}
void loop()
{
SendTextMessage();
delay(2000);
}
void SendTextMessage()
{
Serial.println("AT"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGF=1"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGS=\"+91******\"\r"); // change to the phone number you using
delay(100);
Serial.println("A test message!");//the content of the message
delay(100);
Serial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
}
////////////////////////////////////////////////////////////////////////////////////////////////
This Code will Send message continuously every 2 seconds.
To restrict to a single message, use it n setup function or
int a =0;
To restrict to a single message, use it n setup function or
int a =0;
void setup()
{
Serial.begin(9600); // Baud rate of the GSM Module
}
void loop()
{
if(a=0)
{
SendTextMessage();
a=1;
}
delay(2000);
}
void SendTextMessage()
{
Serial.println("AT"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGF=1"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGS=\"+91******\"\r"); // change to the phone number you using
delay(100);
Serial.println("A test message!");//the content of the message
delay(100);
Serial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
}
{
Serial.begin(9600); // Baud rate of the GSM Module
}
void loop()
{
if(a=0)
{
SendTextMessage();
a=1;
}
delay(2000);
}
void SendTextMessage()
{
Serial.println("AT"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGF=1"); //Because we want to send the SMS in text mode
delay(100);
Serial.println("AT+CMGS=\"+91******\"\r"); // change to the phone number you using
delay(100);
Serial.println("A test message!");//the content of the message
delay(100);
Serial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
Here we declare 'a' as a flag. Initially a is set to zero and anfter sending the messgae, we just pull the value of a to one so that it comes out of the loop.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Here we declare 'a' as a flag. Initially a is set to zero and anfter sending the messgae, we just pull the value of a to one so that it comes out of the loop.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Queries accepted ..willing to help if your problem is inside my range of knowledge :)
Mail me : nikhiljoji@gmail.com
Comments
Post a Comment