Can someone please help me improve this sketch?

Hello world, my first post here, total beginner in this : )

I have made this thermostat code, by cutting and pasting from all over… It reads a thermistor, can set desired temperature with a potentiometer and turn on/off a relay for the heater I use. In addition it has a light sensor, which is set to start a buzzer if I turn off the light in the room. This is because I don’t want to forget that it is on.

The code is probably very bloated, but it kinda works. I would, however, like to improve it by cleaning it up, making it better, more reliable and so on. I love to learn by watching how things can be improved.

So, anyone want to help make this a better sketch?

Thanks a million!!

PS: So sorry if I did this the wrong way, I have never posted in a forum before.

Thermostat_with_potentiometer_and_light_sensor_trigger.ino (2.6 KB)

go to the main forum listing. at the top of each forum, there is a how to use this forum. open that, click on the post, scroll down to .. 6 or 7... that will show you how to use a thing called a code tag. then post your code in a new post on this thread using code tags. also, if your sketch is huge, copy and paste it into a text file. raw text format post that file as an attachment.

for us to open your file, we have to create a new folder for it and that clutters our system. some of us will not do that.

A dose of auto-format wouldn't go amiss.

//  // wait 2 milliseconds before the next loop
  //  // for the analog-to-digital converter to settle
  //  // after the last reading:
  delay(500);

Comments that don't match code simply waste space and time.

 Serial.println(F("Super Awesome Temperature Controller 2000"));

Don't waste precious RAM

// print Celcius temp  with 1 decimal reading in serial monitor

Comments that misspell peoples' names are just irritating

    if (lightValue > 200) (13, LOW);Did we forget something here?

    tone(13, pitch, 300);

You gave pin 13 a nice name - why don't you use it?

const byte analogInPin  = A1;  
const byte digitalOutPin = 13; 
const byte RelayHOT     = 4;      
const int lightLow = 1023;
const int lightHigh = 0;

They don't change, so they should be constants.