Introduction: Arduino Time & Temp Display Shield

Another project I'm working on required a good timer, but the more I read about Arduino, I realized that I couldn't make an accurate timer using an Arduino that was already devoted to other tasks. The Arduino will always lose time if you perform other tasks. The solution was a Real Time Clock module that keeps perfect time and has a battery backup so it won't reset if the Arduino loses power.

I like to make things modular, so I decided to combine the Real Time Clock module, an LCD screen, and a few thermistors together on one shield to make a sort of all in one "Atomic clock"/Weather station shield.

Step 1: Parts & Materials

I started with an official Arduino protoboard as a base. On other projects, I have tried to use the perf boards you find at Radio Shack and other electronics stores to make shields, but its nearly impossible to solder on the back side of those boards. For some reason, its very expensive to get protoboards that are through-hole plated unless they are about an inch across. These blank protoshields are the easiest way to make a shield if you need to solder on both sides. They also have bus lines for 5v and ground built right in that are already tied to the correct header pins. There is also a spot for a tactile switch that is tied to the reset pin and there is a spot for a surface mount chip.

Arduino Protoshield or Mega Protoshield
LCD
RTC module
Right angle headers
Straight headers
Female headers
Thermistor
Epoxy Covered Thermistor
10k Ω Resistors
Speaker or Buzzer (I grabbed this one out of an old PC)
Wire (I use single stranded cat5 cable that I untwist and separate)
Sugru or hot glue

Step 2: Mocking Up

I propped up the RTC and LCD modules to see how they would fit on the finished shield. The screen is nice and large, but it is only supported by the header pins coming out of the top left corner. I will show how I support the rest of the device a little later.

Step 3: LCD and RTC

LCD
I buy these female header pins in strips of 40 and cut them down as needed. I use an X-acto knife to score the plastic over the hollow of one of the header slots. I flip the headers over and score the other side the hold the set tightly with pliers while I snap it along the score. The little metal fork that makes up the internal and external contact then falls out and I clean up the edge with the X-acto knife.

I made one set of female pins for the 16 pin connector coming from the LCD screen and another with 5 pins so I can plug the RTC module into it.

I made another set of female pins with some scrap pieces I had laying around. This set is just to give the screen something to rest on and take a little strain off the male and female header pin connections. I soldered the female pins to the board, stuck some male headers into them and trimmed off the excess metal. I then covered the tops with some Sugru I had laying around. The Sugru makes the LCD board tilt up a little bit, so it is now a pretty snug fit and keeps everything from moving around.

For this LCD, I had to connect pins 1, 5, and 16 to ground and pins 2 and 15 to 5v. I then connected pins 4, 6, 11, 12, 13, and 14 on the LCD to Arduino's pins 7, 8, 9, 10, 11, and 12 respectively. You also have to connect the trim pot to 5v, ground and pin 3 on the LCD. For better instructions go here.

RTC
The RTC was much easier to connect. I soldered the 5 pin female header to the short bars next to the power and ground buses. The pins on the RTC module are labeled, so I just connected GND to ground, 5v to 5v, and SDA and SCL to Arduino's A4 and A5 respectively.

Step 4: Other Bits

Thermistors
After the big pieces were arranged, I added 2 right angle headers to the edge of the board to connect my epoxy coated thermistors. I intentionally mounted them close to the bus bars on the left side of the board so I could easily connect them to 5v and to ground with a pull down resistor. I then ran wires to the analog in pins so I could read the temperatures. I added another thermistor on the other side of the board, but not one of the epoxy coated ones. This one I just soldered to the board and ran wires to 5v and ground with a pull down resistor. Now I have 1 internal and 2 satellite temperature sensors that I can attach to computer parts or string feed them out a window to get the outdoor temperature.

Speaker
I still had some extra space under the LCD screen so I thought, if this is going to be used as a clock, why not have an alarm as well? I had an old PC speaker that I salvaged from an old computer, so I added some more right-angle headers and wired the speaker to ground and one of the PWM pins. At first I used the last unused PWM pin, 13 to keep the used pins together (7,8,9,10,11,12) but I don't recommend that. When the Arduino boots up it flashes the LED attached to pin 13 which makes a popping sound from the speaker.

