Here I describe how to build the most basic (and probably the lowest cost as well) Arduino clock, using a real time clock (RTC) chip and a 1602 LCD display (2 lines of 16 characters). Unlike most of the LCD clocks out there (the only notable exception being Kevin Rye's LCD clock), this one is also encased and ready to be used in real life. Actually, the build starts with the enclosure (the very affordable adafruit LCD stand), which drives the requirements for the rest of the components.
Note: This LCD clock does not have any buttons. The time and date are set with the serial monitor (or Hyperterminal or any other serial console), by sending specific commands. I was thinking of adding the Bluetooth module, but then the process would be the same (or maybe even more complex, if you consider the pairing step), and it would only replace the PC with an Android phone or tablet.
Using serial monitor makes sense because the Pro Micro already has on-board USB interface, that is, one doesn't need the extra FTDI cable to communicate with the PC (also requiring attention to the connector's orientation when plugging it in).
List of materials
- LCD stand - from adafruit;
- 16x2 LCD - from various sources: adafruit, sparkfun, ebay;
- Pro Micro (sparkfun's original or clones from ebay) - board compatible with Arduino Leonardo, chosen because it is the only one fitting the LCD stand, both in size and the position of the USB connector;
- prototyping PCB - I used this, but many others can be found on ebay;
- 10k trimpot (for adjusting the contrast on LCD);
- DS1307 real time clock IC + 32kHz crystal - from ebay;
- CR1220 coin battery + battery holder - from ebay;
- two 10k resistors (pull ups for I2C lines);
- a bunch of wires;
- micro USB cable - from ebay;
- 16-pin male header and 16-pin female header - from ebay;
- USB power adapter.
Depending on the component sourcing, the cost for the whole project can vary between $20 (ebay) and $45 (adafruit, sparkfun).
Solder the 16-pin male header onto the LCD display.
Assemble the LCD stand including the LCD as well, selectively following the manufacturer's instructions.
Cut a piece of prototyping PCB to match the size of the LCD. This will be used as a "backpack" (plugged into the LCD) holding the Pro Micro board, the RTC and the battery.
Solder the female header onto the backpack in the appropriate position (so that it can be plugged into the LCD).
Solder the small Pro Micro board on the PCB so that the micro USB connector matches the side opening of the stand, also making sure that the micro USB cable can be plugged in through that opening.
Then wire the Pro Micro to the header of the LCD display, as follows:
- pin A1 of Pro Micro to pin 4 (RS) of LCD
- pin A0 of Pro Micro to pin 6 (EN) of LCD
- pin 16 of Pro Micro to pin 11 (D4) of LCD
- pin 10 of Pro Micro to pin 12 (D5) of LCD
- pin 15 of Pro Micro to pin 13 (D6) of LCD
- pin 14 of Pro Micro to pin 14 (D7) of LCD
- LCD's pins 1, 5 and 16 are wired to ground
- LCD's pin 2 is connected to Vcc (5V)
- LCD's pin 3 is connected to the 10k trimpot slider (middle pin), used for adjusting the contrast
- LCD's pin 15 (backlight LED) is connected to Pro Micro's pin 9.
Solder the RTC, battery holder and crystal, then connect the I2C lines (SDA and SCL) to the Pro Micro, according the the schematic below.
DS1307 talks to any microcontroller on I2C, through 2 wires named SDA and SCL. Unlike Arduino 2009 or UNO (with ATmega328) where SDA and SCL are on pins A4 and A5 respectively, Leonardo and Pro Micro (with ATmega32u4) use pins D2 and D3 as SDA and SCL.
We also need to pullup the I2C lines (SDA and SCL), by connecting D2 and D3 to Vcc through the 10k resistors. The final result is shown in the photo below.
I used the SMD version of DS1307, soldered on the PCB's plated side (see photo below). Also note the trimpot, soldered on the same side for accessibility.
Familiarize yourself with the Pro Micro (or the equivalent Arduino Leonardo). Read about how to install the board's driver, if this is the first time you use it.
Download the sample sketch, compile (in Arduino IDE 1.04 or later, after you made sure that "Arduino Leonardo" is selected as the current board), then upload.
Open the serial monitor and set the current time by sending the command TIME=hh:mm:ss, where hh is the actual hour and mm is the actual minute (e.g. TIME=08:25:00 or TIME=15:42:38).
As well, set the date by sending the command DATE=yy/mm/dd, e.g. DATE=14/04/03.
Disconnect the USB cable from the computer and power the clock from the USB power adapter.
The time and date are displayed as shown in the photo below.
- If the LCD does not show anything:
- adjust the trimpot for contrast;
- check the wiring, by making sure the connections are right, according to the list in step 5;
- check that there are no shorts between pins.
- If the date and/or time show 0:
- check that the DS1307 is connected correctly to pins D2 and D3 and to the rest of components, according to the schematic in step 6;
- check that the backup battery provides 3V and is inserted properly.