Arduino Programable Thermostat


Introduction: Arduino Programable Thermostat

About: EE Educator, Pink Floyd fan, father, human,from Earth

This project uses an Arduino Nano, a RTC, a rotary encoder, a Nokia 5110 display and a relay. It allows manual and programmed setting of temperature, and furnace control.

You can see a video of the system, a breakdown of the code, and how I put it together here: Arduino Programmable Thermostat

Step 1: The Real Time Clock

The DS3231 RTC is an I2C device. So in addition to needing +5V and ground, it has a clock pin (SCK) that connects to A5 and a data pin (SDA) that connects to A4.

The clock is set in the setup() function the first time you run the program with the following code:








Make sure to comment them out and reset the Arduino after setting the clock.

Step 2: The Relay

The relay's + pin is connected to +5V, the - pin goes to ground. The "S" pin (signal) goes to digital 6 on the Arduino. The furnace control wires are connected between the normally open (NO) and common posts on the relay. The relay used here is a Songle 30VDC10A.

Step 3: The Display

We are using a Nokia 5110 display in this project. It uses the Adafruit PCD8544 library. The 5110 is a 3.3V device with 5V tolerant signal pins. So the Vcc must connect to the Nano's 3.3V pin, the ground of course, goes to ground. Also note that the LED pin goes to 3.3V. The signal pins connect as follows:

pin 7 - Serial clock out (SCLK)

pin 6 - Serial data out (DIN)

pin 5 - Data/Command select (D/C)

pin 4 - LCD chip select (CS)

pin 3 - LCD reset (RST)

Step 4: The Rotary Encoder

The rotary encoder is user front end to this system. The rotation function is used to adjust both time and temperature. The clickable button is used to select modes, toggle between features, and make selections. It connects as follows:

Arduino pin 8 - Rot Enc switch

Arduino pin 9 - Rot Enc Clock

Arduino pin 10 - Rot Enc data

Step 5: Modes

The system has two basic modes of operation:

Manual and Program

In the manual mode, turning the rotary encoder clockwise will increase the temperature. Counter-clockwise with decrease the temperature. Finally clicking the switch will send the system to the program menu.

In the program menu, clicking the switch will move the cursor to each selection: hour, minute, temperature. When the cursor is under one of the selections, turning the knob will adjust that selection. Clicking again will move the cursor to the next selection. When all adjustments have been made, a final click will activate the Program Mode.

In program mode, the system will change to the programmed temperature at the time selected.

Step 6: The Code

My code is available to download here:



    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Clocks Contest

      Clocks Contest

    12 Discussions

    Hi, just the project I was looking for, I have probably missed something, but I can't see where the actual room temperature is being sensed, where is the temperature sensor IC. Thank you.

    Can you say what library do you use for rtc?

    Nice project want to build one but would be nice to get the exact part numbers for the relay and rotary encoder. The relay is on a PCB but could not find it. All rotary encoders are not the same so part number is needed.


    1 year ago

    any plans for a cooling cycle option?

    1 reply

    Hi, the code to download link seems to does'nt work

    Hi, very good project. I was just wondering about the accuracy of your thermostat. Including a PID mode would make it totally professional, I think there's an Arduino library for that. Keep up!


    1 year ago

    the real time clock is a little useless and expensive, you can use the fonction millis() in your code.
    however it's a nice project :p

    Muy interesante tu trabajo. Felicitaciones.

    Good instructable :) I wish our thermostat was more reliable. It tends to overshoot the set temperature.

    1 reply

    Swansong, I believe that most commercial thermostats have +/- 2 deg dead zone to keep them from switching on and off all the time. Thanks for your kinds words.

    Cool project!