Go Down

Topic: How to control temperature  (Read 744 times) previous topic - next topic


Apr 10, 2015, 03:23 pm Last Edit: Apr 10, 2015, 06:00 pm by Isurindu
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.



Code: [Select]

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

void setup()
  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);


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.
meArm build blog:     http://jimbozamearm.blogspot.com/

Please don't PM for technical advice. Firstly my advice is sometimes wrong, and second, in the forum you get a broader, more timely, range of responses.

Coding Badly

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

(Sidetrack removed.)


[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.



Can always add an external reference voltage, such as REF194 for a stable 4.5V reference powered by a varying Vusb.
Alternately, scale your incoming voltage down and use the Arduino's internal 1.1V bandgap reference.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


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.

Code: (not tested) [Select]

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

void setup()
  pinMode(relayPin, OUTPUT);

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

  if ((celsius > uppertemp) && (digitalRead(relayPin) == LOW))
    digitalWrite(relayPin, HIGH);
  else if ((celsius < lowertemp) && (digitalRead(relayPin) == HIGH))
    digitalWrite(relayPin, LOW);
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131