LM 35 scaling

Im trying to get my head around this scaling stuff.

I have an LM35 temp sensor and i want to control a fan with pwm.

Im trying to get the fan to come on at 15oC and be fully on at 30oC with with pwm scaled from 0-255within these values.

( 15oC = zero pwm - 30oC = 255 pwm)

Can anyone help me out here?

VR :-[

If you simply want a linear scale it's pretty easy. Just take your calculated degrees C subtract 15 and multiply by 17 to get the analog value to write to the pwm pin.

If your temp was 15:

(15 - 15) * 17 = 0

temp 25:

(25 - 15) * 17 = 170

temp 30;

(30 - 15) * 17 = 255

You'll need a transistor or other circuit to drive the fan off of the pwm pin.

Thanks for that ill give it a try and see what i can come up with. I already have the transistor circuit in place and it was just the code that i could'nt fathom. Ill let you know how it works out!

VR

I hope you'll report back!

Personally, I fear that your fan's response may be very non-linear.
Because the flow is turbulent, even rpm and the airflow aren't simply related.

Perhaps you could use a pot on an analog input (simply to provide a variable test input) and so test the fan drive (while observing the pwm setting via serial monitor). Depending on your fan and drive circuiry, you may well find it takes a value much larger than 1 to get the thing moving!

It does take a little to get the fan moving. Im having no luck working out diggers code at the mo.

Do you have any suggestions?

Can you post what you have? Yes, you may have to do some testing to find at what setting the fan begins to move and scale from there.

Ok this is what i have so far. I looked what values i was getting in serial monitor from my 'value' register and adjusted the code to suit.

So far its working ok but i now just need to work out what number in the 'value' register corresponds to the actual temp.

int value = 0;
int lm35pin = 2;
int fanpin = 6;

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

void loop()
{
int value = ( analogRead (lm35pin)-15) *17;

if (value < 500) analogWrite(fanpin, LOW);
if (value > 500) analogWrite(fanpin, 100);
if (value > 700) analogWrite(fanpin, 200);
if (value > 800) analogWrite(fanpin, 255);

Serial.print(value );
Serial.print(" ");

delay (500);

Oh also do you know why my fan squeels when its getting a pwm pulse but then runs quite when it full speed ( Ie: 255)??????

Its a standard 12VDC fan through a BC337 Transistor?????

set up like this:

https://web.archive.org/web/20210508004940/http://www.uchobby.com/index.php/2007/09/23/arduino-temperature-controlled-pc-fan/

But without the opto coupler.

Ahh, I thought you already had to code to convert to degree C. The equation I gave you assumes you were working with degrees C. I'll post up some code in a little bit that will get you going.

Im kinda new to this so ive been getting bits working one at a time. This bit is working great but now i have a major problem.

I have the code i just created above and altered the wording to fit into my main program for my project:

int HS_value = 0;
int HS_lm35pin = 2;
int HS_fanpin = 6;

void setup()
{
pinMode (HS_fanpin, OUTPUT);

}

void loop()
{
int HS_value = ( analogRead (HS_lm35pin)-15) *17;

if (HS_value < 500) analogWrite(HS_fanpin, LOW); // below 70oF
if (HS_value > 500) analogWrite(HS_fanpin, 50); // above 70oF
if (HS_value > 600) analogWrite(HS_fanpin, 100); // above 80oF
if (HS_value > 700) analogWrite(HS_fanpin, 150); // above 85oF
if (HS_value > 800) analogWrite(HS_fanpin, 200); // above 90oF
if (HS_value > 900) analogWrite(HS_fanpin, 255); // above 100oF

}

No When i try to copy and paste this code into my main project program it will not work. Ive treid several times and moved it to different places in the loop but still no joy. Im sure it has something to do with the brackets locations but i cant figure it out. If one of you guys could cast an eye over it and see if im just having a brain fart!!

Main Project Sketch:

see next post:

                                    // AQUATROLLER  //




 //***************************Arduino Initialisation***********************************
  #include <LiquidCrystal.h>
  #include "Wire.h"
  #define DS1307_I2C_ADDRESS 0x68
  #define led_white_pin        5                           // Output to white leds on pwm pin 5 
  #define alarmpin             4                           // Output to alarm circuit on digital pin 4
  #define led_actinic_pin      3                           // Output to actinic leds on pwm pin 3
  #define fuge_light_pin       2                           // Output to fuge light on digital pin 2
  
  LiquidCrystal lcd(11, 13, 12, 7, 8, 9, 10);

  int water_temp_sensor = 3;                               // Water Temp Sensor connects to Pin 2
  int water_temp_c = 0,water_temp_f = 0;                   // Water temperature variables
  int samples[8];                                          // Water temperature variables to make a better precision
  int maxi = -100,mini = 100;                              // Water integers to start max/min water temperature
  int i;     
    
  int ph_sensor = 4;                                       // Ph sensor connects to pin 4 
  
  
  int HS_value = 0;                                        // Lights Heat SInk Variable
  int HS_lm35pin = 2;                                      // Lights heat Sink Temp sensor on analog pin 2
  int HS_fanpin  = 6;                                      // Output to Heat Sink Fans on pwm pin 6
  
  
  int value1 = 0;
  int value2 = 0;
  int value3 = 255;
  int value4 = 255;
  
  long time1 = 0;
  long time2 = 0;
  long time3 = 0;
  long time4 = 0;
  
  unsigned long last_temperature_check_time = 0;           // Time Delay Routine Setup
  unsigned long last_lcd_turn_on_time = 0;                 // 


 //*************************RTC Intialisation*******************************************

  // 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) );
}



 // 1) Sets the date and time on the ds1307
 // 2) Starts the clock
 // 3) Sets hour mode to 24 hour clock
 // Assumes you're passing in valid numbers
void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second));                        // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));                          // If you want 12 hour am/pm you need to set
                                                       // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}

 // 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.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

 // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);       // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}



