user27245: I have tried changing pinModes and I/O declarations but still getting erratic or unexpected pin readings (HIGH), even though, I think, that I have set them LOW during setup. I read elsewhere that this is not uncommon, but I have not found a similar situation or a suitable explanation/solution. I can only believe that it is a basic misunderstanding (still learning). Thanks for any support. By the way, I had deleted the use of the keypad for trial purposes. My code is below:
//////////////////////////// Initialize & Includes //////////////////////////
#include "SIM900.h"
#include "sms.h"
#include "Keypad.h"
#include <GSM.h>
SMSGSM sms;
boolean pir_SensorPin = 2;
int led_OutPin = 11; // green
int alarm_OutPin = 12; // red
int alarm_count = 0;
boolean switchPin = 4; // alarm on test
boolean keypadPIN;
int z = 0;
int i = 0;
int waitTime = 5000;

//////////////////////////// Setup Keypad //////////////////////////
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
char keys[ROWS][COLS] =
{
  {
    '1', '2', '3', 'A'
  }
  ,
  {
    '4', '5', '6', 'B'
  }
  ,
  {
    '7', '8', '9', 'C'
  }
  ,
  {
    '*', '0', '#', 'D'
  }
};
byte rowPins[ROWS] = {
  6, 7, A2, A3 // row pin# on keypad to Arduino pin#, ie Row Pin #1 goes to Arduino Pin #6, etc.
}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {
  3, A0, A1, A4
}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const char PIN[5] = {
  '9', '6', '7', '9', '#'
}; // PIN number
char key_input[5] = {
  0, 0, 0, 0, 0
}; // used for comparison

//////////////////////////////// Setup ///////////////////////////////////
void setup() {
  Serial.begin (9600);  // Establish Serial connection;
  pinMode (switchPin, INPUT);       // Set pinMode.
  pinMode (led_OutPin, OUTPUT);     // Set pinMode.
  pinMode (alarm_OutPin, OUTPUT);   // Set pinMode.
  pinMode (pir_SensorPin, INPUT);   // Set pinMode.
  digitalWrite (led_OutPin, LOW);   // Set output pins to LOW for start.
  digitalWrite (alarm_OutPin, LOW); // Set output pins to LOW for start.
  digitalWrite (switchPin, LOW);
  digitalWrite (pir_SensorPin, LOW);
  Serial.println ("Studio Alarm starting up."); // Serial message that GSM shield is starting up
  if (gsm.begin(4800)) {    // Set GSM shield to recommended 4800 baud rate.
    Serial.println ("Status = Network READY");
    digitalWrite (led_OutPin, HIGH);
  }
  //  attachInterrupt (digitalPinToInterrupt (2), trigger, CHANGE); // PIR as interrupt
  Serial.println ("System Ready");

}

//////////////////////////// State Setup //////////////////////////
enum STATE {
  armed, // system acknowledges trigger
  unarmed, // system unarmed via keypad entry setting keypadPIN = LOW
  justActivated, // PIR-triggered
  alarm // confirm system unarmed then goto unarmed state else start alarm
};

STATE systemState = unarmed;
long timeGettingArmed;

/////////////////////////// Trigger ///////////////////////////////
//void trigger() {
//  systemState = alarm;

//////////////////////////// State Machine //////////////////////////
void loop() {
  check(); Serial.print ("switchPin = "); Serial.println (switchPin);
  Serial.print ("pir_SensorPin ="); Serial.println (pir_SensorPin);
  switch (systemState) {
    case armed:
      Serial.println ("armed");
      if (digitalRead (pir_SensorPin == HIGH)) {
        systemState = alarm;
      } else if (digitalRead (keypadPIN == LOW)) {
        systemState = unarmed;
      }
      break;
    case unarmed:
      if (digitalRead (pir_SensorPin == HIGH)) {
        Serial.println ("unarmed");
        timeGettingArmed = millis(); // Or just do a delay here.
        systemState = justActivated;
      }
      break;
    case justActivated:
      Serial.println ("juatActivated");
      if (timeGettingArmed + waitTime < millis()) {
        systemState = armed;
      }
      break;
    case alarm:
      Serial.println ("alarm");
      if (digitalRead (keypadPIN == LOW)) {
        systemState = unarmed;
      } else {
        beep();
      }
      break;
  }
}

