--> Project I - 8. 6 Digit of Digital Clock using-7 Segment Based on Arduino | basic arduino tutorial

Thursday, August 24, 2017

Project I - 8. 6 Digit of Digital Clock using-7 Segment Based on Arduino

| Thursday, August 24, 2017
6 Digit of Digital Clock using-7 Segment


Arduino will read RTC data (Real Time Clock) data that obtained in the form of hour, minute, second, day to-, date, month and year.

In this project we will create a digital clock with seven segment. The numbers displayed in each digit are displayed alternately from digits 1 through 6 with a 3mS / digit appearance pause so that the numbers appear at the same time. RTC used DS1307 as its clock source.

Hardware Requirement
  • Arduino Uno Board
  • 6 Digit of 7-Segment with Common Anode
  • RTC DS1307 Module
  • Power supply +5 Volt
  • Jumper

7-Segment | Source        RTC DS1307 | Source

Block Diagram


Schematic


7-Segment CA Wiring | Source

Arduino - 7 Segment Wiring




Arduino - RTC Wiring



Source Code/Sketch
#include <LiquidCrystal.h>
#include <Wire.h>
#define DS1307_ADDRESS 0x68
byte zero = 0x00;
byte nilai,i;
byte second ,minute,hour, weekDay;
byte monthDay,month,year;
byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,0,1,0,0 } // = 9
};
void setup()
{
pinMode(2, OUTPUT); //a
pinMode(3, OUTPUT);//b
pinMode(4, OUTPUT);//c
pinMode(5, OUTPUT);//d
pinMode(6, OUTPUT);//e
pinMode(7, OUTPUT);//f
pinMode(8, OUTPUT);//g
pinMode(9, OUTPUT);//dig 1
pinMode(10, OUTPUT);//dig 2
pinMode(11, OUTPUT);//dig 3
pinMode(12, OUTPUT);//dig 4
pinMode(13, OUTPUT);//dig 5
pinMode(A0, OUTPUT);//dig 6
Wire.begin();
/*---------seting jam
second = 5; //0-59
minute = 36; //0-59
hour = 11; //0-23
setingRTC();
---------------------*/
}
void loop(){
bacaRTC();
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
digitalWrite(A0,HIGH);
sevenSegWrite(hour/10);
delay(3);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
digitalWrite(A0,HIGH);
sevenSegWrite(hour%10);
delay(3);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
digitalWrite(A0,HIGH);
sevenSegWrite(minute/10);
delay(3);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
digitalWrite(A0,HIGH);
sevenSegWrite(minute%10);
delay(3);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
digitalWrite(A0,HIGH);
sevenSegWrite(second/10);
delay(3);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
digitalWrite(A0,LOW);
sevenSegWrite(second%10);
delay(3);
}
void sevenSegWrite(byte segment) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[segment][segCount]);
++pin;
}
}
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}
void bacaRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111);
weekDay = bcdToDec(Wire.read());
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void setingRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop RTC
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(zero); //start
Wire.endTransmission();
}

How it Works

1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.

3. Add some library if needed
4. Compile and upload the script program above to your arduino.
5. Seven segment instantly displays the clock according to RTC settings.






Video for Project I - 8. 6 Digit of Digital Clock using-7 Segment Based on Arduino






Required file

Related Posts

1 comment:

  1. Coin Casino | €20 No Deposit Bonus and 200 Free Spins for
    Play Coin Casino with €20 septcasino No Deposit Bonus 인카지노 and 200 Free Spins for RTG Slots, Roulette and Video Poker. Exclusive €20 No Deposit Bonus & 200 Free 제왕카지노 Spins for

    ReplyDelete