void setup() {
  {
 //*******************************Setup Routine of RTC*************************************
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();                                       // Starts 2 wire commuication with RTC module
  Serial.begin(9600);                                 // Starts Serial communication with PC
  pinMode (HS_fanpin,         OUTPUT);                // Sets digital pin 6 as an output pin          
  pinMode (led_white_pin,     OUTPUT);                // Sets digital pin 5 as an output pin
  pinMode (alarmpin,          OUTPUT);                // Sets digital pin 4 as an output pin
  pinMode (led_white_pin,     OUTPUT);                // Sets digital pin 5 as an output pin
  pinMode (led_actinic_pin,   OUTPUT);                // Sets digital pin 3 as an output pin
  pinMode (fuge_light_pin,    OUTPUT);                // Sets digital pin 2 as an output pin


  time1 = millis();
  time2 = millis();
  time3 = millis();
  time4 = millis();
  
 //***************************************************************************************** 
 //***************************SET TIME & DATE HERE****************************************** 

 // **********Change these values to what you want to set your clock************************
 // Remove (//) from front of..... setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); 
 // Then set the time and date and upload to Arduino,
 // Then place them back and save program
 
  second = 40;
  minute = 50;
  hour = 15;
  dayOfWeek = 2;
  dayOfMonth = 10;
  month = 2;
  year = 9;
  
   
 //setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); 
  
 //*****************************************************************************************
 //*****************************************************************************************
 

}
 }

