Author Topic: Need Help With Simple Temperature controller  (Read 2674 times)

MrCookie

  • Newbie
  • *
  • Posts: 21
Re: Need Help With Simple Temperature controller
« Reply #15 on: May 14, 2018, 03:17:43 am »
Code: [Select]
void setup()
{
  // Pin Assignments.
  pinMode(2, INPUT); //Analog input 1 for TMP36
  pinMode(0, OUTPUT);//Red LED
  pinMode(1, OUTPUT);//Relay to turn on Heater
  pinMode(3, OUTPUT);//Green LED
  pinMode(4, OUTPUT);//Yellow LED

  // Declare variables.
  int volts = 0;
  float Farenheit = 0;
}
 
void loop()
{
  volts= analogRead(1); //Read P2 voltage
 
  Farenheit = (((volts*5)/1024.0) - 0.5) * 100; //Convert voltage to centigrade.
  Farenheit = (Farenheit*9.0/5.0)+32.0; //Convert centigrade to farenheit.
 
  if (Farenheit >= 75)
  {
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);
  }
  else if (Farenheit < 75 && Farenheit > 68)
  {
    digitalWrite(4,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);
  }
  else if (Farenheit <= 68)
  {
    digitalWrite(0,HIGH);
    digitalWrite(1,HIGH);
    digitalWrite(4,LOW);
    digitalWrite(3,LOW);
  }
  delay(1000);
}
^^ Try that. I compared your code to this page I found on adafruit:
https://learn.adafruit.com/tmp36-temperature-sensor?view=all#using-a-temp-sensor
« Last Edit: May 14, 2018, 03:22:16 am by MrCookie »

NO2nice

  • Newbie
  • *
  • Posts: 10
Re: Need Help With Simple Temperature controller
« Reply #16 on: May 15, 2018, 10:22:57 am »
thanks- i guess i do have to assign the unused pins either LOW or HIGH when they are not used.


MrCookie

  • Newbie
  • *
  • Posts: 21
Re: Need Help With Simple Temperature controller
« Reply #17 on: May 20, 2018, 10:35:42 am »
Did it work? :o

NO2nice

  • Newbie
  • *
  • Posts: 10
Re: Need Help With Simple Temperature controller
« Reply #18 on: May 22, 2018, 06:01:18 am »
Yeah- i actually got it working and I managed to power everything off of the USB so now this little temp controller can be self contained with just the usb wall adapter.

thanks