Project tutorial
Arduino Digital Clock Using 1Sheeld

Arduino Digital Clock Using 1Sheeld

Monitor the real-time clock on LCD using 1Sheeld board and its companion app.

  • 2,295 views
  • 0 comments
  • 5 respects

Components and supplies

About this project

If I asked you: could you please turn off the lights when it comes to 10:30?

Actually, the common answer would be check your smartphone and make a reminder on your phone to turn the lights off by 10:30.

Well, that's ok for any normal person, but not for a maker, who would certainly think of automating this process by making some cool stuff which can get time automatically and take certain actions when 10:30 comes!

So, this your 10-minute tutorial to learn how to get time automatically, monitoring it and can make any decisions based on it as far as we want.

Let’s talk about the idea behind the Arduino Digital Clock project...

Idea:

We are going to get time from the smartphone automatically and wirelessly by using 1Sheeld with it's Android/iOS App with Arduino board.

The idea behind the Arduino Digital Clock is to use the clock shield from the App and connect the App to the 1Sheeld via Bluetooth so the App on our smartphone will automatically send the current date+time to the 1Sheeld board which is connected to the Arduino.

So we can print the current time (hours + minutes + seconds) on an LCD 16*2 and once time changed whether a second passed, a minute passed or an hour passed the time on the LCD will be changed automatically... with this simple :)

Getting started:

If this is your first time to deal with 1Sheeld or you want to learn more about it, I recommend checking this quick and easy getting started tutorial.

And if you haven't tried LCD 16*2 before, I recommend checking this quick video.

Now, after you've become a little bit familiar with 1Sheeld, let's start!

Step 1: Software components:

Step 2: Connection and Schematic:

  • Plug the 1Sheeld board into your Arduino as this:
  • Connect the LCD 16*2 as illustrated below:
  • Switch the 1Sheeld power to operate on 5v (Not the 3.3v):
  • 1Sheeld have 2 modes: Uploading mode and Operating mode. You can switch between them using the switch close to the Digital pins and is called “UART SWITCH” on 1Sheeld and “SERIAL SWITCH” on 1Sheeld+.

Firstly, you slide the switch towards the “SWITCH” notation which turns the 1Sheeld board into the Uploading mode to let you upload the Arduino code.

Secondly, after you finish uploading the code, slide the switch towards the “UART” notation (or “SERIAL” at 1Sheeld+ board) which turns the 1Sheeld board into the Operating mode to communicate with your smartphone 1Sheeld App.

  • Connect the Arduino via your PC using Arduino USB cable.

Step 3: Code:

I would recommend checking the Arduino Clock Shield documentation to know more about the Arduino Clock Shield functionality and how to use them.

Now, switch the 1Sheeld board to the Uploading mode, upload the attached code for the Arduino Digital Clock:

Switch the 1Sheeld board to the Operating mode then open the 1Sheeld app and connect it to the 1Sheeld board via Bluetooth.

Step 4: Run it:

Finally, select the Arduino clock shield from the shields list.

You will notice that the LCD is showing only zeros and this is normal because you have to press the Arduino reset button to make the 1Sheeld re-initiate the request of time from the App.

What happened after uploading the code is that any code inside the void setup() part (where the time request is sent) is executed fast (even faster than the time you took to switch to the operating mode) and then the Arduino lies inside the void loop() part forever.

So, briefly, the Arduino sent the time request quickly then you switched to the operation mode where the communication between the 1Sheeld and the App started and missed the time request.

So, by resetting the Arduino after the 1Sheeld is in operating mode, it goes inside the void setup() part again and sends the time request again and now the request reached the App and the time is updated on the LCD!

Now you are done with the Arduino Digital Clock and you can add your own extra code lines to check whether the hours, minutes and seconds reached a certain value and then take any decision like switching lights connected to a relay or even open the fan for you to cool weather just at the time you return home :)

Hope you enjoyed this Arduino Digital CLock project! If you have any question, please don’t hesitate to leave it in the comments down below and stay tuned for more 10-minute Tutorials ;)

Code

Digital_Clock.inoArduino
/*
  Arduino Digital Clock Project

  This project shows an application on 1Sheeld's clock shield.

  By using this project, you can monitor the current real time
  by using clock shield from 1Sheeld.
  You can then take certain actions based on the time you get.

  OPTIONAL:
  To reduce the library compiled size and limit its memory usage, you
  can specify which shields you want to include in your sketch by
  defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.
*/

/* Include clock shield only */
#define CUSTOM_SETTINGS
#define INCLUDE_CLOCK_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Include LCD library */
#include <LiquidCrystal.h>

/* Define some variables for the time. */
int hour, minute, second;

// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

  /* Start communication. */
  OneSheeld.begin();

  /* Start the clock shield. */
  Clock.queryDateAndTime();

  /* Set up the LCD's number of columns and rows */
  lcd.begin(16, 2);

  /* Print this line to the LCD */
  lcd.print("1Sheeld Clock");
}

void loop() {

  /* Always get the time. */
  hour = Clock.getHours();
  minute = Clock.getMinutes();
  second = Clock.getSeconds();

  /* Set the cursor to column 0, line 1 */
  lcd.setCursor(0, 1);

  /* Print the current hour */
  lcd.print(hour);
  lcd.print(":");

  /* Print the current minute */
  lcd.print(minute);
  lcd.print(":");

  /* Print the current second */
  lcd.print(second);

  /* As once second reaches "59", it start again with "0" not "00" so, the "9" of the previous "59" will stay causing a confusion */
  /* So, we clear the second line after a second has passed */
  if (second == 59)
  {
    delay(100);

    /* Move the cursor to the begining of the second line */
    lcd.setCursor(0, 1);

    /* Loop to clear "print empty spaces" all the 16 places of the second line */
    for (int i = 0; i < 16; i++)
    {
      /* Clear "print empty spaces" to clear the previous time to print a new one */
      lcd.print(" ");
    }
  }
}

Schematics

Circuit Diagram
Untitled znmlmsgenv

Comments

Similar projects you might like

Arduino Joystick Servo Control Using 1Sheeld

Project tutorial by amrmostaafaa

  • 2,412 views
  • 0 comments
  • 12 respects

Arduino can hear and understand your voice with 1Sheeld !

Project tutorial by Alessandro Didonna

  • 3,926 views
  • 1 comment
  • 10 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 116,864 views
  • 29 comments
  • 106 respects

4-Stroke Digital Clock With Arduino

Project tutorial by LAGSILVA

  • 14,034 views
  • 16 comments
  • 44 respects

Digital And Binary Clock With Two LED Matrix And RTC

Project tutorial by LAGSILVA

  • 10,864 views
  • 36 comments
  • 42 respects

Analog Clock using 1Sheeld Graphical LCD

Project tutorial by Ahmed El-Hinidy

  • 2,693 views
  • 0 comments
  • 7 respects
Add projectSign up / Login