   sensors.begin();
   if (!sensors.getAddress(ambientTemperature, 0)) Serial.println("Unable to find address for Device 0"); 
   if (!sensors.getAddress(casingTemperature, 1)) Serial.println("Unable to find address for Device 1"); 
+  if (!sensors.getAddress(glandTemperature, 2)) Serial.println ("Unable to find address for Device 2");
   sensors.setResolution(ambientTemperature, TEMPERATURE_PRECISION);
   sensors.setResolution(casingTemperature, TEMPERATURE_PRECISION);
-  sensors.setWaitForConversion(false);
+  sensors.setResolution(glandTemperature, TEMPERATURE_PRECISION);
+  sensors.setWaitForConversion(false);      //Important undocumented feature that is only needed for "parasitic mode"
   sensors.requestTemperatures();
   delayInMillis = 750 / (1 << (3)); 
   lastTempRequest = millis(); 
 
 
-//Initialize load washer samples
-for (int i = 0; i<load_sample_window; i++){
-  load1_samples[i]=0;
-  load2_samples[i]=0;
-
-
+  //Initialize load washer samples
+  for (int i = 0; i<load_sample_window; i++){
+    load1_samples[i]=0;
+    load2_samples[i]=0;
+  }
+	
+	
+  //Initialize SEN0093 pins (shaft temperature)
   pinMode(DataPin,INPUT);
   pinMode(ClockPin,INPUT);
   pinMode(TestPin,OUTPUT);
   digitalWrite(TestPin, HIGH);
   delay(100);
-}
   
 } 
 

   ////////////////////////////////////////////////////////Tachometer 
   // Check if tach was triggered
   if (revolution_occured) {
   revolution_count ++;
   revolution_occured = !revolution_occured;
   }   
 
 // Calculate RPM
 current_time = millis();
   if (current_time - previous_time >= 1000) {
     rpm = (revolution_count / DURATION * 60);
     previous_time = current_time;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                           SENSOR NETWORK FIRMWARE
//
// This is the code for the sensor node. It integrates the following SENSORS an prints data to the serial monitor. 
// 1. Temperature Sensors.
//      At various locations around the pump
// 2. Shaft Temperature Sensor
// 3. Tachometer
//      Measuring the rpms of the motor shaft
// 4. Load Washers 1 & 2
// 5. Level Sensor
//
//The following are driven based on the sensor values:
// 5. Solenoid Drain Valve
// 6. The Serial Monitor
//      The data from each sensor is printed on the serial monitor. The data on the serial monitor will be picked up
//      by the Zigbee module and automatically transmitted to the base node. (Remember to toggle switch on shield to SERIAL) 




//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                            1. TEMPERATURE SENSORS
#include <OneWire.h>
#include <DallasTemperature.h>


#define ONE_WIRE_BUS 4                 // Data wire is plugged into port 2 on the Arduino
#define TEMPERATURE_PRECISION 9        // 9 bits or one decimal point

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);        

DallasTemperature sensors(&oneWire);                  // Pass our oneWire reference to Dallas Temperature.
DeviceAddress casingTemperature, ambientTemperature, glandTemperature;   // OneWire variables
unsigned long lastTempRequest = 0;
int  delayInMillis = 0;
float ambient_temperature = 0.0;
float casing_temperature = 0.0;
float gland_temperature = 0.0;
int  idle = 0;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                           2. SHAFT TEMPERATURE SENSOR
//
// This device uses a 2KHz SPI protocol and has no memory scratchpad to read from so data must be read sequentially
// according to its clock speed It takes approximately 470ms for a reading and the data is five bytes long.

#define  ClockPin  6  // clock in
#define  DataPin   7  //data in  
#define  TestPin   8  //driver pin  set pin low to start deliver data

float shaftTemp = 0.0;

void data_read(int *p)
{
  int i,j,PinState,tempData;   
  digitalWrite(TestPin, LOW);              //start device transmission
  for(i=0;i<5;i++) {                       //read 5 bytes
    for(j=0;j<8;j++){                      //read 8 bits
      do{
        PinState = digitalRead(ClockPin);
      } while(PinState);                   //sync to clock by waiting for change to LOW 
      delayMicroseconds(100);              //buffer
      PinState = digitalRead(DataPin);     //read data bit
      if(1 == PinState)                    
        tempData = (tempData<<1 & 0xfe)+1; //add 1
      else
        tempData = (tempData<<1 & 0xfe);   //add 0
      do{
        PinState = digitalRead(ClockPin);  //get stuck until clock changes
      }while(PinState != 1);
    }
  *p++ = tempData;                         //pass byte to array pointer address 
  }
  digitalWrite(TestPin, HIGH);             //stop device transmission
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                  3. TACHOMETER
const byte TACH = 2;
const byte DURATION = 1;
volatile boolean revolution_occured = false;   
unsigned int revolution_count = 0;
unsigned int current_time = 0;
unsigned int previous_time = 0;
unsigned int rpm = 0;

// Tachometer Interrupt Service Routine (ISR)

void revolution (){
  revolution_occured = true;
  }  

///////////////////////////////////////////////////////////////////////////////////////////////////////////// 
//                                                 4. LOAD WASHER 1 & 2

int loadWasher1Pin = A0;
int loadWasher2Pin = A1;