Step 5: Code

Here are some tutorials for writing code for this LCD screen and RTC module.

And here is my sample code that reads the 3 thermistors, the date and time from the RTC module and displays them on the LCD screen. There are a few functions at the bottom that help everything display the way I wanted (padding the time to 2 digits and converting the midnight hour to 12 from 0). There is a video on the next page that shows how everything displays on the screen.


#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"
#include <math.h>

RTC_DS1307 rtc;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


// make some custom characters:
byte fan1[8] = { B00000, B01100, B01011, B10101, B11010, B00110, B00000, B00000 };
byte fan2[8] = { B00000, B00110, B11010, B10101, B01011, B01100, B00000, B00000 };
byte fan3[8] = { B00000, B11011, B11011, B00100, B11011, B11011, B00000, B00000 };

int icon = 1;
int delayTime = 100;

void setup() {
  Serial.begin(57600);

  // create a new character
  lcd.createChar(1, fan1);
  lcd.createChar(2, fan2);
  lcd.createChar(3, fan3);

  // set up the LCD's number of columns and rows:
  lcd.begin(20,4);


#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  rtc.begin();

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__));
  } 
}

void loop() {
  //Format the Date...
  DateTime now = rtc.now();

  //Read the Temperatures...
  lcd.setCursor(0, 0);
  lcd.print("Temp.");   

  lcd.setCursor(0, 1);
  lcd.print("1:"); 
  lcd.print(int(Thermister(analogRead(0))));
  lcd.print((char)223);
  lcd.print('F'); 

  lcd.setCursor(0, 2);
  lcd.print("2:");
  lcd.print(int(Thermister(analogRead(1))));
  lcd.print((char)223);
  lcd.print('F'); 

  lcd.setCursor(0, 3);
  lcd.print("3:");
  lcd.print(int(Thermister(analogRead(2))));
  lcd.print((char)223);
  lcd.print('F');

  lcd.setCursor(8, 0); 
  lcd.print(now.month(), DEC);
  lcd.print('/');
  lcd.print(now.day(), DEC);
  lcd.print('/');
  lcd.print(now.year(), DEC);

  //Hours
  lcd.setCursor(8, 1);
  lcd.print(Pad(ClockHours(now.hour())));
  //Minutes
  lcd.setCursor(10, 1);
  lcd.print(':');
  lcd.setCursor(11, 1);
  lcd.print(Pad(now.minute()));
  //Seconds
  lcd.setCursor(13, 1);
  lcd.print(':');
  lcd.setCursor(14, 1);
  lcd.print(Pad(now.second()));


  FanSpinFn();

  delay(delayTime);
}

double Thermister(int RawADC) {
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  return Temp;
}

void FanSpinFn(){
  lcd.setCursor(19, 3);
  lcd.write(icon);
  if (icon < 3) { icon++;}
  else {icon = 1;} 
}

String Pad(int Time_Segment){ 
  if (Time_Segment < 10){ return "0" + String(Time_Segment, DEC); }
  else { return  String(Time_Segment, DEC); } 
}

int ClockHours(int Hours){
  if (Hours < 1) { return 12; }
  else { return Hours; } 
}

Step 6: Finished

Everything turned out great and it's a good base to tinker with and see what else I can come up with.

Here are some ideas I have had of how to use this new shield:
  • Weather Station - Use the 1 on board thermistor and the 2 remote thermistors to monitor temperatures inside and outside of the house.
  • Alarm Clock - Alarm clocks are pretty easy to come by, but its always fun to make something yourself.
  • Animated Music Box - This will probably be an Instructable in the future.
  • Timer/Display for other projects - This is the actual reason for making this shield, but by making my commonly used parts into reusable modules, I hope to simplify future projects.
  • Fish Tank/Hydroponic Controller - You would need more components on another shield, but the timer, display and 3 temperature sensors would be very helpful in a number of applications.
  • Temperature Logger - I saw a food safety temperature log on a clipboard on one of the refrigerators in the cafeteria at work and I thought, there has to be a better way to do this.

Make It Glow Contest

Participated in the
Make It Glow Contest

Hardware Hacking

Participated in the
Hardware Hacking

Supercharged Contest

Participated in the
Supercharged Contest