Skip to main content

85. Analog and Digital Clock on Adafruit TFT Display using Arduino

 Hey everyone,

Sorry I have not posted in a while. Today, I will be presenting you my Analog and Digital Clock on Adafruit TFT Display using Arduino. You can find the schematic and code explanation within this post. Read on further to learn how I did this project.



Hardware components used in this project

  • Arduino Mega 2560
  • Adafruit 2.8" TFT Touch Shield for Arduino w/ Capacitive Touch - You could also use any other Arduino compatible TFT display
  • DS1307 RTC Module
  • Solderless Breadboard - Half+ (This is optional if you are connecting the RTC module to the development board directly)
  • Jumper wires (x4) - Male/Male jumper wires if using solderless breadboard. Female/Male if connecting RTC module directly to Arduino Mega.

Software apps

  • Arduino IDE - latest version is recommended

Setup





Connections

DS1307 RTC Module

  • SCL - A5
  • SDA - A4
  • VCC - 5V
  • GND - Ground

Adafruit TFT Touch shield

You can simply place the Adafruit TFT Touch shield onto your Arduino Mega 2560 development board.
Make sure to include these in your code:
  • TFT Data Command pin - D9
  • TFT Chip Select pin - D10

Coding

For this sketch, you will need the following libraries:
The SPI and Wire libraries are inbuilt so you do not have to download them.
Refer to each library's documentation to learn about the functions.

Create tft instance using the Adafruit_ILI9341 class. Use this object to draw two rounded rectangles. Please refer to this guide about drawing pixels using the Adafruit GFX library.
One rounded rectangle should be labelled as 'Analog' while the other should be labelled as 'Digital'.

This project uses the same technique followed in the CapTouch_onoffbutton example sketch from the Adafruit FT6206 library. Make sure to write down the coordinates located within the rounded rectangles. 

Analog Clock

You will need some basic trigonometry knowledge to calculate the coordinates of your 'clock hands'.
You will be needing the sin and cos functions for this sketch and remember that the angles should be in radians. 
To convert degrees to radians, multiply the angle (in degrees) by pi and divide it by 180.
There are 60 minutes in an hour and 60 seconds in a minute so the angle for each minute and second are: 360/60 = 6 degrees.
The hour hand travels 360 degrees around the clock face and the angle between each hour is : 360/12 = 30 degrees.
Draw a white circle to denote the clock face.
The radius of the circle should be used with sine and cosine functions and the result should be added to the coordinates denoting the centre of the circle to calculate the coordinates where the clock hands should point to.
angle = a
height = h
width = w
centre of circle = (x,y)
hands = (x1,y1)

sin (a) = w/ radius
cos (a) = h/ radius

w = sin(a) x radius
h = cos (a) x radius

x1 = x + w
y1 = y - h

You should decide the radius for each clock hand. The minute hand is the shortest and the second hand is the longest.

Digital Clock

Displaying the digital clock is quite easy. The display should be refreshed every 1 second. 
Draw a black rectangle within which the time, date and day of the week should be displayed.
The day of the week function gives the result as a number so you should create an array which stores the days of the week. The result of the function will be used as the index of the array to display the day.
The time and date can be obtained by using the hour( ), minute( ), second( ), day( ), month( ) and year( ) functions.


Watch the YouTube video in the last section of this post to see how this project works.
If anyone has any questions or suggestions about this project, please feel free to comment below.
Do not send me any email requesting the codes.

Final Look

The YouTube video will be published in the next few hours so please stay tuned.
If anyone has any questions or suggestions about this project, please feel free to comment below.


Comments

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)

86. RFID Health tag (Arduino and Python)

 Hey everyone, Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project. Hardware components used in this project Arduino Uno Solderless Breadboard - Half+ MRFC522 RFID reader RFID key tags (x5) Push-buttons (x2) Male-to-Male Jumper wires (x12) USB Type A/ B cable (for Arduino Uno) Software required Arduino IDE - latest version recommended Python 3.8 Schematic MFRC522 RFID reader SDA/ SS - D10 SCK - D13 MOSI - D11 MISO - D12 IRQ - Not connected GND - Ground RST/ RESET - D9 3.3V - 3.3V Push-buttons Submit button - D4 Retrieve button - D5 Coding Arduino For this project, you will be using the following libraries: MFRC522 by miguelbalboa -  https://github.com/miguelbalboa/rfid SPI - In-bu