text messaging alarm status

I work on a boat and over the weekends there is no one on the boat to monitor the status of the vessel so i wrote this code to read 5 alarm states, as digital inputs, and then send a text to me notifying me of the issue. much of the insperation for the coding came from http://jeffmurchison.com/blog/send-sms-from-your-arduino/ and modified for the setup i have. i do not have the hardware yet to test this and was wondering if some people with more experience can look it over for me. thanks in advance.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3,2); //RX, TX pins

// these constants won’t change:

const int forwardbilge = 4; // the pin that the forward bilge alarm is attached to
const int aftbilge = 5; // the pin that the aft bilge alarm is attached to
const int zdrivebilge = 6; // the pin that the z- drive bilge alarm is attached to
const int fire = 7; // the pin that the fire alarm is attached to
const int powerfailure = 8; // the pin that detects power failure

int forwardbilgestate = 0; // initial state of bilge alarm
int aftbilgestate = 0; // initial state of bilge alarm
int zdrivebilgestate = 0; // initial state of the z-drive bilge
int firestate = 0; // initial state of the fire alarm
int powerfailurestate =HIGH; // initial state of power failure

void setup() {
pinMode(13, OUTPUT); //sets pin 13 (led) as a output
pinMode(forwardbilge, INPUT);// sets the forward bilge as an input
pinMode(aftbilge, INPUT); // sets the aft bilge as an input
pinMode(zdrivebilge, INPUT); // sets the z-drive bilge as an input
pinMode(fire, INPUT); // sets the fire alarm as an input
pinMode(powerfailure, INPUT);// sets the power failure as an input
mySerial.begin(4800);
}

void loop() {
// the main loop will constantly read the state of the inputs and will serial print\
// when the state changes.\
forwardbilgestate = digitalRead(forwardbilge);
aftbilgestate = digitalRead(aftbilge);
zdrivebilgestate = digitalRead(zdrivebilge);
firestate = digitalRead(fire);
powerfailurestate = digitalRead(powerfailure);

if (forwardbilgestate == HIGH){ // if the forward bilge is full
digitalWrite(13, HIGH); // Turn LED on to tell you message is sending
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500); // wait
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000); // Wait
mySerial.print(“forward bilge is full.”); // Message contents
delay(1000); // Wait
mySerial.write(byte(26)); // (signals end of message)
delay(1000); // Wait
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250); // Wait
digitalWrite(13, HIGH); // Turn LED on
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
}
if (aftbilgestate == HIGH){ // if the aft bilge is full
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“aft bilge is full.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
if (zdrivebilgestate == HIGH){ // if the z-drive bilge is full
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“Z-drive bilge is full.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
if (firestate == HIGH){ // if the fire alarm is active
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“fire alarm is active.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
if (powerfailurestate == HIGH){ // if there is a power failure
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“power failure.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
}

remote_alarm_panel2.ino (7.69 KB)

i posted this in a different spot but i think this is a more proper place.

I work on a boat and over the weekends there is no one on the boat to monitor the status of the vessel so i wrote this code to read 5 alarm states, as digital inputs, and then send a text to me notifying me of the issue. much of the insperation for the coding came from http://jeffmurchison.com/blog/send-sms-from-your-arduino/ and modified for the setup i have. i do not have the hardware yet to test this and was wondering if some people with more experience can look it over for me. thanks in advance.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3,2); //RX, TX pins

// these constants won’t change:

const int forwardbilge = 4; // the pin that the forward bilge alarm is attached to
const int aftbilge = 5; // the pin that the aft bilge alarm is attached to
const int zdrivebilge = 6; // the pin that the z- drive bilge alarm is attached to
const int fire = 7; // the pin that the fire alarm is attached to
const int powerfailure = 8; // the pin that detects power failure

int forwardbilgestate = 0; // initial state of bilge alarm
int aftbilgestate = 0; // initial state of bilge alarm
int zdrivebilgestate = 0; // initial state of the z-drive bilge
int firestate = 0; // initial state of the fire alarm
int powerfailurestate =HIGH; // initial state of power failure

void setup() {
pinMode(13, OUTPUT); //sets pin 13 (led) as a output
pinMode(forwardbilge, INPUT);// sets the forward bilge as an input
pinMode(aftbilge, INPUT); // sets the aft bilge as an input
pinMode(zdrivebilge, INPUT); // sets the z-drive bilge as an input
pinMode(fire, INPUT); // sets the fire alarm as an input
pinMode(powerfailure, INPUT);// sets the power failure as an input
mySerial.begin(4800);
}

void loop() {
// the main loop will constantly read the state of the inputs and will serial print\
// when the state changes.\
forwardbilgestate = digitalRead(forwardbilge);
aftbilgestate = digitalRead(aftbilge);
zdrivebilgestate = digitalRead(zdrivebilge);
firestate = digitalRead(fire);
powerfailurestate = digitalRead(powerfailure);

if (forwardbilgestate == HIGH){ // if the forward bilge is full
digitalWrite(13, HIGH); // Turn LED on to tell you message is sending
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500); // wait
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000); // Wait
mySerial.print(“forward bilge is full.”); // Message contents
delay(1000); // Wait
mySerial.write(byte(26)); // (signals end of message)
delay(1000); // Wait
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250); // Wait
digitalWrite(13, HIGH); // Turn LED on
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
}
if (aftbilgestate == HIGH){ // if the aft bilge is full
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“aft bilge is full.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
if (zdrivebilgestate == HIGH){ // if the z-drive bilge is full
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“Z-drive bilge is full.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
if (firestate == HIGH){ // if the fire alarm is active
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“fire alarm is active.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
if (powerfailurestate == HIGH){ // if there is a power failure
digitalWrite(13, HIGH); // Turn LED on.
mySerial.println(“AT”); // Sends AT command to wake up cell phone
delay(500);
mySerial.println(“AT+CMGF=1”); // Puts phone into SMS mode
delay(1000); // Wait a second
mySerial.println(“AT+CMGW=”+12076648321""); // Creates new message to number
delay(1000);
mySerial.print(“power failure.”); // Message contents
delay(1000);
mySerial.write(byte(26)); // (signals end of message)
delay(1000);
mySerial.println(“AT+CMSS=1”); // Sends message at index of 1
digitalWrite(13, LOW); // Turn LED off
delay(250);
digitalWrite(13, HIGH); // Turn LED on.
delay(10000); // Give the phone time to send the SMS
mySerial.println(“AT+CMGD=1”); // Deletes message at index of 1
digitalWrite(13, LOW); // Turn LED off.
delay(250);
}
}

remote_alarm_panel2.ino (7.69 KB)

My first reaction is that there is a lot of duplicated code. Turn the code to send a text into a function and pass it the message to be sent.

If one of the sensors were to go off, your setup will keep sending messages to your phone until you fix the problem. It might be too much. For the five sensors, do you have to get to your boat if ANY of the sensors go off? If yes, you can do this, see if one of the sensors is HIGH, then send out two SMS (in case first one is lost) and then run a while(1) so the program is stuck there instead of keep sending messages.

Read this before posting a programming question

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator