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)