Arduino 7-segment RTC After making so many Arduino prototypes on a breadboard, I decide to make something useful that everyone in the house can use. What is more useful that a digital clock as the year 2010 is coming to an end. I starter doing my research on making a digital clock and gathering the components needed to make one. One of the criteria is that all the components must be easily available locally in Kuala Lumpur, Malaysia. Visually, it looks like those countdown timer bomb found on old movies where the hero needs to cut some wires to deactivate the bomb. In order to make a clock to tell the time, I have a few options, either set the time in Arduino, keep the Arduino power on all the time but this method is not very feasible as I would need to set the time everytime I need to power cycle the Arduino. The second option was an idea of a hugh 7-segments LED powered by a GPS from Sparkfun article. As GPS give a very accurate time, this option should good and I do not need to set the clock everyime it was powered on. I took out my Garmin GPS60C, plug in the serial connection to the Arduino, load a few GPS libraries and I got myself a very accurate time. The problem with this method is that since I live in the middle of Kuala Lumpur, a concrete jungle with condominium surrounding my condominium unit, I need to put an external GPS antenna outside my windows to receive GPS signal directly from the sky. Without a satellite lock, the GPS unit was not able to receive any satellite signals from the key. And the clock either need to be close to the window or I had to run GPS antenna to the place I put my 7-segments digital clock. The third method is the best, running Arduino with a DS1307 realtime clock (RTC) powered by a 3V coin size battery that can keep the time when it is powered off or during power cycle. I went to the local electronic heaven called Jalan Pasar (market street in english), located in a very congested part of town and try my luck to find the necessary components. To my surprise, I found all the necessary parts to built this digital clock. The main components are :- - Arduino board - Four red 7-segments LED ( could not find other cool colour locally ) - DS1307 realtime clock - 32.768 kHz crystals - coin size battery holder - Four shift registers 74HC595 to control the 7-segment LEDS - resistors and hookups cables - header pins and integrated circuit/chip (IC) sockets As I have not acquired the skills to make a printed circuit board (PCB) yet, I decide to use a veroboard ( board with holes to make the components permanent also called a doughnut board ) and solder all the header pins and IC sockets. All the 7-segments LEDs and IC can be easily replaced with this method. As the board size is quite limited, I can only fit four 35mm size 7-segments LED and have enough space for a battery holder. I wanted to get a much bigger 7-segments LED but the bigger ones would requires higher voltage above the 5V and my circuit would need to support dual power rails. I did not want to deal with a dual voltage power regulator circuit at the moment and focus on making my first digital clock. Uploading sketch on digital clock This Arduino digital clock only uses 5 pins, 3 digital pins for the 74595 shift registers and 2 analog pins for the RTC using I2C connection. What is different between my Arduino Digital Clock vs the commercial digital clock is that I can control the behavior of the clock and can easily add any functions I see fit. Some ideas are like alternating display between hours/minute and minute/seconds, playing a tune every 1 hour, add in a LM35 to double as a thermometer, sound an alarm in the morning or even control other electrical appliance via a solid-state relay based on time related events or readings from other sensors. As the four digit are quite big and bright, I can use it to display other information too. I discovered the first issue after I soldered the first digit from the 74595 shift registers to the common cathode 7-segments LEDs. I only use one 220 ohm resistor connected to the common cathode to save the number of resistors needed and found that the number 8, all segments turn on was very dim. This is okay for a prototype but this is not acceptable for a real useful digital clock. Would be very annoying to have different digits with different brightness. So I remove all the wires and went out to get a lot of 220 ohm resistors to connect them to each of the seven segments. 7-segment with 74595 shift registers The second issue I found was that I forgot to allocate space for two 5mm LEDs as the colon to blink as a second indicator after I soldered the third digit. As it is quite a lot of work just to make one digit with all the soldering, joining the resistors to the wires, I decide to do away with the 2 colon dots between the hour and the minute digits. I will find a way to install a LED or two as second indicators. The photo in the current photo, I just blink LED on pin 13 for 500 ms delays. Here are some photos of the finished working product, now I just need to some some acrylic to mount the board and hide the Arduino board behind the digital clock. The codes are based on Paul's Electronics 7-segment shift register. Arduino clock with blue LED second indicator Arduino clock without 7-Seg LEDs Back of clock with perfboarduino This Arduino clock is powered by a perfboard version of Arduino with FTDI header and DC plug. Arduino clock with DHT11 sensor Complete Arduino clock with DHT11 Humidity and Temp sensors. The full sketch are located at https://github.com/stanleyseow/Arduino-realtime-clock-with-four-7-segment-LED-and-74595-shift-registers
For a good clock must use a RTC (real-time clock) like DS1307. For Arduino enthusiasts and hobbylist exists some RTC module with DS1307, but you can made yourself a good RTC module like me. Original schematic is from DS1307 datasheet, but I redesigned schematic using freeversion of Eagle PCB Software: Note: Battery is CR2032, like in schematic... in boards is a little error A full schematic for RTC clock with Arduino is: Compared to other schematics that can adjust time (reset clock at 0:00, adjust hours and minutes). Original schematic, design and sketch is from article Using Arduino with a DS1307 Real Time Clock by Lewis Loflin. If you want to change time, must push and hold S3 (adjust) switch and display is change on 0:00, then push S1 (hour) or S2 (minute) repeatedly until time is ok, after this realise S3, and time is put in RTC. I use a multiplexed 4-digit 7-segment display with common anode same in article named Arduino UNO running 4-digit 7-segment display from http://www.hobbytronics.co.uk/. Is a unusual schematic, but works fine; a usual schematic use resistors for current limit. My sketch is: /* 4 digit 7 segment display: http://www.sparkfun.com/products/9483 Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf 7 segments + 4 digits + 1 colon = 12 pins required for full control */ // modified connexion by niq_ro from http://nicuflorica.blogspot.com // for my Luckylight KW4-563ASA // dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf int digit1 = 11; //PWM Display pin 12 (digit1 is common anonds A1 from right side) int digit2 = 10; //PWM Display pin 9 (digit2 is common A2) int digit3 = 9; //PWM Display pin 8 (digit3 is common anods A3) int digit4 = 6; //PWM Display pin 6 (digit4 is common anods, from left side) //Pin mapping from Arduino to the ATmega DIP28 if you need it //http://www.arduino.cc/en/Hacking/PinMapping int segA = 2; //Display pin 11 int segB = 3; //Display pin 7 int segC = 4; //Display pin 4 int segD = 5; //Display pin 2 int segE = 12; //Display pin 1 int segF = 7; //Display pin 10 int segG = 8; //Display pin 5 int segDP = 13; // Display pin 3 #include #include "RTClib.h" RTC_DS1307 RTC; // Date and time functions using a DS1307 RTC connected via I2C and Wire lib // original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/ // add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/ // add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm byte SW0 = A0; byte SW1 = A1; byte SW2 = A2; // use for hexa in zecimal conversion int zh, uh, ore; int zm, um, miniti; void setup() { // Serial.begin(57600); Wire.begin(); RTC.begin(); // RTC.adjust(DateTime(__DATE__, __TIME__)); // if you need set clock... just remove // from line above this // part code for flashing LED Wire.beginTransmission(0x68); Wire.write(0x07); // move pointer to SQW address // Wire.write(0x00); // turns the SQW pin off Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz // Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz Wire.endTransmission(); 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__)); } // dht.begin(); pinMode(segA, OUTPUT); pinMode(segB, OUTPUT); pinMode(segC, OUTPUT); pinMode(segD, OUTPUT); pinMode(segE, OUTPUT); pinMode(segF, OUTPUT); pinMode(segG, OUTPUT); pinMode(segDP, OUTPUT); pinMode(digit1, OUTPUT); pinMode(digit2, OUTPUT); pinMode(digit3, OUTPUT); pinMode(digit4, OUTPUT); // pinMode(13, OUTPUT); Serial.begin(9600); Serial.println("test for niq_ro"); pinMode(SW0, INPUT); // for this use a slide switch pinMode(SW1, INPUT); // N.O. push button switch pinMode(SW2, INPUT); // N.O. push button switch digitalWrite(SW0, HIGH); // pull-ups on digitalWrite(SW1, HIGH); digitalWrite(SW2, HIGH); } void loop() { digitalWrite(segDP, HIGH); DateTime now = RTC.now(); int timp = now.hour()*100+now.minute(); // int timp = (now.minute(), DEC); // displayNumber(12); // this is number to diplay // int timp = 1234; Serial.print(now.hour(), DEC); Serial.print(":"); Serial.print(now.minute(), DEC); Serial.print(" -> "); Serial.print(timp); Serial.println(" !"); // display parts for(int i = 250 ; i >0 ; i--) { if (timp >= 1000) displayNumber01(timp); else displayNumber02(timp); } for(int i = 250 ; i >0 ; i--) { if (timp >= 1000) displayNumber03(timp); else displayNumber04(timp); } if (!(digitalRead(SW0))) set_time(); // hold the switch to set time } void set_time() { byte minutes1 = 0; byte hours1 = 0; byte minutes = 0; byte hours = 0; while (!digitalRead(SW0)) // set time switch must be released to exit { minutes1=minutes; hours1=hours; while (!digitalRead(SW1)) // set minutes { minutes++; // converting hexa in zecimal: zh = hours / 16; uh = hours - 16 * zh ; ore = 10 * zh + uh; zm = minutes / 16; um = minutes - 16 * zm ; miniti = 10 * zm + um; for(int i = 20 ; i >0 ; i--) { displayNumber01(ore*100+miniti); } if ((minutes & 0x0f) > 9) minutes = minutes + 6; if (minutes > 0x59) minutes = 0; Serial.print("Minutes = "); if (minutes >= 9) Serial.print("0"); Serial.println(minutes, HEX); delay(150); } while (!digitalRead(SW2)) // set hours { hours++; // converting hexa in zecimal: zh = hours / 16; uh = hours - 16 * zh ; ore = 10 * zh + uh; zm = minutes / 16; um = minutes - 16 * zm ; miniti = 10 * zm + um; for(int i = 20 ; i >0 ; i--) { displayNumber01(ore*100+miniti); } if ((hours & 0x0f) > 9) hours = hours + 6; if (hours > 0x23) hours = 0; Serial.print("Hours = "); if (hours <= 9) Serial.print("0"); Serial.println(hours, HEX); delay(150); } Wire.beginTransmission(0x68); // activate DS1307 Wire.write(0); // where to begin Wire.write(0x00); //seconds Wire.write(minutes); //minutes Wire.write(0x80 | hours); //hours (24hr time) Wire.write(0x06); // Day 01-07 Wire.write(0x01); // Date 0-31 Wire.write(0x05); // month 0-12 Wire.write(0x09); // Year 00-99 Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7. Wire.endTransmission(); // converting hexa in zecimal: zh = hours / 16; uh = hours - 16 * zh ; ore = 10 * zh + uh; zm = minutes / 16; um = minutes - 16 * zm ; miniti = 10 * zm + um; for(int i = 20 ; i >0 ; i--) { displayNumber01(ore*100+miniti); } // delay(150); } } void displayNumber01(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: digitalWrite(digit1, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, LOW); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } void displayNumber02(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: lightNumber(10); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, LOW); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } void displayNumber03(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: digitalWrite(digit1, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } void displayNumber04(int toDisplay) { #define DISPLAY_BRIGHTNESS 500 #define DIGIT_ON HIGH #define DIGIT_OFF LOW for(int digit = 4 ; digit > 0 ; digit--) { //Turn on a digit for a short amount of time switch(digit) { case 1: lightNumber(10); digitalWrite(segDP, HIGH); break; case 2: digitalWrite(digit2, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 3: digitalWrite(digit3, DIGIT_ON); digitalWrite(segDP, HIGH); break; case 4: digitalWrite(digit4, DIGIT_ON); digitalWrite(segDP, HIGH); break; } lightNumber(toDisplay % 10); toDisplay /= 10; delayMicroseconds(DISPLAY_BRIGHTNESS); //Turn off all segments lightNumber(10); //Turn off all digits digitalWrite(digit1, DIGIT_OFF); digitalWrite(digit2, DIGIT_OFF); digitalWrite(digit3, DIGIT_OFF); digitalWrite(digit4, DIGIT_OFF); } } //Given a number, turns on those segments //If number == 10, then turn off number void lightNumber(int numberToDisplay) { #define SEGMENT_ON LOW #define SEGMENT_OFF HIGH switch (numberToDisplay){ case 0: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_OFF); break; case 1: digitalWrite(segA, SEGMENT_OFF); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_OFF); break; case 2: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_OFF); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_ON); break; case 3: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_ON); break; case 4: digitalWrite(segA, SEGMENT_OFF); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 5: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_OFF); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 6: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_OFF); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 7: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_OFF); break; case 8: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_ON); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; case 9: digitalWrite(segA, SEGMENT_ON); digitalWrite(segB, SEGMENT_ON); digitalWrite(segC, SEGMENT_ON); digitalWrite(segD, SEGMENT_ON); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_ON); digitalWrite(segG, SEGMENT_ON); break; // all segment are ON case 10: digitalWrite(segA, SEGMENT_OFF); digitalWrite(segB, SEGMENT_OFF); digitalWrite(segC, SEGMENT_OFF); digitalWrite(segD, SEGMENT_OFF); digitalWrite(segE, SEGMENT_OFF); digitalWrite(segF, SEGMENT_OFF); digitalWrite(segG, SEGMENT_OFF); break; } } I made a litle movie named manual adjust for RTC clock with Arduino and 7-segment LED display Note: Original article in roumanian language is Afisaje LED cu 7 segmente si.. Arduino (IV)!!! 11.10.2016 I correct sketch for display 10:00 case.. 07.02.2017 Now, I pun on my Github channel sketch for cathode comon display, see github.com/tehniq3/multiplexedclock
display fun!
Аʙᴛ᧐ρ ʙ ᴛʙᥙᴛᴛᥱρᥱ-@Tina_cat25
Warrior Cats Fanart
seventeen jun weibo live 200325