/*
SMS sender
Number is automatically inouted to sketch. SMS content is manually inputed
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(6, 8, 9, 10, 11, 12);
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
const int BUTTON1 = 4;
const int BUTTON2 = 5;
char Receiver[9] = {"********"}; // telephone number to send sms
char Sender[9] = {"********"}; // telephone number to send sms
string
char c;
char txtMsg[200];
int buttonState = 0;
char incomingByte;
byte character[8] =
{
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
void ReceiveIncomingDataFromPC()
{
int i = 0;
if (Serial.available() > 0)
{
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
Receiver[i] = incomingByte;
if (i != 8 )
{
i++;
}
if ( i == 9)
{
Serial.println(Receiver[9]);
}
}
}
void setup()
{
//initialization pushbuttons
pinMode (BUTTON1, INPUT);
pinMode (BUTTON2, INPUT);
lcd.createChar(0, character);
lcd.begin(16, 2);
lcd.write(byte(0));
// initialize serial communications and wait for port to open:
Serial.begin(9600);
startup();
}
void loop()
{
ReceiveIncomingDataFromPC();
if(digitalRead(BUTTON1) == HIGH)
{
FaultMessage1();
}
if(digitalRead(BUTTON2) == HIGH)
{
FaultMessage2();
}
if (sms.available())
{
ReceivAndRespond();
}
}
void FaultMessage1()
{
ReceiveIncomingDataFromPC();
Serial.println("Fault detected at Bus 1");
char txtMsg[200] = {"Fault detected at Bus 1"};
Serial.println("SENDING MESSAGE");
Serial.println();
lcd.clear();
lcd.print("Sending Message");
// send the message
sms.beginSMS(Receiver);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nMESSAGE SENT!\n");
lcd.clear();
lcd.print("Message Sent!");
}
void FaultMessage2()
{
Serial.println("Fault detected at Bus 2");
char txtMsg[200] = {"Fault detected at Bus 2"};
Serial.println("SENDING MESSAGE");
Serial.println();
lcd.clear();
lcd.print("Sending Message");
// send the message
sms.beginSMS(Receiver);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nMESSAGE SENT!\n");
lcd.clear();
lcd.print("Message Sent!");
}
void ReceivAndRespond()
{
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(Sender, 20);
Serial.println(Sender);
lcd.clear();
lcd.print(Sender);
delay(1000);
// This is just an example of message disposal
// Messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
lcd.clear();
lcd.print("Message : ");
while(c=sms.read())
Serial.print(c);
lcd.print(c);
Serial.println("\nEND OF MESSAGE");
// delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}
void startup()
{
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Connnecting . . .");
lcd.print("Connnecting . . .");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
Serial.print("Officer in-charge number:");
Serial.println(Sender);
}
Serial.println("GSM initialized");
lcd.clear();
lcd.print("GSM Initialized");
}
what i get is
Connnecting . . .
Officer in-charge number:********
GSM initialized
I received: *
I received: *
I received: *
I received: *
I received: *
I received: *
I received: *
I received: *
I received:
I received:
Fault detected at Bus 2
SENDING MESSAGE
MESSAGE SENT!
i did not receive the message
Moderator edit: code tags, yet again. Why is it so difficult?