void loop() {
  

  
  
  //*****************************Water Temp Time Delay Routine***************************************
  
  unsigned long time = millis(); 
  if (time - last_temperature_check_time > 5000)             // Has it been 5 seconds?
  {    last_temperature_check_time = time;
                 
  
  //************************Main Temp Read and Display Routine*********************************//
  
  
  

  
  
  lcd.clear();                                              // Clears LCD screen
  lcd.print("..AQUATROLLER..");                             // Displays AQAUTOLLER on top line
  lcd.setCursor(9,5);                                       // Positions cursor for TEMP: label
  lcd.print("TEMP:");                                       // Displays TEMP:
  lcd.setCursor(23,5);                                      // Positions cursor for degrees label
  lcd.print((char)223);                                     // Displays degrees symbol
  lcd.setCursor(24,5);                                      // Positions cursor of F label
  lcd.print("F");                                           // Displays F label
  lcd.setCursor(16,1);                                      // Positions cursor for Ph: label
  lcd.print("Ph:");                                         // Displays Ph: label
  lcd.setCursor(27,1);                                      // Positions cursor for Ph reading
  lcd.print("00");                                          // Displays Ph reading************** AJUST THIS PART FOR ACTUAL PH READIN WHEN SENSOR IS FITTED!!!!!!!!!!!!!!!
  lcd.setCursor(30,1);                                      // Positions cursor for ph reading label
  lcd.print("Ph");                                          // Displays ph reading label
 
  for(i = 0;i<=7;i++){                                      // Gets 8 samples of temperature

  samples[i] = ( 5.0 * analogRead(water_temp_sensor) * 100.0) / 1024.0;
  water_temp_c = water_temp_c + samples[i];


}

  water_temp_c = water_temp_c/8.0;                          // Better precision
  water_temp_f = (water_temp_c * 9)/ 5 + 32;                // Converts celcius to fahrenheit

  if(water_temp_f > maxi) {maxi = water_temp_f;}            // Set max temperature ( F )
  if(water_temp_f < mini) {mini = water_temp_f;}            // Set min temperature ( F )



  lcd.setCursor(19,5);                                      // Positions cursor to display WATER TEMP
  lcd.print(water_temp_f,DEC);                              // Sends farenheit temp to screen
  
  


  //*****************************Send Serial Temp Data to Computer**************************
  Serial.print(water_temp_c,DEC);
  Serial.print(" Celsius, ");

  Serial.print(water_temp_f,DEC);
  Serial.print(" fahrenheit -> ");

  Serial.print(maxi,DEC);
  Serial.print(" Max, ");
  Serial.print(mini,DEC);
  Serial.println(" Min ");

  water_temp_c = 0;
  
  

  }
  
  //**************************LCD Print Routine of RTC***************************************
  {
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
 
  {
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  lcd.setCursor(0,1);
  lcd.print(hour, DEC);
  lcd.print(":");
  lcd.print(minute, DEC);
  lcd.print("    ");
  lcd.print(month, DEC);
  lcd.print("/");
  lcd.print(dayOfMonth, DEC);
  lcd.print("/");
  lcd.print(year, DEC);
  }
  //********************************Sunrise & Sunset Times*********************************************
 
  //Actinics Sunrise begins at 7am and fades in every 6 minutes for an hour ( 10 steps ) until fully on
  
     if(millis()>time1)
  
  
   if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))analogWrite(led_actinic_pin, value1);           
   if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))time1 = millis()+360000;                                // Time delay between each pwm fade in pulse
   if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))value1+=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
   if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))if (value1>255)digitalWrite (led_actinic_pin, HIGH);  // Turn pin fully on once faded in
  
 
  
  //Whites Sunrise begins at 8am and fades out every 6 minutes for an hour ( 10 steps ) until fully off
  
     if(millis()>time2)
  
 
   if ((hour > 8 )&&( minute >1  )&&( minute  <=59 ))analogWrite(led_white_pin, value2);           
   if ((hour > 8 )&&( minute >1  )&&( minute <=59 ))time2 = millis()+360000;                                // Time delay between each pwm fade in pulse
   if ((hour > 8 )&&( minute >1  )&&( minute <=59 ))value2+=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
   if ((hour > 8 )&&( minute >1  )&&( minute <=59 ))if (value2>255)digitalWrite (led_white_pin, HIGH);    // Turn pin fully on once faded in
  
 
 
 //Whites Sunset begins at 10pm and fades out every 6 minutes for an hour ( 10 steps ) until fully off
 
    if(millis()>time3)
  
  
   if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))analogWrite(led_white_pin, value3);           
   if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))time3 = millis()+360000;                                 // Time delay between each pwm fade in pulse
   if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))value3-=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
   if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))if (value3<=0)digitalWrite (led_white_pin, LOW);      // Turn pin fully on once faded in
  
 

 
  //Actinic Sunset begins at 11pm and fades out every 6 minutes for an hour ( 10 steps ) until fully off
 
 
     if(millis()>time4)
  
  
   if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))analogWrite(led_actinic_pin, value4);           
   if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))time4 = millis()+360000;                                 // Time delay between each pwm fade in pulse
   if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))value4-=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
   if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))if (value4<=0)digitalWrite (led_actinic_pin, LOW);    // Turn pin fully on once faded in
  
 
  
  
  //Refugium light on/off times
  
   if ((hour > 7  )&&( minute >1  )) digitalWrite (fuge_light_pin, HIGH);
   if ((hour > 21 )&&( minute >1  )) digitalWrite (fuge_light_pin, LOW);
  
} 