//////////////////////////// Alarm //////////////////////////
void beep() {
  Serial.println("at beep");
  // (sms.SendSMS("**********", "*** Motion Detected in Studio! ***"));
  Serial.println ("MOTION detected: SMS Sent");
  for (alarm_count = 0; alarm_count <= 5; alarm_count++) { // Cycle outputs if triggered
    digitalWrite (alarm_OutPin, HIGH); delay (1000); // On/Off/On/Off/Off
    digitalWrite (alarm_OutPin, LOW); delay (500);
    digitalWrite (led_OutPin, HIGH); // delay (1000);
    Serial.println (alarm_count);
  }
  systemState = armed;
}

void check() {
  if (digitalRead (switchPin == HIGH)) { // manual test in lieu of keypad attached
    (keypadPIN = LOW); // unarmed
  }
  else {
    (keypadPIN = HIGH); // armed
  }
  Serial.print ("switchPin = "); Serial.println (switchPin);
  Serial.print ("keypadPIN = "); Serial.println (keypadPIN);
}

Serial output shows:
pir_SensorPin =1
switchPin = 1
keypadPIN = 1
switchPin = 1


user31794: Your code to read from the pins is incorrect. You write
if (digitalRead (pir_SensorPin == HIGH)) {

However, this compares pir_SensorPin == HIGH, (which is 2 == HIGH), producing a true or false that it then passes as the argument to digitalRead, which will try to interpret that as a pin number. Fix your parentheses:
if (digitalRead(pir_SensorPin) == HIGH)  {

(This problem occurs throughout your code.)
You also are writing an input pin in your setup, which is not necessarily wrong (it is one way of enabling or disabling the pullup resistor), but you should understand why you're doing it:
pinMode (pir_SensorPin, INPUT);   // Set pinMode.
...
digitalWrite (pir_SensorPin, LOW);


27245: <p>I have tried changing pinModes and I/O declarations but still getting erratic or unexpected pin readings (HIGH), even though, I think, that I have set them LOW during setup. I read elsewhere that this is not uncommon, but I have not found a similar situation or a suitable explanation/solution. I can only believe that it is a basic misunderstanding (still learning). Thanks for any support. By the way, I had deleted the use of the keypad for trial purposes. My code is below:</p>

<pre class="lang-cpp prettyprint-override"><code>//////////////////////////// Initialize &amp; Includes //////////////////////////
#include "SIM900.h"
#include "sms.h"
#include "Keypad.h"
#include &lt;GSM.h&gt;
SMSGSM sms;
boolean pir_SensorPin = 2;
int led_OutPin = 11; // green
int alarm_OutPin = 12; // red
int alarm_count = 0;
boolean switchPin = 4; // alarm on test
boolean keypadPIN;
int z = 0;
int i = 0;
int waitTime = 5000;

//////////////////////////// Setup Keypad //////////////////////////
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
char keys[ROWS][COLS] =
{
  {
    '1', '2', '3', 'A'
  }
  ,
  {
    '4', '5', '6', 'B'
  }
  ,
  {
    '7', '8', '9', 'C'
  }
  ,
  {
    '*', '0', '#', 'D'
  }
};
byte rowPins[ROWS] = {
  6, 7, A2, A3 // row pin# on keypad to Arduino pin#, ie Row Pin #1 goes to Arduino Pin #6, etc.
}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {
  3, A0, A1, A4
}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const char PIN[5] = {
  '9', '6', '7', '9', '#'
}; // PIN number
char key_input[5] = {
  0, 0, 0, 0, 0
}; // used for comparison

//////////////////////////////// Setup ///////////////////////////////////
void setup() {
  Serial.begin (9600);  // Establish Serial connection;
  pinMode (switchPin, INPUT);       // Set pinMode.
  pinMode (led_OutPin, OUTPUT);     // Set pinMode.
  pinMode (alarm_OutPin, OUTPUT);   // Set pinMode.
  pinMode (pir_SensorPin, INPUT);   // Set pinMode.
  digitalWrite (led_OutPin, LOW);   // Set output pins to LOW for start.
  digitalWrite (alarm_OutPin, LOW); // Set output pins to LOW for start.
  digitalWrite (switchPin, LOW);
  digitalWrite (pir_SensorPin, LOW);
  Serial.println ("Studio Alarm starting up."); // Serial message that GSM shield is starting up
  if (gsm.begin(4800)) {    // Set GSM shield to recommended 4800 baud rate.
    Serial.println ("Status = Network READY");
    digitalWrite (led_OutPin, HIGH);
  }
  //  attachInterrupt (digitalPinToInterrupt (2), trigger, CHANGE); // PIR as interrupt
  Serial.println ("System Ready");

}

//////////////////////////// State Setup //////////////////////////
enum STATE {
  armed, // system acknowledges trigger
  unarmed, // system unarmed via keypad entry setting keypadPIN = LOW
  justActivated, // PIR-triggered
  alarm // confirm system unarmed then goto unarmed state else start alarm
};

STATE systemState = unarmed;
long timeGettingArmed;

/////////////////////////// Trigger ///////////////////////////////
//void trigger() {
//  systemState = alarm;

//////////////////////////// State Machine //////////////////////////
void loop() {
  check(); Serial.print ("switchPin = "); Serial.println (switchPin);
  Serial.print ("pir_SensorPin ="); Serial.println (pir_SensorPin);
  switch (systemState) {
    case armed:
      Serial.println ("armed");
      if (digitalRead (pir_SensorPin == HIGH)) {
        systemState = alarm;
      } else if (digitalRead (keypadPIN == LOW)) {
        systemState = unarmed;
      }
      break;
    case unarmed:
      if (digitalRead (pir_SensorPin == HIGH)) {
        Serial.println ("unarmed");
        timeGettingArmed = millis(); // Or just do a delay here.
        systemState = justActivated;
      }
      break;
    case justActivated:
      Serial.println ("juatActivated");
      if (timeGettingArmed + waitTime &lt; millis()) {
        systemState = armed;
      }
      break;
    case alarm:
      Serial.println ("alarm");
      if (digitalRead (keypadPIN == LOW)) {
        systemState = unarmed;
      } else {
        beep();
      }
      break;
  }
}

//////////////////////////// Alarm //////////////////////////
void beep() {
  Serial.println("at beep");
  // (sms.SendSMS("**********", "*** Motion Detected in Studio! ***"));
  Serial.println ("MOTION detected: SMS Sent");
  for (alarm_count = 0; alarm_count &lt;= 5; alarm_count++) { // Cycle outputs if triggered
    digitalWrite (alarm_OutPin, HIGH); delay (1000); // On/Off/On/Off/Off
    digitalWrite (alarm_OutPin, LOW); delay (500);
    digitalWrite (led_OutPin, HIGH); // delay (1000);
    Serial.println (alarm_count);
  }
  systemState = armed;
}

void check() {
  if (digitalRead (switchPin == HIGH)) { // manual test in lieu of keypad attached
    (keypadPIN = LOW); // unarmed
  }
  else {
    (keypadPIN = HIGH); // armed
  }
  Serial.print ("switchPin = "); Serial.println (switchPin);
  Serial.print ("keypadPIN = "); Serial.println (keypadPIN);
}

Serial output shows:
pir_SensorPin =1
switchPin = 1
keypadPIN = 1
switchPin = 1
</code></pre>
 31794: <p>Your code to read from the pins is incorrect. You write</p>

<pre><code>if (digitalRead (pir_SensorPin == HIGH)) {
</code></pre>

<p>However, this compares <code>pir_SensorPin == HIGH</code>, (which is <code>2 == HIGH</code>), producing a true or false that it then passes as the argument to <code>digitalRead</code>, which will try to interpret that as a pin number. Fix your parentheses:</p>

<pre><code>if (digitalRead(pir_SensorPin) == HIGH)  {
</code></pre>

<p>(This problem occurs throughout your code.)</p>

<p>You also are writing an input pin in your setup, which is not necessarily wrong (it is one way of enabling or disabling the pullup resistor), but you should understand why you're doing it:</p>

<pre><code>pinMode (pir_SensorPin, INPUT);   // Set pinMode.
...
digitalWrite (pir_SensorPin, LOW);
</code></pre>
