Temp control project Help

So I'm pretty new to to this stuff but I'm enjoying it.
This is my first project sort of, Its my first multi project.
What I am wanting to accomplish is to have 2 different temp sensors,one inside and one outside (of a room)
a fan, a servo to open a air door when fan comes on, and a LCD to display temp inside and out.

So what i am not sure of is how to add the second temp sensor so that when the outside is cooler than inside the fan comes on.

Also i would like it so that the fan comes on at a linear rate as the temp goes up (or down).
I would like both temps on the LCD (which is 16,2)

I hope I'm making sense here.

The code that I have so far may or may be the correct way to do it but so far it works (with just one sensor), Its made up of some copying of example codes and some of just trying to figure things out on my own..lol

Chris

analogtemplcdfanservo.ino (2.66 KB)

So what i am not sure of is how to add the second temp sensor so that when the outside is cooler than inside the fan comes on.

You've got the sequence of events wrong. You add another sensor just like the first one, but using a different pin or a different address on the bus, depending on the type of sensor. You read the second sensor just like the first one, except for the different pin or address. Then, you make decisions based on what you read from the two sensors.

for linear control you could use the map function: example : output = map ( tempcelsius , 80 , 90 , 1000 , 1100);
this will map values 80 - 90 to 1000 - 1100 so for 85 you get 1050. It also maps values outside 80 - 90 range so you might need to limit the input or output or else the servo values will be out of range.

Towards the top of your code you have the line

#define tempSensor 0 // Define the A0 pin as “sensor”

What this line does, is allow you to use the expression "tempSensor" instead of '0' within your code. But since you never refer to "tempSensor" again, this line is totally redundant. (it could be deleted without changing a thing)

The line of code that is actually reading the temperature is

TC=(int(Thermister(analogRead(0))));

To read from a second sensor, you would simply call the same function but with a different pin number (for example 1 instead of 0)

To make it easier for you to keep track of which probe is where you could create TWO define lines at the top of your code, then within the loop function call each one by name.
Something like

#define outdoorSensor 0 // Define "outdoorSensor" to mean 0
#define indoorSensor 1 // Define the "indoorSensor" to mean 1

blah
blah
blah

void loop()
float indoorTempC; // Variable receives the converted  ºCtemperature from indoor sensor
float outdoorTempC; // Variable receives the converted  ºCtemperature from indoor sensor

IndoorTempC=(int(Thermister(analogRead(indoorSensor))));
outdoorTempC=(int(Thermister(analogRead(outdoorSensor))));

blah
blah
blah

Thank you guys for helping me understand this stuff theres soo much to learn.

So,just so i can understand ,

I have two sensors indoor ,outdoor.
I want to compare the two and if indoor < outdoor I want a fan to come on (but not just full speed I would like it to be variable)
How do I compare the two and then get the fan?

Is the (if) statement used here , like if (indoor<outdoor)
I am controlling my speed control by servo2 servo2.write(map(what goes here?

Am I at least thinking the right way here?

I have changed the code to use the map function with one sensor past a certain temp and it works (horay) now add more stuff.

chris

Hi Chris,
A thermiser is not a very good temp sensor, use the DS18b20 you can use 2 or more on the same WIRE line, no problem.
Here's the code for my propagator system, this checks the light level (What's the point in keeping plants warm in the dark?) and adjust the target temp, this temp is then maintained via relay etc.

Just might give you an idea or two, regards. I have a schematic if needed.

Mel.

#include <FastIO.h>
#include <I2CIO.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
 
// DS18b20 Data line is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
 
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire); 
/*
Connections:
Heater1 pin 3
Heater2 pin 4
SDA to Arduino Analog pin 4
SCL to Arduino Analog pin 5
LightPin Analog pin A7
TempPin pin 12
*/

#define DS1307_I2C_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);  // Set the LCD I2C address 

//*****constants*****
int Light,LightPin=A7,TargetTemp,Heater1=3,Heater2=4,TempPin=12;
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
float TEMP;
void setup()
//----------------Start of Set up---------------------
{
TargetTemp=23;  //Set Normal/Target temp to 23c
pinMode(Heater1,OUTPUT);
pinMode(Heater2,OUTPUT);
pinMode(13,OUTPUT);
Wire.begin();
lcd.begin(20,4); // tells Arduino the LCD dimensions
// start serial port
Serial.begin(9600);
//Serial.println("Dallas Temperature IC Control Library Demo"); 
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
//------------End of Setup loop------------------------
//--------------Start of Main loop------------------
void loop()  
{
  GetTime();
  GetTemp();
  TestIt();
  digitalWrite(13,HIGH);    //Flash LED
  delay(100);               //For 100mS
  digitalWrite(13,LOW);     //LED off
}
//------------End of main loop-----------------------------
void GetTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
//if (second <=5)
{
//lcd.clear(); // clear LCD screen
lcd.setCursor(0,0);
lcd.print(" ");
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.print(" ");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print("20");
lcd.print(year, DEC);
//delay(1000);
}
}
//------------------------------------------------------------------------------------------
void GetTemp()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
TEMP=(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
}
//-----------------------------------------------------------------------------------------------------------
void TestIt()
 {
  Light=analogRead(LightPin);
  Light=Light/4;
  if(Light>200)
  {TargetTemp=25;}
  if(Light>160 && Light<200)
  {TargetTemp=18;}
  if(Light<160)
  {TargetTemp=14;}
// Set Temp******
 
   lcd.setCursor(1,1);
   lcd.print("Target Temp:");
   lcd.print(TargetTemp);
   lcd.print(".00c ");
   lcd.setCursor(1,2);
   lcd.print("Current Temp:");
   lcd.print(TEMP); 
   lcd.print("c ");
   
   if (TEMP < TargetTemp)
  {
   digitalWrite(Heater1,LOW);    //Heater ON
   digitalWrite(Heater2,LOW);
   lcd.setCursor(1,3);
   lcd.print("Heater ON ");
   lcd.print("Lite=");
   lcd.print(Light);
   lcd.print("  ");
  }
  if (TEMP > TargetTemp)
  {
    digitalWrite(Heater1,HIGH);
   digitalWrite(Heater2,HIGH);  //Heater OFF
   lcd.setCursor(1,3);
   lcd.print("Heater OFF ");
   lcd.print("Lite=");
   lcd.print(Light);
   lcd.print("  ");
 //lcd.clear();
}
}
//*************************************************************************************************************

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
//-----------------------------------------------------------------
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
//------------------------------------------------------------------
// Gets the date and time from the ds1307
void getDateDs1307
(
byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read() &0x07);
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
//==================================================================================

I will eventually change and do one wire temps eventually, But for now or at least until i understand what I'm doing I am trying to keep it simple.

I do appreciate the replies,That's how one learns right.

chris