//**************************Heat Sink Fan Control*************************************************


  int HS_value = ( analogRead (HS_lm35pin)-15) *17;


  if (HS_value < 500) analogWrite(HS_fanpin, LOW);     // Fans off below 70oF
  if (HS_value > 500) analogWrite(HS_fanpin, 50);      // Fans on 20% above 70oF
  if (HS_value > 600) analogWrite(HS_fanpin, 100);     // Fans on 40% above 80oF
  if (HS_value > 700) analogWrite(HS_fanpin, 150);     // Fans on 60% above 85oF
  if (HS_value > 800) analogWrite(HS_fanpin, 200);     // Fans on 80% above 90oF
  if (HS_value > 900) analogWrite(HS_fanpin, 255);     // Fans on 100% above 100oF



  
}

I had to use 2 windows as it was too big to fit in one. The sketch just carries on into the second post

Yeah, there were several extra!! I haven't tested this, but it compiles fine.

Part 1:

                                    // AQUATROLLER  //

 //***************************Arduino Initialisation***********************************
 #include <LiquidCrystal.h>
 #include "Wire.h"
 #define DS1307_I2C_ADDRESS 0x68
 #define led_white_pin        5                           // Output to white leds on pwm pin 5
 #define alarmpin             4                           // Output to alarm circuit on digital pin 4
 #define led_actinic_pin      3                           // Output to actinic leds on pwm pin 3
 #define fuge_light_pin       2                           // Output to fuge light on digital pin 2

 LiquidCrystal lcd(11, 13, 12, 7, 8, 9, 10);

 int water_temp_sensor = 3;                               // Water Temp Sensor connects to Pin 2
 int water_temp_c = 0,water_temp_f = 0;                   // Water temperature variables
 int samples[8];                                          // Water temperature variables to make a better precision
 int maxi = -100,mini = 100;                              // Water integers to start max/min water temperature
 int i;

 int ph_sensor = 4;                                       // Ph sensor connects to pin 4

 int HS_value = 0;                                        // Lights Heat SInk Variable
 int HS_lm35pin = 2;                                      // Lights heat Sink Temp sensor on analog pin 2
 int HS_fanpin  = 6;                                      // Output to Heat Sink Fans on pwm pin 6

 int value1 = 0;
 int value2 = 0;
 int value3 = 255;
 int value4 = 255;

 long time1 = 0;
 long time2 = 0;
 long time3 = 0;
 long time4 = 0;

 unsigned long last_temperature_check_time = 0;           // Time Delay Routine Setup
 unsigned long last_lcd_turn_on_time = 0;                 //

 //*************************RTC Intialisation*******************************************

  // 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) );
}

 // 1) Sets the date and time on the ds1307
 // 2) Starts the clock
 // 3) Sets hour mode to 24 hour clock
 // Assumes you're passing in valid numbers
