How to control temperature

I made a egg incubator.I want to control temperature of that.It has 12v bulb.I want to turn off the bulb if temperature is higher than 39°C (102°F) And turn it back on if temperature is lower than 37°C (98°F). Can anyone tell me how I make this circuit and program my Arduino uno.

Start by searching for temperature control in the search box at the top of the page.

Weedpharma

#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A0;
int relay = 7;

void setup()
{
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
}

void loop()
{
  reading = analogRead(sensorPin);
  int celsius = reading / 2;

  Serial.print("temprature:"); Serial.println(celsius);
  if (celsius > 35)
  {
    digitalWrite(7, HIGH);
  } else
  {
    digitalWrite(7, LOW);
  }
  delay(500);

}

simple code here relay out can given to bulb through relay;
calibrate your temprature sensor based on used.

AMPS-N's division of the input by 2 implies a sensor like an LM35 at 5V.... and as he says you'll change that based on the sensor actually chosen.

I think something like a DHT22 might be called for, and even that's only good to 0.5 degrees.

@AMPS-N, stop trying to pick a fight with someone who [u]agrees[/u] with you.

(Sidetrack removed.)

AMPS-N: [code deleted]

simple code here relay out can given to bulb through relay; calibrate your temprature sensor based on used.

That will work pretty well as it is. The calibration bit is tricky.

I am working on a butter conditioner. It keeps the butter spreadable all year round. That needs to keep the temperature within one degree of the correct temperature, pretty easy without lots of controlling, but I was surprised how much the calibration changed when I disconnected the usb and tried to run from an external supply.

AREF had moved the equivalent of several degrees, and my calibration had gone out the window.

This issue crops up in the forum many times (and so I learned a lot). It seems that everyone expected the AREF voltage to be a voltage reference, and that caused my (and many other users') problem.

Keep it in mind when you design your controller and you will avoid the disappointment of a malfunctioning controller.

Pogo.

Can always add an external reference voltage, such as REF194 for a stable 4.5V reference powered by a varying Vusb. http://www.digikey.com/product-search/en?FV=fff40027%2Cfff8013f&k=ref194&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=25 Alternately, scale your incoming voltage down and use the Arduino's internal 1.1V bandgap reference.

Use a digital sensor like the DS18B20 it is the best under the cheap ones.

furthermore you need to handle hysteresis, that is switching the relay on/off should have different temperatures. Here some sample code base upon AMPS-N above.

const int sensorPin = A0;
const int relayPin = 7;
const int interval = 500;
const int uppertemp = 35;
const int lowertemp = 34;

void setup()
{
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);
}

void loop()
{
  int celsius = analogRead(sensorPin) / 2;

  Serial.print(millis());
  Serial.print("\t");
  Serial.println(celsius);
  if ((celsius > uppertemp) && (digitalRead(relayPin) == LOW))
  {
    digitalWrite(relayPin, HIGH);
    Serial.print(millis());
    Serial.print("\t");
    Serial.println("ON");
  }
  else if ((celsius < lowertemp) && (digitalRead(relayPin) == HIGH))
  {
    digitalWrite(relayPin, LOW);
    Serial.print(millis());
    Serial.print("\t");
    Serial.println("OFF");
  }
  delay(interval);
}