Pages: [1]   Go Down
Author Topic: GPRS/GSM alarm system responding to 'state change'  (Read 1600 times)
0 Members and 1 Guest are viewing this topic.
Cardiff
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I'm currently working on a project which should be very simple for a competent programmer but im having trouble with my code. In basic terms all I want to replicate is to send a text in response to  'state changes'  which differentiate between certain 'zones' along several lengths of cable . In the following code I have attempted to simulate 4.5V from 2 seperate battery packs powering two twisted pairs of cable then connected to inputs 11 and 12 which are simulating zones 1 and 2 respectively. The code is attempting to do the following:-
1. When there is a dis on line 1 (pin11) ZONESTATE1 will change from high to low and send a text stating 'Zone 1'.
2. When there is a dis on line 1 and 2 (pin11 and 12) ZONESTATE2 and ZONESTATE1 will both change from high to low and send a text stating 'Zone 2'.
3. There will be no seperate dis for line 2 alone so this is not relevant.

Here is my attempt at the code:-

/* GSM Shield Sending an SMS Text Message - written by Geezo 26/02/13 */
#include <NewSoftSerial.h>
NewSoftSerial cell(2,3);  // This creates a serial port on D2/D3 to talk to the GSM module
char mobilenumber[] = "0xxxxxxx8";  // Replace 0xxxxxx8 with whatever the recipient's mobile number
const int LED = 13; // the pin for the LED
const int PINZONE1 = 11; // name pin 11 as 'Zone 1'
const int PINZONE2 = 12; // name pin 12 as 'Zone 2'
int ZONE1STATE = LOW; //  Will store state of input pin to 0 (i.e. LOW), so when sees 5V will be HIGH
int ZONE2STATE = LOW; //  Will store state of input pin to 0 (i.e. LOW), so when sees 5V will be HIGH
int LASTZONE1STATE = HIGH;
int LASTZONE2STATE = HIGH;
void setup()
{  //Initialize serial ports for communication.
cell.begin(9600);
delay(35000); // give the GSM module time to initialise, locate network etc.
pinMode(LED,OUTPUT); // Tell Arduino LED is an output
pinMode(PINZONE1,INPUT); // And Zone1 is an input
pinMode(PINZONE2,INPUT); // And Zone2 is an input
}
void loop()
{
ZONE1STATE = digitalRead(PINZONE1); //read PINZONE1 input value and store it
ZONE2STATE = digitalRead(PINZONE2); //read PINZONE2 input value and store it
if (ZONE1STATE == HIGH && ZONE2STATE == HIGH) 
{
digitalWrite(LED,LOW);
}

else if (ZONE2STATE == LOW && ZONE1STATE ==LOW) 
    {{
    digitalWrite(LED,HIGH);
    cell.println("AT+CMGF=1"); // set SMS mode to text
    cell.print("AT+CMGS=");  // now send message...
    cell.print(34,BYTE); // ASCII equivalent of "
    cell.print(mobilenumber);
    cell.println(34,BYTE);  // ASCII equivalent of "
    delay(500); // give the module some thinking time
    cell.print("Cable Fault Zone 2 ");   // our message to send
    cell.println(26,BYTE);  // ASCII equivalent of Ctrl-Z
    delay(15000);// the SMS module needs time to return to OK status
    }
    do
    {
    delay(1);
     }
    while (1>0);
 }

else if (ZONE1STATE < ZONE2STATE && ZONE1STATE != ZONE2STATE)
{delay(5);
 if (ZONE1STATE == LOW && ZONE2STATE == HIGH)
    {
     digitalWrite(LED,HIGH);
     cell.println("AT+CMGF=1"); // set SMS mode to text
     cell.print("AT+CMGS=");  // now send message...
     cell.print(34,BYTE); // ASCII equivalent of "
     cell.print(mobilenumber);
     cell.println(34,BYTE);  // ASCII equivalent of "
     delay(500); // give the module some thinking time
     cell.print("Cable Fault Zone 1");   // our message to send
     cell.println(26,BYTE);  // ASCII equivalent of Ctrl-Z
     delay(15000);// the SMS module needs time to return to OK status
     }
     do
     {
     delay(1);
     }
     while (1>0);
}
}

Using this code sends a text OK for 'Zone 1' only, regardless of whether just line 1 is disconnected or both.
I assume this must be down to my basic knowledge of the code. Further along the line I would also like to attempt the following:-
1. Send texts out to multiple zones when more zones are added to the code.
2. Send the text out to multiple parties. (not just one number).
If Im struggling with just 2 zones now then i can see this being a long couple of weeks haha  smiley-lol.

Many thanks in advance to anybody who can guide me in the right direction. Your help will be very much appreciated.


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You aren't using the hardware serial port to talk to the cell chip. So, why not use it to talk to the Serial Monitor application.

Are ZONE1STATE and ZONE2STATE what you think they are, after reading the pins? You are not using the internal pullup resistors, so you must be using external pullup or pulldown resistors. How is whatever is wired to pins 11 and 12 wired?

By the way, all upper case names are, by convention, limited to constants. Constants never appear on the left side of an equal sign in a function.
Logged

Pages: [1]   Go Up
Jump to: