Introduction: Clock, LCD Display, Infrared to Set

About: I have developed training courses for research companies during an interesting career. My computer book was published by Prentice Hall. Now, I'm sharing my hardware projects, some of which were aided by other …

Build a real time clock that keeps actuate time within a few minutes a year. The code and components can easily be repurposed into other projects.

This project requires a minimum amount of wiring and no soldering. The time keeper is a DS3231 real time clock. The time is displayed on an inexpensive 1602 LCD. Both modules use I2C communications. I2C only use 2 wires per module when connecting to an Arduino. I'm using an Arduino Nano because it fits nicely on a breadboard. The following instructions will work with an Arduino Uno as it has the same pin numbers as the Nano for this project. The other component is the infrared receiver. It allows you to use a common remote controller such as TV remote to set the time just like you would on our smart TV. The infrared receiver only requires one wire to connect it to the Arduino.

The first step is testing the Arduino and wiring it to the breadboard. The steps following that are designed to work independently. Each step has wiring instructions and testing instructions. When I build projects, I wire and test each component to confirm they are working. This helps integrating number of components because know that each work and I can focus on the integration requirements.

This Instructable requires that you have the Arduino IDE installed. You are also required to have the basic skills to download an Arduino sketch program from the links in this project, create a directory for the program (directory name same as the program name). The next steps are to load, view and edit the program in the IDE. Then, upload the program through a USB cable to your Arduino board.

Supplies

  • Nano V3 ATmega328P CH340G Micro controller board for Arduino. As an alternative, you can use an Uno.
  • DS3231 real time clock and a CR2032 battery.
  • 1602 LCD with an I2C module
  • Infrared receiver and remote control. I used an IR Wireless Remote Control Module Kits which came with an Infrared receiver and infrared remote control.
  • Breadboard
  • Wire cables
  • 5 volt wall adapter

I bought the parts on eBay, mostly from Hong Kong or China distributors. US distributors sometime have the same or similar parts for reasonable prices and faster delivery. The China parts take from 3 to 6 weeks to be delivered. The distributors I've used have all been reliable.