void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second));                        // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));                          // If you want 12 hour am/pm you need to set
                                                       // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}

 // 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.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

 // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);       // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void setup()
{
  //*******************************Setup Routine of RTC*************************************
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();                                       // Starts 2 wire commuication with RTC module
  Serial.begin(9600);                                 // Starts Serial communication with PC
  pinMode (HS_fanpin,         OUTPUT);                // Sets digital pin 6 as an output pin
  pinMode (led_white_pin,     OUTPUT);                // Sets digital pin 5 as an output pin
  pinMode (alarmpin,          OUTPUT);                // Sets digital pin 4 as an output pin
  pinMode (led_white_pin,     OUTPUT);                // Sets digital pin 5 as an output pin
  pinMode (led_actinic_pin,   OUTPUT);                // Sets digital pin 3 as an output pin
  pinMode (fuge_light_pin,    OUTPUT);                // Sets digital pin 2 as an output pin


  time1 = millis();
  time2 = millis();
  time3 = millis();
  time4 = millis();

  //*****************************************************************************************
  //***************************SET TIME & DATE HERE******************************************
 
  // **********Change these values to what you want to set your clock************************
  // Remove (//) from front of..... setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  // Then set the time and date and upload to Arduino,
  // Then place them back and save program

  second = 40;
  minute = 50;
  hour = 15;
  dayOfWeek = 2;
  dayOfMonth = 10;
  month = 2;
  year = 9;

  //setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

  //*****************************************************************************************
  //*****************************************************************************************
}

