temperature controlled relay with LCD Printout

hi i am a beginner to arduino, i have built a circuit using:

1 x uno 3 arduino
1 x lcd screen
1 x potentiometer
1 x LM35
1 x Relay module Single channel
1 x RTC Module

my goal was to turn on and off my new vivarium lights one uv light on at 8am and off at 8pm and another light the basking light to be turned on at 8am with off pulses throughout the day to maintain a temperature within the viv. The basking light will also end programming and turn off at 8pm.

At present i have used one relay as mentioned this will control the basking light for now and i will add a second or dual relay later for the UV control

my problems are when i connect the relay to digital pin 9 for UV control it works fine as this is just using the time in the if statement but when i connect the relay to digital pin 1 the if statement is test the time and the temperature and it pulses and crashes the program

i have tried all different types of code from the internet and ardunio ide examples but can't seem to figure it out

i am wondering is my code wrong or do i need a pullup resistor on relay circuit if resistor needed where does it need to go

i have added a copy of my code in attachments and a paste of it here for someone to maybe see if i am going wrong

thanks
stu

#include <LiquidCrystal.h> //Library LCD
#include <LM35.h> //LM35 Temp sensor library
#include <Wire.h>
#include <DS1307.h>

LiquidCrystal lcd(2,3,4,5,6,7); //configuration pin Arduino to LCD
LM35 temp(A0);
DS1307 clock;//define a object of DS1307 class

void setup(){
Serial.begin(9600);
clock.begin();
clock.fillByYMD(2018,12,31);//Jan 19,2013
clock.fillByHMS(12,10,30);//15:28 30"
clock.fillDayOfWeek(MON);//Saturday
clock.setTime();//write time to the RTC chip
lcd.begin(16,2); //Initialize the LCD size used is the type of 16x2
lcd.setCursor(0,1); //Set the column and row
lcd.print("Temp:"); //Displays the value of the temperature
pinMode(1, OUTPUT);
pinMode(9, OUTPUT);
}

void loop (){
clock.getTime();
Serial.print(clock.hour, DEC);
Serial.print(":");
Serial.print(clock.minute, DEC);
Serial.print(":");
Serial.print(clock.second, DEC);
Serial.print(" ");
Serial.print(clock.month, DEC);
Serial.print("/");
Serial.print(clock.dayOfMonth, DEC);
Serial.print("/");
Serial.print(clock.year+2000, DEC);
Serial.print(" ");
switch (clock.dayOfWeek)// Friendly printout the weekday
{
case MON:
Serial.print("MON");
break;
case TUE:
Serial.print("TUE");
break;
case WED:
Serial.print("WED");
break;
case THU:
Serial.print("THU");
break;
case FRI:
Serial.print("FRI");
break;
case SAT:
Serial.print("SAT");
break;
case SUN:
Serial.print("SUN");
break;
}
Serial.println(" ");
Serial.println(temp.getTemp()); //Temp in celcius to pc

lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(clock.hour, DEC);
lcd.print(":");
lcd.print(clock.minute, DEC);

float temperature = temp.getTemp(); //store variable of temperature

lcd.setCursor(5, 1); //set column and row to start text
lcd.print(temperature); // output temp in celcius to lcd
lcd.print(" Celcius"); //print word celcius after temp numbers

delay(500); //Refresh readings from sensors

if (clock.hour >= 8)
{
digitalWrite(9,HIGH); //relay for uv tube
}
if (clock.hour >= 20)
{
digitalWrite(9,LOW); //relay for uv tube
}

if ( (clock.hour >= 8) && (temperature <= 28) ) //check time and temp
{
digitalWrite(1,HIGH); //relay for basking light
}

else
{
digitalWrite(1,LOW);
}

if (clock.hour >= 20)
{
digitalWrite(1,LOW); //relay for basking light
}

}

thermometer_new_with_library_lm35_and_time.ino (2.39 KB)

sorry i think i have posted this in wrong section can you please move to correct section

haha < = 8 ) turned into smileys with sun shades

stuy1982:
haha < = 8 ) turned into smileys with sun shades

That's the sort of thing that happens when you don't use code tags.

stuy1982:
but when i connect the relay to digital pin 1 the if statement is test the time and the temperature and it pulses and crashes the program

Pins 0 and 1 on the Uno are internally connected to the USB-Serial interface. You can't use them as general purpose pins if you're using Serial in your sketch.

Try a different pin for the basking light relay.

Also

  1. Learn about the forum's code tags - it stops those little 8) smilies appearing in your code.
  2. You say you're using relay modules - you need to check if these have built-in freewheel diodes (most of them do).

GypsumFantastic:
Pins 0 and 1 on the Uno are internally connected to the USB-Serial interface. You can't use them as general purpose pins if you're using Serial in your sketch.

Try a different pin for the basking light relay.

Also

  1. Learn about the forum's code tags - it stops those little 8) smilies appearing in your code.
  2. You say you're using relay modules - you need to check if these have built-in freewheel diodes (most of them do).

thanks for your response will try and look into everything mentioned

thanks again
stu