Approximate costs: Nano $3, DS3231 $1, LCD $3, Infrared kit $1, breadboard $2, package of 40 wire cables $1, $1 for a 5 volt wall adapter. Total, about $11. Note, I bought the Nano and LCD with the breadboard pins already soldered in place, as I my solder skills are poor. For the clock battery, I bought a 5 pack of lithium CR2032 batteries for about $1.25. I also bought a 5 pack of DS3231s because I like time pieces. This project uses 1 breadboard. I bought a 3 breadboard package for about $7; a better deal than buying an individual board.

    Step 1: Add the Arduino Nano to the Breadboard

    Plug the Arduino Nano into the Breadboard. Or, if you prefer, you can use an Arduino Uno for this project; they both use the same pins for this project. Connect the Nano (or Uno) to your computer via a USB cable.

    Connect power and ground from the Arduino to the breadboard's power bar. Connect the Arduino 5+ pin to the breadboard's positive bar. Connect the Arduino GRN (ground) pin to the breadboard's negative (ground) bar. This will be used by other components.

    Download and run the basic Arduino test program: arduinoTest.ino. When running the program, the onboard LED light will turn on for 1 second, then turn off for 1 second. Also, messages are posted which can be viewed in the Arduino IDE Tools/Serial Monitor.

    +++ Setup.
    + Initialized the on board LED digital pin for output. LED is off.
    ++ Go to loop.
    + Loop counter = 1
    + Loop counter = 2
    + Loop counter = 3
    ...

    As an exercise, change the time delay on the blinking light, upload the changed program, and confirm the change.

    In the above photo is a 140 piece solderless breadboard jumper wire kit box you can get for 3 to 5 dollars. They make boards neater that using long cables for short connections.

    Step 2: Add the DS3231 Clock Module and Connect It to the Arduino

    Plug the clock module into the breadboard. Connect the GND pin of the clock module, to the breadboard's ground bar strip. Connect the VCC pin of the clock module, to the breadboard's positive bar strip. Connect the clock module SDA (data) pin to the A4 pin of the Arduino(I2C data pin). Connect the clock module SCL (clock) pin to pin A5 of the Arduino(I2C clock pin).

    In the Arduino IDE, install a DS3231 Clock Library. Select Tools/Manage Libraries. Filter your search by typing in ‘rtclib’. Select RTClib by Adafruit (for reference, the library link).

    Download and run the basic test program: clockTest.ino. When running the program, clock time messages are posted which can be viewed in the Arduino IDE Tools/Serial Monitor.

    +++ Setup.
    + Clock set.
    ++ Go to loop.
    ----------------------------------------
    + Current Date & Time: 2020/3/22 (Sunday) 11:42:3
    + Current Date & Time: 2020/3/22 (Sunday) 11:42:4
    + Current Date & Time: 2020/3/22 (Sunday) 11:42:5
    ...

    As an exercise, use rtc.adjust() to set the clock's time and date, upload the changed program, and confirm the change.

    rtc.adjust(DateTime(2020, 3, 19, 10, 59, 50));	// First day of spring, 2020.

    Step 3: Add the 1602 LCD Display Module and Connect It to the Arduino

    Plug the LCD module into the breadboard. Connect the GND pin of the clock module, to the breadboard's ground bar strip. Connect the VCC pin of the clock module, to the breadboard's positive bar strip. Connect the clock module SDA (data) pin to the A4 pin of the Arduino(I2C data pin). Connect the clock module SCL (clock) pin to pin A5 of the Arduino(I2C clock pin).

    In the Arduino IDE, install a 1602 LCD Library. Select Tools/Manage Libraries. Filter your search by typing in ‘LiquidCrystal’. Select LiquidCrystal I2C by Frank de Barbander (for reference, the library link).

    Download and run the basic test program: lcd1602Test.ino. When running the program, clock time messages are posted which can be viewed in the Arduino IDE Tools/Serial Monitor.

    +++ Setup.
    + LCD ready to use.
    +++ Go to loop.
    + theCounter = 1
    + theCounter = 2
    + theCounter = 3
    ...
    

    As an exercise, change the LCD display messages, upload the changed program, and confirm the change.

    Step 4: Add the Infrared Receiver and Connect It to the Arduino

    Plug the female to male cable wires into the infrared receiver(female ends). Connect the ground pin of the clock module, to the breadboard's ground bar strip. Connect the power pin of the clock module, to the breadboard's positive bar strip. Connect the output pin of the infrared receiver, to the Arduino A1 pin.

    Connect infrared receiver, pins from top left to right:
        Left most (next to the X) - Nano pin A1
        Center - 5V
        Right  - ground
       A1 + -   - Nano pin connections
        | | |   - Infrared receiver pins
      ---------
      |S      |
      |       |
      |  ---  |
      |  | |  |
      |  ---  |
      |       |
      ---------

    In the Arduino IDE, install an infrared library. Select Tools/Manage Libraries. Filter your search by typing in ‘IRremote’. Select IRremote by Shirriff (for reference, the library link).

    Download and run the basic test program: infraredReceiverTest.ino. When running the program, point your remote control at the receiver and press various buttons such as the number from 0 to 9. Serial messages are output (printed) which can be viewed in the Arduino IDE Tools/Serial Monitor.

    +++ Setup.
    + Initialized the infrared receiver.
    ++ Go to loop.
    + Key OK - Toggle
    + Key > - next
    + Key < - previous
    + Key up
    + Key down
    + Key 1: 
    + Key 2: 
    + Key 3: 
    + Key 4: 
    + Key 6: 
    + Key 7: 
    + Key 8: 
    + Key 9: 
    + Key 0:
    + Key * (Return)
    + Key # (Exit)

    As an exercise, use a TV remote to see the values printed. You can then modify the program to use the values in the infraredSwitch() function's switch statement. For example, press the "0" key and get the value for your remote, for example, "0xE0E08877". Then, add a case into the switch statement as in the following code snippet.

        case 0xFF9867:
        case 0xE0E08877:
          Serial.print("+ Key 0:");
          Serial.println("");
          break;

    Step 5: Load the Clock Project Arduino Sketch Program and Test It

    Now that all the components are added to the breadboard, wired, and tested; it's time to load the main clock program and run it. The clock program gets the time from clock module, displays the time on the LCD, and allows you to set the time using an infrared remote control.

    Download and run the project's clock program: clockLcdSet.ino.

    When the program starts, it will display the DS3231's time on the 1602 LCD screen. Messages are viewable in the Arduino IDE Tools/Serial Monitor.

    +++ Setup.
    + LCD set.
    + syncCountWithClock, theCounterHours=13 theCounterMinutes=12 theCounterSeconds=13
    + Clock set and synched with program variables.
    + Infrared receiver enabled.
    ++ Go to loop.
    + clockPulseMinute(), theCounterMinutes= 15
    + clockPulseMinute(), theCounterMinutes= 16
    + clockPulseMinute(), theCounterMinutes= 17
    ...
    

    Point your remote control at the receiver and press the right arrow button. The year will be displayed for setting. Press the right arrow button a number of times to see that you can set the year, month, day, hour, minute, and seconds. To set a time value, go to the value. Use the up and down arrows to set the display value. Then use the "OK" key to set the clock's value. One value is set at a time.

    Step 6: External Power Supply

    Now that your clock is tested and working, you can unplug it from your computer and use an independent power supply. For simplicity, I use a 5 volt wall adapter, which can be bought for about a dollar, and a USB cable, another dollar. The cable connects the Arduino to the +5V wall adapter. Since the Arduino power and ground pins are connected to breadboard, that will power the other components.

    Because of it's simplicity and low cost, I use this same combination to power other projects.

    I hope you were successful and enjoyed building an infrared controlled LCD clock.