arduino malfunction in program

the program works just only for 3 hours or 5., i cant just sure of it.,
after many hours of working is suddenly on and off the relay., every seconds

what would be my problem?
i use power supply for arduino uno an 13.8 volts 3a.
since arduino has its own voltage regulator.
can you identify my problems?

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
pinMode(2, OUTPUT); // maintain bulb small bulb ; this connected to relay controlling ac bulb
pinMode(3, OUTPUT); // two bulb;this connected to relay controlling ac bulb
pinMode(8, OUTPUT); // exhaust fan;this connected to relay controlling ac fan
pinMode(10, OUTPUT); this connected to relay controlling ac fan
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
sensors.begin();
}

void loop(void)
{
sensors.requestTemperatures(); // Send the command to get temperatures
delay(2000);
float sensorT = sensors.getTempCByIndex(0);
//-----------------------------
if (sensorT < 36.9){
Serial.println("less than normal temp");
Serial.println(sensorT);
digitalWrite(2, HIGH); // maintain bulb small bulb
digitalWrite(3, HIGH); // two bulb
digitalWrite(8, LOW); // exhaust fan
digitalWrite(10, LOW); // pakanat fan
}
else if ((sensorT >36.9) && (sensorT < 37.5 ))
{
Serial.println("normal temp");
Serial.println(sensorT);
digitalWrite(2, HIGH); // maintain bulb small bulb
digitalWrite(3, LOW); // two bulb
digitalWrite(8, LOW); // exhaust fan
digitalWrite(10, LOW); // pakanat fan
// break;
}

else if (sensorT > 37.5 && sensorT < 38)
{
Serial.println("higher 37.5 temp");
Serial.println(sensorT);
Serial.println(digitalRead(2));
digitalWrite(2, HIGH); // maintain bulb small bulb
digitalWrite(3, LOW); // two bulb
digitalWrite(8, HIGH); // exhaust fan
digitalWrite(10, LOW); // pakanat fan
}
else
{
Serial.println("higher 38 temp");
Serial.println(sensorT);
Serial.println(digitalRead(2));
digitalWrite(2, LOW); // maintain bulb small bulb
digitalWrite(3, LOW); // two bulb
digitalWrite(8, HIGH); // exhaust fan
digitalWrite(10, HIGH); // pakanat fan
}
delay(2000);
}

What happens if the sensorT is exactly 37.5?

what would be my problem?

What do the debug prints tell you?

kikiloaw:
what would be my problem?
i use power supply for arduino uno an 13.8 volts 3a.
since arduino has its own voltage regulator.

!!!!!

It's true the arduino has its own voltage regulator. It's also true that that regulator has a tiny little heatsink and you are making its life much harder than it needs to be.

since its 37.5 degree C (assuming) the 2nd condition is executed.,

Incorrect, look at your code again. What happens when the temp is exactly and equal to 37.5.

i just figure out my mistake in the condition,. here's what i made from a mistake :smiley:
if (sensorT <=36.9){
Serial.println("less than normal temp");
}
else if ((sensorT >36.9) && (sensorT <=37.5 ))
{
Serial.println("normal temp");
}

else if (sensorT > 37.5 && sensorT <=38)
{
Serial.println("higher 37.5 temp");
}
else
{
Serial.println("higher 38 temp");
}

}

Or you can really sit and think and knock off the unnecessary comparisons.

  if (sensorT < 37)  // gets everything less than 37, no need to check again for less than 37
  {
    Serial.println("less than normal temp");
  }
  else if (sensorT <=37.5 ) // now everything 37.5 or less is covered between the first 2 if()
  {
    Serial.println("normal temp");
  }
  else if (sensorT <= 38) // now 38 or less
  {
    Serial.println("higher 37.5 temp");
  }
  else
  {
    Serial.println("higher 38 temp");
  }

your really much a great help of me. thank you very much :smiley:

All these logic statements where execution can go one way or another are called 'conditionals'.

You can use if-else-if-else-if-else.... like a knife slicing away possibilities, ordered by the conditions you set. You can start at one end and proceed to the other or when it will speed the process, slice the middle and work from there.

When you arranging your logic, go back over your plans and question every bit, every step to take out what is not needed and try to see if different patterns with different steps would not fit better. You can draw or arrange coins or objects and move them around to test just the ideas how it would go, all the time using your knives of logic to slice the problem down to 'chewable' pieces.