Feedback!

DIY LED Clock

Views: 4313 Difficulty: 2 Status: Pipeline
Clcok_main

Build your own clock with the MCP79410 chip and 4 7-Segment LED modules.

Turn your Arduino into a clock! Keep track of the time and learn about electronics. We hook our real time clock breakout board up to our 4 x 7 Segment LED breakout board to make a fun, beginner friendly project. We use a real time clock chip with its own little lithium battery so that even when you power down the Arduino it continues to keep track of the time. The 4 x 7 Segment LED breakout board lets us display 4 decimal digits. We'll use two digits to display the hour, and two digits to display the minutes. To keep track of the seconds we blink the decimal point on and off. Each digit is controlled by a shift register. The shift registers are daisy-chained together so we can control them by using only 3 pins on the Arduino. This means we are controlling 28 LEDs (32 if you count the decimal points) with only 3 pins! Ah the magic of the Daisy Chain.
We also 3D printed a housing for our DIY clock with a cut out for LEDs and the clock chip. We designed the housing in Blender and printed it with an Afinia H-Series 3D printer. Check out our tutorial on 3D printing with blender to learn more.

Display the time in shining blue light!

Clock_reflection
Show the time with a 3D printed LED clock.

Clock Video

Watch the clock in super high speed!

Step-by-Step Instructions

Step 0 Tutorial Read ME

LUCID TRONIX LED CLOCK


https://www.lucidtronix.com/tutorials/52
Objective:

Provide the information to build a working clock that gets time from programming source and keeps it even when power is shut down. Displays time via four, 7-segment LED blocks, that use shift registers to multiply output from source to endpoint.


Skills Needed:

Soldering ability both for iron and hot air.
Arduino ISP programming knowledge.
Arduino code reading and debugging.
Lucid Tronix clock chip Tutorial.
Lucid Tronix shift register Tutorial

Skills Gained:

  • Surface mount soldering.
  • 7-segement LED connection.
  • Clock chip breakout usage.
  • Surface mount component intro


Required Resources :
  • Surface mount components.
  • Through hole components.
  • Soldering Iron and hot air gun.
  • Computer with Arduino programming Environment.
  • Arduino board with working input/output.
  • All relevant Tutorials.

Step 1 Fail Early Fail Often

STUB:: Always make sure to test your LED blocks early. Otherwise you might be surprised when you get to the end of your soldering and see that one block works but another doesn't and another displays random chaos.

Arduino Code for LED Clock

Here is the code for the DIY LED Arduino Clock. It is not a ton of code so we do it all in the main loop function but there are a few things worth mentioning. First to switch between a 24-hour clock and a 12-hour clock we check the hour returned by the RTC clock chip in this line:
  if (thehour > 12 ) thehour -= 12;
Comment this line out if you want a 24 hour clock. Next we have to separate the tens column from the ones column for both the minutes and the hours. We do this with the lines:
  int minute_tens = now.minute() / 10;
  int minute_ones = now.minute() % 10;
Here we are making use of integer division and the modulo operator. So, if now.minute() returns 57, with integer division 57 / 10 = 5 and 57 % 10 = 7 and these are the digits we will display on the seven segment LEDs. Lastly, in the video you can see the decimal point on one of the seven segment LEDs blinks every second. We do this with the following two lines of code:
  if (now.second()% 2 == 0) decimal_point_mask = 0b01111111;
  else decimal_point_mask = 0b11111111;
Depending on whether the current second is even or odd, we toggle the state of the first bit in the decimal_point_mask variable. All the rest of the bits in this variable are 1 so that when we AND it with the byte dec_digits[hour_ones] it doesn't change any of the bits controlling the segments of the seven segment LED it just turns the decimal point on or off.
  shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[hour_ones] & decimal_point_mask); 
This code uses the standard Arduino Wire library for I2C communication with the real time clock chip, as well as adafruit's fork of the RTCLib library. The wire library comes with Arduino, but you will need to download the RTClib by clicking the download as zip button on the github page, then unzip it and rename it and place it in your Arduino libraries folder.
/* LucidTronix
 * Daisy Chained Shift Registers
 * 74HC595 connected to 7-Segment LED display
 * with DS1307 Real time clock chip
 * Tutorial at:
 * http://www.lucidtronix.com/tutorials/52
 * September 2013
 */
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

int dataPin = 5;
int latchPin = 6;
int clockPin = 7;

byte dec_digits[] = {0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000011,0b11111000,0b10000000,0b10011000 };
byte decimal_point_mask = 0b01111111;

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop() {
  DateTime now = RTC.now();
  int thehour = now.hour();
  // switch between 24 hour clock and 12 hour clock
  if (thehour > 12 ) thehour -= 12;
  int hour_tens = thehour / 10;
  int hour_ones = thehour % 10;
  int minute_tens = now.minute() / 10;
  int minute_ones = now.minute() % 10;
  if (now.second()% 2 == 0) decimal_point_mask = 0b01111111;
  else decimal_point_mask = 0b11111111;
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[minute_ones]);
  shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[minute_tens]);
  shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[hour_ones] & decimal_point_mask); 
  shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[hour_tens]);
  //take the latch pin high so the LEDs will light up:
  digitalWrite(latchPin, HIGH);
  // pause before next value:
  delay(250);
}
Permalink: http://lucidtronix.com/tutorials/52
32 buttons for a fully-functioning hand-held USB keyboard....
Connect shift registers together to get more output and input pins from your microcontroller....
Shift Registers help you multiply your inputs and outputs....
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Wearable digital compass displays the direction in green LEDs....
Connecting the DS1307 real-time clock chip and our Heart Matrix you can show the time with love....
Display 4 digits using only 3 MCU wires with the 4 x 7 Segment LED and shift register breakout board....
Display numbers in big bright red LEDs use only 3 micro-controller pins and the 74HC595 shift registe...