August 25, 2011

How long until Christmas?

I have kids. They have questions. One of their big questions, all year long it seems, is "How long until Christmas?" Here's one way to answer that question.


The circuit consists of three main elements: Arduino Pro Mini, DS3231 real-time clock (RTC) breakout board, and a standard 2x16 LCD. 

The Arduino Pro Mini takes power (raw) from the 9V battery through the toggle switch. The Vcc output  of the Arduino's regulator (5V) is used to drive the LCD and the clock. Here's the program on that Arduino. The program reads the time from the RTC, calculates the number of seconds between 'now' and a hard-coded 'targetDate', then from that time differential calculates and displays the number of days/hours/minutes/seconds remaining. It does this roughly 4x/second, which makes a nice ticking-second countdown. When the countdown reaches zero, it displays "Merry Christmas!" and goes to sleep.

The Arduino uses I2C to communicate with the RTC. I used a homemade DS3231 breakout board with a battery backup for my RTC, but one could use the more standard Sparkfun DS1307 breakout as well. In either case, my DS3231 library works fine. The code provided above does not set the clock: it assumes the clock has been set previously. I used the setClock.pde sketch from my DS3231 library to set the clock using the serial port, and no hardware changes are required to make that program set the clock on this circuit.

The LCD is a standard 2x16 LCD with the HD44780 driver, as shown here.

Nothing particularly fancy, but I just happened to have all the necessary parts sitting on my workbench anyway so I threw it together one evening. You can of course change the target date and message in the software so it works for any other event you might want. At this point in the semester, I'm leaning towards counting the seconds until the Physics 202B final...

3 comments:

  1. You need to change your surname to Falken and have a 20x4 LCD with stars going around the outside.

    "How about a nice game of chess?"

    ReplyDelete
  2. Hi awesome project, as I am completely new to arduino what would I need to change to use a DS3232 RTC and a LED DMD like this one http://www.freetronics.com/collections/display/products/dot-matrix-display-32x16-red#.UMbtW4OR-8A

    Cheers

    Chris

    ReplyDelete
    Replies
    1. I haven't used the DS3232 yet, but as far as I can tell the DS3231 library should work fine. No changes needed there.

      The display you link to uses a different control library than my LCD. There's a link on the freetronics website to some demo code: figure that out and then replace my display function calls with their equivalent.

      Delete