Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I write the code? Have your arduino get the date(mm/dd/yyyy) & time(hh/mm

ID: 3598476 • Letter: H

Question

How do I write the code?

Have your arduino get the date(mm/dd/yyyy) & time(hh/mm/ss) from the user via the serial monitor in the arduino software.

Date includes day, month and year

Time includes hour, minutes and seconds

You circuit/program should:

print a prompt on the serial monitor,

get input of date and time from user

display date and time on the 16x2 display

keep accurate time on 16x2 display

include error checking for input that doesn't make sense (hours not in range of 0 to 23, minutes not in range 0 to 59, month not range of 1 to 12, etc).

Explanation / Answer

CODE

#include <Process.h>

Process date;

int hours, minutes, seconds;

int lastSecond = -1;

void setup()

{

Serial.begin(2400);

Serial.write("AT+CMGF=1 ");   

delay(1500);

Serial.write("AT+CCLK=? ");   

while(1)

{

    if(Serial.available())

    {

      Serial.write(Serial.read());

    }

}

}

void setup()

{

Serial.begin(2400);

Serial.write("AT+CMGF=1 ");              //set GSM to text mode

delay(1500);

Serial.write("AT+CCLK="99/12/12,04:06:30+08" "); //Set date and time YY/MM/DD hh:mm:ss+zz

while(1)

{

    if(Serial.available())

    {

      Serial.write(Serial.read());

    }

}

void setup() {

Bridge.begin();   

SerialUSB.begin(9600);   

while (!Serial);   

SerialUSB.println("Time Check");

if (!date.running()) {

    date.begin("date");

    date.addParameter("+%T");

    date.run();

}

}

void loop() {

if (lastSecond != seconds)

{

    if (hours <= 9) {

      SerialUSB.print("0");

    }

    SerialUSB.print(hours);

    SerialUSB.print(":");

    if (minutes <= 9) {

      SerialUSB.print("0");

    }

    SerialUSB.print(minutes);

    SerialUSB.print(":");

    if (seconds <= 9) {

      SerialUSB.print("0"); // adjust for 0-9

    }

    SerialUSB.println(seconds);

  if (!date.running()) {

      date.begin("date");

      date.addParameter("+%T");

      date.run();

    }

}

while (date.available() > 0) {

String timeString = date.readString();

int firstColon = timeString.indexOf(":");

    int secondColon = timeString.lastIndexOf(":");

String hourString = timeString.substring(0, firstColon);

    String minString = timeString.substring(firstColon + 1, secondColon);

    String secString = timeString.substring(secondColon + 1);

hours = hourString.toInt();

    minutes = minString.toInt();

    lastSecond = seconds;   

    seconds = secString.toInt();

}

}

IF ANY QUERIES REGARDING CODE PLEASE GET BACK TO ME

THANK YOU FOR THE OPPURTUNITY

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote