can some one help me with this i am trying to get readings from all the sensors and activate a realy if any of them go outside a maxtemp range if i use normal way the temp0 activates but temp1 tries to close relay at same time
thanks
#include <Ethernet.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <VirtualWire.h>
int temperature_sensor_bus=7; //connection for temperature sensing bus
//------------------------------------------------------------
unsigned long previousMillis_temp;
int temp_postrate=30000; //every two min
//------------------------------------------------------------
// Temperature Variables
//------------------------------------------------------------
OneWire oneWire(temperature_sensor_bus); //setup one wire and Dallas temperature sensor library
DallasTemperature sensors(&oneWire);
float temp0; //
float temp1; //
float temp2; //
float temp3; //
float temp4; //
float acc0=0, acc1=0, acc2=0, acc3=0, acc4=0; //accumulators
int acc_count=0; //accumulator count
int temp_samples=30; //number of temperature samples to average over (30 samples means the average temp is calculated ever 8.144 seconds)
int TEMPERATURE_PRECISION=12; //9 b bit percision
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
// Ethernet Varialbes
byte mac[] = {0x90, 0xA2, xxx, xxx, 0xAC, 0xF1};
byte ip[] = {192, xxx, xxx, xxx };
byte gateway[] = {192, xxx, xxx, xxx};
byte subnet[] = {255, 255, 255, 0};
byte server[] = {xxx, xxx, xxx, xxx};
EthernetClient client;
char str[250];
// Setup
void setup(){
Serial.begin(9600);
sensors.begin();
delay(100);
numberOfDevices = sensors.getDeviceCount();
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(numberOfDevices, DEC);
Serial.println(" devices.");
for(int i=0;i<numberOfDevices; i++)
{
if(sensors.getAddress(tempDeviceAddress, i))
{
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" with address: ");
printAddress(tempDeviceAddress);
Serial.println();
Serial.print("Setting resolution to ");
Serial.println(TEMPERATURE_PRECISION,DEC);
delay(100);
// set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
Serial.print("Resolution actually set to: ");
Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
Serial.println();
}else{
Serial.print("Found ghost device at ");
Serial.print(i, DEC);
Serial.print(" but could not detect address. Check power and cabling");
}
}
sensors.requestTemperatures(); //issue global request for each temp sensor on network to retunr a temp
if(sensors.getAddress(tempDeviceAddress, 0))
temp0=(sensors.getTempC(tempDeviceAddress)); //read temp from sensor 0 and store in accumulator 0
if(sensors.getAddress(tempDeviceAddress, 1))
temp1=(sensors.getTempC(tempDeviceAddress));
if(sensors.getAddress(tempDeviceAddress, 2))
temp2=(sensors.getTempC(tempDeviceAddress));
if(sensors.getAddress(tempDeviceAddress, 3))
temp1=(sensors.getTempC(tempDeviceAddress));
if(sensors.getAddress(tempDeviceAddress, 4))
temp2=(sensors.getTempC(tempDeviceAddress));
if (temp0 == DEVICE_DISCONNECTED)
{
sensors.begin();
for(int i=0;i<numberOfDevices; i++)
sensors.getAddress(tempDeviceAddress, i);
Serial.println("problem");
}
Ethernet.begin(mac, ip, gateway, subnet); //Setup ethernet client
}
void loop(){
if (temp0 == DEVICE_DISCONNECTED)
{
sensors.begin();
for(int i=0;i<numberOfDevices; i++)
sensors.getAddress(tempDeviceAddress, i);
Serial.println("problem");
}
if (acc_count <= temp_samples){
sensors.requestTemperatures(); //issue global request for each temp sensor on network to retunr a temp
if(sensors.getAddress(tempDeviceAddress, 0))
acc0=acc0 + (sensors.getTempC(tempDeviceAddress)); //read temp from sensor 0 and store in accumulator 0
if(sensors.getAddress(tempDeviceAddress, 1))
acc1=acc1 + (sensors.getTempC(tempDeviceAddress));
if(sensors.getAddress(tempDeviceAddress, 2))
acc2=acc2 + (sensors.getTempC(tempDeviceAddress));
if(sensors.getAddress(tempDeviceAddress, 3))
acc1=acc1 + (sensors.getTempC(tempDeviceAddress));
if(sensors.getAddress(tempDeviceAddress, 4))
acc2=acc2 + (sensors.getTempC(tempDeviceAddress));
acc_count++; //increment accumulator count
}
if (acc_count >temp_samples) //after 30 samples have been taken...
{
temp0=acc0/acc_count; //get average temperature sensor reading
temp1=acc1/acc_count; //get average temperature sensor reading
temp2=acc2/acc_count; //get average temperature sensor reading
temp3=acc3/acc_count; //get average temperature sensor reading
temp4=acc4/acc_count; //get average temperature sensor reading
acc0=0; //reset accumulator
acc1=0; //reset accumulator
acc2=0; //reset accumulator
acc3=0; //reset accumulator
acc4=0; //reset accumulator
acc_count=0; //reset accumulator count
}
Serial.print(temp0);
Serial.print(" ");
Serial.print(temp1);
Serial.print(" ");
Serial.print(temp2);
Serial.print(" ");
Serial.print(temp3);
Serial.print(" ");
Serial.println(temp4);
Serial.print(" ");
int variableB = (int) temp0;
int variableC = (int) temp1;
int variableD = (int) temp2;
int variableE = (int) temp3;
int variableF = (int) temp4;
char str_rf[30]; //create string
strcat(str_rf,"A"); //Add identifier character
itoa(variableB,str_rf,10); //Convert to string
strcat(str_rf,"B"); //Add identifier character
itoa(variableC,str_rf,10); //Convert to string
strcat(str_rf,"C"); //Add identifier character
itoa(variableD,str_rf,10); //Convert to string
strcat(str_rf,"D"); //Add identifier character
itoa(variableE,str_rf,10); //Convert to string
strcat(str_rf,"E"); //Add identifier character
itoa(variableF,str_rf,10); //Convert to string
strcat(str_rf,"F"); //Add identifier character
// 3a) Create a string to be sent to the server