void loop()
{

  //*****************************Water Temp Time Delay Routine***************************************

  unsigned long time = millis();
  if (time - last_temperature_check_time > 5000)             // Has it been 5 seconds?
  {
    last_temperature_check_time = time;

    //************************Main Temp Read and Display Routine*********************************//

    lcd.clear();                                              // Clears LCD screen
    lcd.print("..AQUATROLLER..");                             // Displays AQAUTOLLER on top line
    lcd.setCursor(9,5);                                       // Positions cursor for TEMP: label
    lcd.print("TEMP:");                                       // Displays TEMP:
    lcd.setCursor(23,5);                                      // Positions cursor for degrees label
    lcd.print((char)223);                                     // Displays degrees symbol
    lcd.setCursor(24,5);                                      // Positions cursor of F label
    lcd.print("F");                                           // Displays F label
    lcd.setCursor(16,1);                                      // Positions cursor for Ph: label
    lcd.print("Ph:");                                         // Displays Ph: label
    lcd.setCursor(27,1);                                      // Positions cursor for Ph reading
    lcd.print("00");                                          // Displays Ph reading************** AJUST THIS PART FOR ACTUAL PH READIN WHEN SENSOR IS FITTED!!!!!!!!!!!!!!!
    lcd.setCursor(30,1);                                      // Positions cursor for ph reading label
    lcd.print("Ph");                                          // Displays ph reading label

    for(i = 0;i<=7;i++)                                      // Gets 8 samples of temperature
    {
      samples[i] = ( 5.0 * analogRead(water_temp_sensor) * 100.0) / 1024.0;
      water_temp_c = water_temp_c + samples[i];
    }

    water_temp_c = water_temp_c/8.0;                          // Better precision
    water_temp_f = (water_temp_c * 9)/ 5 + 32;                // Converts celcius to fahrenheit

    if(water_temp_f > maxi) {maxi = water_temp_f;}            // Set max temperature ( F )
    if(water_temp_f < mini) {mini = water_temp_f;}            // Set min temperature ( F )

    lcd.setCursor(19,5);                                      // Positions cursor to display WATER TEMP
    lcd.print(water_temp_f,DEC);                              // Sends farenheit temp to screen

    //*****************************Send Serial Temp Data to Computer**************************
    Serial.print(water_temp_c,DEC);
    Serial.print(" Celsius, ");

    Serial.print(water_temp_f,DEC);
    Serial.print(" fahrenheit -> ");

    Serial.print(maxi,DEC);
    Serial.print(" Max, ");
    Serial.print(mini,DEC);
    Serial.println(" Min ");

    water_temp_c = 0;

  }

  //**************************LCD Print Routine of RTC***************************************
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  lcd.setCursor(0,1);
  lcd.print(hour, DEC);
  lcd.print(":");
  lcd.print(minute, DEC);
  lcd.print("    ");
  lcd.print(month, DEC);
  lcd.print("/");
  lcd.print(dayOfMonth, DEC);
  lcd.print("/");
  lcd.print(year, DEC);

Part 2:

 //********************************Sunrise & Sunset Times*********************************************

  //Actinics Sunrise begins at 7am and fades in every 6 minutes for an hour ( 10 steps ) until fully on

  if(millis()>time1)
  {
    if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))analogWrite(led_actinic_pin, value1);
    if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))time1 = millis()+360000;                                // Time delay between each pwm fade in pulse
    if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))value1+=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
    if ((hour > 7 )&&( minute >1  )&&( minute <=59 ))if (value1>255)digitalWrite (led_actinic_pin, HIGH);  // Turn pin fully on once faded in
  }

  //Whites Sunrise begins at 8am and fades out every 6 minutes for an hour ( 10 steps ) until fully off

  if(millis()>time2)
  {
    if ((hour > 8 )&&( minute >1  )&&( minute  <=59 ))analogWrite(led_white_pin, value2);
    if ((hour > 8 )&&( minute >1  )&&( minute <=59 ))time2 = millis()+360000;                                // Time delay between each pwm fade in pulse
    if ((hour > 8 )&&( minute >1  )&&( minute <=59 ))value2+=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
    if ((hour > 8 )&&( minute >1  )&&( minute <=59 ))if (value2>255)digitalWrite (led_white_pin, HIGH);    // Turn pin fully on once faded in
  }

   //Whites Sunset begins at 10pm and fades out every 6 minutes for an hour ( 10 steps ) until fully off

   if(millis()>time3)
   {
     if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))analogWrite(led_white_pin, value3);
     if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))time3 = millis()+360000;                                 // Time delay between each pwm fade in pulse
     if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))value3-=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
     if ((hour > 21 )&&( minute >1  )&&( minute <=59 ))if (value3<=0)digitalWrite (led_white_pin, LOW);      // Turn pin fully on once faded in
   }

  //Actinic Sunset begins at 11pm and fades out every 6 minutes for an hour ( 10 steps ) until fully off

  if(millis()>time4)
  {
    if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))analogWrite(led_actinic_pin, value4);
    if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))time4 = millis()+360000;                                 // Time delay between each pwm fade in pulse
    if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))value4-=25;                                           // Number of pulse counts from 0 to fully on ( 0,25,50,75,100 etc)
    if ((hour > 22 )&&( minute >2  )&&( minute <=59 ))if (value4<=0)digitalWrite (led_actinic_pin, LOW);    // Turn pin fully on once faded in
  }

  //Refugium light on/off times

   if ((hour > 7  )&&( minute >1  )) digitalWrite (fuge_light_pin, HIGH);
   if ((hour > 21 )&&( minute >1  )) digitalWrite (fuge_light_pin, LOW);

  //**************************Heat Sink Fan Control*************************************************

  int HS_value = 0;
  int values[8];
  for(i = 0;i<=7;i++)                                      // Gets 8 samples of temperature
  {
    values[i] = ( 5.0 * analogRead(HS_lm35pin) * 100.0) / 1024.0;
    HS_value = water_temp_c + values[i];
  }

  HS_value = HS_value/8.0;
  HS_value = (HS_value * 9)/ 5 + 32;
  
  if (HS_value < 70)
  {
    analogWrite(HS_fanpin, 0);
  }
  else if (HS_value > 100)
  {
    analogWrite(HS_fanpin, 255);
  }
  else
  {
    analogWrite(HS_fanpin, ((HS_value - 70) * 5) + 155);
  }
  
}

Hi Digger,

I uploaded it but still nothing happening on the fan.

Ive tried several different lines of code before i came on here. Compiling them was ok but like this one, it doen'st work.

Im really stumped!

Have you verified the LM35 that you have connected to Analog Pin 2 is working? You could add some debug serial prints to verify it is reading like you want it to.

Its working ok. If i put in the small code i posted a while back it works fine. Just whenever i transfer any of the code over it never works with the main program. This was edition no 3 to try and get the heat sink fans working but all seem to fail when i add it to the main program

:frowning:

Does the rest of your sketch seem to work ok when running the code I posted?

I will have to get back to you on that. the other day i shorted out my lcd by accident and i blew it. another is on its way so i cant test the rest fully. But it was all working fine before i blew it and started on the heat sink fan part of the project.