Sitemap / Advertise

Introduction

Set the alarm and activate it with an RFID card or tag to get notified with your favorite songs when the reading time is over. Also, monitor time, date, and temperature.


Tags

Share

Arduino RFID Reading Time Checker with MP3 Player and RTC

Advertisement:


read_later

Read Later



read_later

Read Later

Introduction

Set the alarm and activate it with an RFID card or tag to get notified with your favorite songs when the reading time is over. Also, monitor time, date, and temperature.

Tags

Share





Advertisement

Advertisement




    Components :
  • [1]RFID Reading Time Checker (PCB)
  • [1]Arduino Nano v3
  • [1]Nokia 5110 Screen Module
  • [1]Serial MP3 Player Module (OPEN-SMART)
  • [1]Micro SD Card
  • [1]DS3231 RTC Module
  • [1]MFRC522 RFID Module
  • [5]1K Resistor
  • [4]220Ω Resistor
  • [4]Button

Description

I created this project (RFID Reading Time Checker with MP3 Player and RTC) to solve one of my perennial problems :) I have the habit of reading one-hour every day and had been using my phone's timer to check my reading time. However, I was always kvetching about its lack of features when it comes to detecting the book reading time and notifying me. Thus, I contemplated a device specialized to check the reading time with various features to ease my reading process. To check the reading time, I needed to elicit the accurate date and time information, so I used a DS3231 RTC module, which also provides the current temperature. And, I wanted to activate the timer (RTC) by using an RFID tag or card before starting to read my book, so I used an MFRC522 RFID module. To get notified when the set reading time is over, I utilized a Serial MP3 Player Module (OPEN-SMART) with Speaker, including my two favorite cartoon soundtracks as the playlist. Lastly, to develop an interface (menu) to control the mentioned modules and implement special features, I used an Arduino Nano and a Nokia 5110 Screen. You can get the more detailed information regarding the specialties of this device in Features.

As a prototype, I tried my code with the mentioned modules and Arduino Nano on two breadboards, as depicted in the figure below. The prototype was working properly, but it had redundant wirings that hinder me from using the device attached to my bookcase as I intended. Therefore, I decided to design a PCB to complete my project, including buttons to control the interface, headers to connect the modules, and embedded-resistors.

project-image
Figure - 45.1

SeeedStudio sponsored my PCB design for this project with its fast and high-quality PCB / PCBA service. You can find more detailed information about the PCB and its fabrication process in Designing the RFID Reading Time Checker PCB.

project-image
Figure - 45.2

Preview: What You Will Learn

- How to design a PCB

- How to use an MFRC522 RFID module with Arduino Nano

- How to register a new RFID card or tag UID to the EEPROM

- How to use a DS3231 RTC module with Arduino Nano

- How to use a Nokia 5110 Screen with Arduino Nano

- How to control a Serial MP3 Player Module (OPEN-SMART) with Speaker by using UART commands with Arduino Nano

- How to program an interface and a timer in Arduino

Features

When you open the device (RFID Reading Time Checker with MP3 Player and RTC), you should see the "Initializing..." message while it is checking the modules.

project-image
Figure - 45.3

Then, the device will show you the home screen (interface), including four menu commands - A. Init Checker, B. Set Checker, C. Clock, and D. New Card. Each menu command lets you activate a different feature of the device.

To select and activate menu commands, you need to use the buttons on the PCB, as explained below, named Left, OK, Right, and Exit (from left to right).

Press Right to go down and Left to go up.

To select a menu command, press OK.

To return to the home screen after selecting, press Exit.

project-image
Figure - 45.4

A. Init Checker

Approximate the registered RFID card or tag in the EEPROM to the MFRC522 RFID module to activate the alarm mode. The device displays the clock icon if the alarm mode is activated.

project-image
Figure - 45.5


project-image
Figure - 45.6


project-image
Figure - 45.7

In the alarm mode, the device notifies you when the timer (RTC) has reached the set reading time - for instance, 15:21 - by displaying the Spider-Man icon and playing the second song (Spider-Man Cartoon Theme Song) in the playlist of the Serial MP3 Player (OPEN-SMART).

In other words, as its name implies, the alarm mode is an alarm that is activated by the registered RFID card or tag and rings when set (the reading time). So, depending on your routine, you can check your reading time daily.

To return to the home screen, press Exit.

project-image
Figure - 45.8


project-image
Figure - 45.9

Important: In the alarm mode, you can play songs without waiting for the device to notify you with the second song and the icon if you want to listen to the playlist:

Press Right to play the first song in the playlist.

Press Left to pause the playing song.

Press OK to play (continue) the playing song.

B. Set Checker

Set the reading time - for instance, 14:2 - to get notified when the timer (RTC) has reached the reading time if the alarm mode is activated. When the reading time is set, it is saved by the device until further changes.

Press Right to increment minutes by 1.

Press Left to decrement minutes by 1.

If minutes exceed 59, the device increases the hour by 1.

If minutes are smaller than 0, the device decreases the hour by 1.

Allowed Range: 0:0 - 23:59

Press Exit to return to the home screen after setting the reading time.

project-image
Figure - 45.10


project-image
Figure - 45.11


project-image
Figure - 45.12

C. Clock

Display time, date, and temperature variables generated by the DS3231 RTC module, which is also the timer of the device.

project-image
Figure - 45.13


project-image
Figure - 45.14

D. New Card

Approximate an RFID card or tag to scan and save the new UID to the EEPROM. In this way, you can define the first UID or change it easily by using the MFRC522 RFID module.

Do not forget that the registered UID in the EEPROM is used to activate the alarm mode by the device, so make sure to see the "Registered Successfully!" message after approximating an RFID card or tag to the MFRC522 RFID module.

project-image
Figure - 45.15


project-image
Figure - 45.16


project-image
Figure - 45.17

Step 1: Designing the RFID Reading Time Checker PCB

As I said earlier, I attached all components on two breadboards to execute my code to test whether the modules are working accurately or not with Arduino Nano v3.

project-image
Figure - 45.18


project-image
Figure - 45.19


project-image
Figure - 45.20

After that, I created a schematic according to the connections on the breadboards and designed the RFID Reading Time Checker PCB on KiCad to complete my project.

project-image
Figure - 45.21


project-image
Figure - 45.22

I used SeeedStudio's PCB / PCBA service to fabricate the RFID Reading Time Checker PCB and Seeed OPL to select integrated components for PCBA (PCB Assembly) - buttons, resistors, headers, and the power-jack. If you want to inspect the part list used in PCBA, download the BOM file in Downloads.

After fabrication, I was able to connect an Arduino Nano, a Nokia 5110 Screen, a DS3231 RTC module, an MFRC522 RFID module, and a Serial MP3 Player (OPEN-SMART) without any redundant wiring and supply the device with an external power source by using the power-jack. You can download the Gerber, fabrication, and BOM files to fabricate the RFID Reading Time Checker PCB by using SeeedStudio's expedite and high-quality PCBA service with competitive prices as I did.

project-image
Figure - 45.23


project-image
Figure - 45.24

Huge thanks to SeeedStudio for sponsoring this project.

Step 2: Sending commands to the Serial MP3 Player (OPEN-SMART)

The playlist for this project - two of my favorite cartoon soundtracks :)

1) Batman Beyond Theme Song | Listen

2) The Spectacular Spider-Man Theme Song | Listen

It is effortless to use a Serial MP3 Player with an Arduino Nano as long as you know the UART commands required to trigger the right functions. I used a Serial MP3 Player module with Speaker by OPEN-SMART. So, if you have a Serial MP3 Player with a different brand name, these commands shown below will not work for you.

Follow the instructions from the guidance:

"The module is a kind of simple MP3 player device which is based on a high-quality MP3 audio chip. It can support 8k Hz ~ 48k Hz sampling frequency MP3 and WAV file formats. There is a TF card socket on board, so you can plug the micro SD card that stores audio files. MCU can control the MP3 playback state by sending commands to the module via UART port, such as switch songs, change the volume and play mode, and so on. You can also debug the module via USB to UART module. It is compatible with Arduino / AVR / ARM / PIC."

"Make sure your micro SD card is formatted as FAT16 or FAT32 and there are some songs in it. You should create folders “01” and “02”, and put some songs with the name 001xxx.mp3 / 002xxx.mp3 / 003xxx.mp3 in the two folders."

In other words, to be able to execute commands accurately, save your songs in a folder named as '01' and add consecutive numbers to song names - 001Spiderman.mp3, 002Batman_Beyond.mp3.

To send UART commands to the Serial MP3 Player with Arduino Nano, I created a function named as send_command_to_MP3_player. It transfers each byte in the requested command to the Serial MP3 Player via the SoftwareSerial library, depending on the length of the requested command - 4, 5, or 6.

As shown below, separate the command you want to send to the Serial MP3 Player by bytes - 0x7e. All commands start with '7E' and end with 'EF'. The second byte is the number of the bytes in between - '02', '03', '04'. Download the Serial MP3 Player manual by OPEN-SMART to inspect all commands and get more detailed instructions.


// Define the Serial MP3 Player Module.
SoftwareSerial MP3(MP3_RX, MP3_TX);

// Select storage device to TF card
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef}; // 7E 03 35 01 EF
// Play the song with the directory: /01/001xxx.mp3
static int8_t play_first_song[] = {0x7e, 0x04, 0x41, 0x00, 0x01, 0xef}; // 7E 04 41 00 01 EF
// Play the song with the directory: /01/002xxx.mp3
static int8_t play_second_song[] = {0x7e, 0x04, 0x41, 0x00, 0x02, 0xef}; // 7E 04 41 00 02 EF
// Play the song.
static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
// Pause the song.
static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF

// Send UART commands to the Serial MP3 Player (OPEN-SMART).
void send_command_to_MP3_player(int8_t command[], int len){
  Serial.print("\nMP3 Command => ");
  for(int i=0;i<len;i++){ MP3.write(command[i]); Serial.print(command[i], HEX); }
  delay(1000);
}

project-image
Figure - 45.25

Step 3: Programming Arduino Nano

Download the required libraries to be able to control the modules.

Nokia 5110 Screen | Library

DS3231 RTC Module | Library

MFRC522 RFID Module | Library

- Include required libraries after downloading.

- Define the RX and TX pins to establish UART communication with the MP3 Player Module.

- Define the required MP3 Player Commands:

- 7E 03 35 01 EF (Select storage device to TF card)

- 7E 04 41 00 01 EF (Play the song with the directory: /01/001xxx.mp3)

- 7E 04 41 00 02 EF (Play the song with the directory: /01/002xxx.mp3)

- 7E 02 01 EF (Play or Continue)

- 7E 02 02 EF (Pause)

- Define the Serial MP3 Player Module by using the SofwareSerial library.

- Define the Nokia screen pins.

- Get the monochrome images for the graphics screen (clock and spidey).

- Monochrome Image Converter

- Initiate the DS3231 RTC Module using SDA and SCL pins.

- Define a time variable to get data from DS3231 properly.

- Create MFRC522 instance.

- Define MFRC522 module key input.

- Define the readCard byte which stores the UID scanned by the MFRC522 RFID Module.

- Define registeredUID and lastRead strings.

- Define the control button pin numbers.

- Define the interface menu commands (booleans).

- Initiate the Serial MP3 Player Module.

- Select the SD card as storage by sending the required command with the send_command_to_MP3_player function.

- Start the rtc object.

- Start the MFRC522 Hardware using SPI protocol.

- Initialize MFRC522 Hardware.

- Initiate the Nokia screen.

- In the read_control_buttons function, read the control buttons (Left, OK, Right, Exit).

- In the select_menu_commands function:

- Increase or decrease the option number using Right and Left buttons.

- Depending on the selected option number, change boolean status.

- In the home_screen function, print the interface (menu).

- Adjust the interface view depending on the selected option.

- If Init_Checker is selected:

- Initiate the alarm mode and activate the timer when the registered UID is detected by the RFID Module (MFRC522).

- In the get_the_registered_UID function, get the registered UID in the EEPROM and arrange it for comparing.

- In the get_the_last_detected_UID function, get the last UID detected when an RFID card or tag is read by the MFRC522 RFID module and arrange it for comparing.

- If the detected UID corresponds to the registered UID in the EEPROM, then activate the alarm mode.

- Draw the alarm mode icon (clock).

- Get the date and time information from the DS3231 RTC Module.

- If the timer (RTC Module) hits the given reading time, then start the MP3 Player (the second song).

- Draw the notification icon - I used a Spider-Man icon because the MP3 Player plays his cartoon's soundtrack :)

- Play or pause selected songs for fun while the device is in the alarm mode :)

- Blank the lastRead string after false readings.

- If Set_Checker is selected:

- Set the reading time by using Left (-) and Right (+) buttons to get notified when the timer (RTC) hits the given time (such as 18 : 37).

- If Clock is selected:

- Monitor date, time, and temperature on the Nokia 5110 screen.

- In the get_time_rtc function, get the current hour and minute from the DS3231 RTC module - t.hour; t.min; - and set them manually by uncommenting the highlighted lines.

- If New_Card is selected:

- Scan a new RFID card or tag and save the new UID to the EEPROM as the registered UID to be used to activate the alarm mode.

- In the register_new_card function, detect the new card UID and save the new UID in the readCard byte to write it to the EEPROM.

- Return the success message ("Registered Successfully!").

project-image
Figure - 45.26


project-image
Figure - 45.27


project-image
Figure - 45.28


project-image
Figure - 45.29


project-image
Figure - 45.30


project-image
Figure - 45.31


project-image
Figure - 45.32


project-image
Figure - 45.33


- As a bonus, the serial monitor prints the transferred UART commands, the registered UID in the EEPROM, and the last UID detected by the MFRC522 RFID module.

project-image
Figure - 45.34

Connections (PCB)

Connect the modules and Arduino Nano to the headers on the PCB (RFID Reading Time Checker) as follows.

A1 -> Arduino Nano v3

J1 -> Serial MP3 Player by OPEN-SMART

J2 -> MFRC522 RFID Module

J3 -> DS3231 RTC Module

J4 -> Nokia 5110 Screen

Integrated Components on the PCB (after PCBA):

R1, R2, R3, R4 -> 220-ohm resistors (buttons)

R5, R6, R7, R8, R9 -> 1K resistors (Nokia 5110 Screen)

K1, K2, K3, K4 -> Control Buttons

J5 -> Power Jack

project-image
Figure - 45.35


project-image
Figure - 45.36

Arduino Pin Connections Embedded on the PCB:


// Connections
// Arduino Nano v3:           
//                                Serial MP3 Player Module (OPEN-SMART)
// D8 --------------------------- TX
// D7 --------------------------- RX
//                                Nokia 5110 Screen
// D2 --------------------------- SCK (Clk)
// D3 --------------------------- MOSI (Din) 
// D4 --------------------------- DC 
// D5 --------------------------- RST
// D6 --------------------------- CS (CE)
//                                DS3231
// SDA(or A4) ------------------- SDA  
// SCL(or A5) ------------------- SCL
//                                MFRC522
// D9  -------------------------- RST
// D10 -------------------------- SDA
// D11 -------------------------- MOSI
// D12 -------------------------- MISO
// D13 -------------------------- SCK
//                                LEFT_BUTTON
// A0 --------------------------- S
//                                OK_BUTTON
// A1 --------------------------- S
//                                RIGHT_BUTTON
// A2 --------------------------- S
//                                EXIT_BUTTON
// A3 --------------------------- S

Demonstration and Conclusion

After completing the device, I fastened it to my bookcase by using a hot glue gun to activate the alarm mode with my RFID tag quickly when I get a book from my bookcase :)

project-image
Figure - 45.37


project-image
Figure - 45.38

Code

Reading_Time_Checker_with_MP3_Player.ino

Download



         ////////////////////////////////////////////////////  
        //       RFID Book Reading Time Checker with      //
       //               MP3 Player and RTC               //
      //           -------------------------            //
     //                 Arduino Nano                   //           
    //               by Kutluhan Aktar                // 
   //                                                //
  ////////////////////////////////////////////////////

//
//
//
//
// Connections
// Arduino Nano v3:           
//                                Serial MP3 Player Module (OPEN-SMART)
// D8 --------------------------- TX
// D7 --------------------------- RX
//                                Nokia 5110 Screen
// D2 --------------------------- SCK (Clk)
// D3 --------------------------- MOSI (Din) 
// D4 --------------------------- DC 
// D5 --------------------------- RST
// D6 --------------------------- CS (CE)
//                                DS3231
// SDA(or A4) ------------------- SDA  
// SCL(or A5) ------------------- SCL
//                                MFRC522
// D9  -------------------------- RST
// D10 -------------------------- SDA
// D11 -------------------------- MOSI
// D12 -------------------------- MISO
// D13 -------------------------- SCK
//                                LEFT_BUTTON
// A0 --------------------------- S
//                                OK_BUTTON
// A1 --------------------------- S
//                                RIGHT_BUTTON
// A2 --------------------------- S
//                                EXIT_BUTTON
// A3 --------------------------- S



// Include required libraries:
#include <SoftwareSerial.h>
#include <LCD5110_Basic.h>
#include <DS3231.h>
#include <EEPROM.h>     
#include <SPI.h>        
#include <MFRC522.h>

// Define the RX and TX pins to establish UART communication with the MP3 Player Module.
#define MP3_RX 8 // to TX
#define MP3_TX 7 // to RX

// Define the required MP3 Player Commands.
// You can inspect all given commands from the project page: 
// Select storage device to TF card
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef}; // 7E 03 35 01 EF
// Play the song with the directory: /01/001xxx.mp3
static int8_t play_first_song[] = {0x7e, 0x04, 0x41, 0x00, 0x01, 0xef}; // 7E 04 41 00 01 EF
// Play the song with the directory: /01/002xxx.mp3
static int8_t play_second_song[] = {0x7e, 0x04, 0x41, 0x00, 0x02, 0xef}; // 7E 04 41 00 02 EF
// Play the song.
static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
// Pause the song.
static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF

// Define the Serial MP3 Player Module.
SoftwareSerial MP3(MP3_RX, MP3_TX);

// Define the Nokia screen.
LCD5110 myGLCD(2,3,4,5,6);

extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
// Define images for the graphics screen.
extern uint8_t clock[];
extern uint8_t spidey[];

// Initiate the DS3231 RTC Module using SDA and SCL pins.
DS3231  rtc(SDA, SCL);

// Define a time variable to get data from DS3231 properly.
Time t;

// Create MFRC522 instance.
#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define MFRC5222 module key input.
MFRC522::MIFARE_Key key;

// Stores scanned ID read from the RFID Module.
byte readCard[4];
// Define registeredUID and lastRead strings.
String registeredUID, lastRead;

// Define the control buttons.
#define B_Exit A3
#define B_Right A2
#define B_OK A1
#define B_Left A0

// Define the data holders.
int Right, OK, Left, Exit;
int alarmHour =0;
int alarmMin = 0;
int selected = 0;

// Define the interface options:
volatile boolean Init_Checker = false;
volatile boolean Set_Checker = false;
volatile boolean Clock = false;
volatile boolean New_Card = false;
volatile boolean Activated = false;
volatile boolean Alarm_Mode = false;

void setup() {
  pinMode(B_Exit, INPUT);
  pinMode(B_Right, INPUT);
  pinMode(B_OK, INPUT);
  pinMode(B_Left, INPUT);
  
  // Initiate the serial moinitor.
  Serial.begin(9600);
  // Initiate the Serial MP3 Player Module.
  MP3.begin(9600);
  // Select the SD Card.
  send_command_to_MP3_player(select_SD_card, 5);
  // Start the rtc object.
  rtc.begin();
  // MFRC522 Hardware uses SPI protocol
  SPI.begin();
  // Initialize MFRC522 Hardware           
  mfrc522.PCD_Init();    
  // Initiate the Nokia screen.
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  myGLCD.print("Initializing...", 0, 8);
  delay(1000);
  myGLCD.clrScr();

}

void loop() {
  read_control_buttons();

  select_menu_commands();
  
  home_screen();

  // Adjust the interface view depending on the selected option.
  if(Init_Checker == true){
    do{
      myGLCD.invertText(true);
      myGLCD.print("A.Init Checker", 0, 16);
      myGLCD.invertText(false);
      // If selected, initiate the alarm mode and activate the alarm when the registered UID is detected by the RFID Module (MFRC522).
      if(OK == true){
        myGLCD.clrScr();
        Activated = true;
        myGLCD.print("Approximate", 0, 0);
        myGLCD.print("the registered", 0, 8);
        myGLCD.print("card or key", 0, 16);
        myGLCD.print("to activate", 0, 24);
        myGLCD.print("the alarm", 0, 32);
        myGLCD.print("mode :)", 0, 40);
        // Get the registered UID in the EEPROM.
        get_the_registered_UID();
        while(Activated == true){
          // Read control variables.
          read_control_buttons();
          // Get the last detected UID from MFRC522.
          get_the_last_detected_UID();
          // If the detected UID corresponds to the registered UID in the EEPROM, then activate the alarm mode.
          if(lastRead == registeredUID){
            myGLCD.clrScr();
            Alarm_Mode = true;
            // ---------- Alarm Mode -------------
            if(Alarm_Mode == true){
              // Draw the alarm mode icon.
              myGLCD.drawBitmap(22, 0, clock, 40, 40);
              boolean song = false;
              while(Alarm_Mode == true){
                // Read control variables.
                read_control_buttons();
                // Get the date and time information from the DS3231 RTC Module.
                get_time_rtc();
                // If the RTC Module hits the given reading alarm time, then start the MP3 Player.
                if(t.hour == alarmHour && t.min == alarmMin && song == false){
                  // Send commands to the MP3 Player Module.
                  send_command_to_MP3_player(play_second_song, 6);
                  // Draw the notification icon - I used a Spider-Man logo because the MP3 Player plays his cartoon's sountrack :)
                  myGLCD.clrScr();
                  myGLCD.drawBitmap(22, 0, spidey, 40, 40);
                  song = true;
                }  
                // MP3 Player Settings:
                // Play or pause selected songs for fun while the module is in the alarm mode :)
                if(Right == true) send_command_to_MP3_player(play_first_song, 6);
                if(Left == true) send_command_to_MP3_player(pause, 4);
                if(OK == true) send_command_to_MP3_player(play, 4);
                // Exit.
                if(Exit == true){ Alarm_Mode = false; myGLCD.clrScr(); lastRead = ""; registeredUID = "";}
              }
            }
            // -----------------------------------
          }else{
            // Blank the lastRead string after false readings.
            lastRead = "";
          }
          // Exit.
          if(Exit == true){ Activated = false; myGLCD.clrScr(); registeredUID = "";}
        }
      }
    }while(Init_Checker == false);
  }
  if(Set_Checker == true){
    do{
      myGLCD.invertText(true);
      myGLCD.print("B.Set Checker", 0, 24);
      myGLCD.invertText(false);
      // If selected, set the reading alarm to get notified when the RTC hits the given time (such as 18 : 37).
      if(OK == true){
        myGLCD.clrScr();
        Activated = true;
        while(Activated == true){
          // Read control variables.
          read_control_buttons();
          // Display the reading alarm.
          myGLCD.setFont(BigNumbers);
          myGLCD.printNumI(alarmHour, LEFT, 0);
          myGLCD.printNumI(alarmMin, RIGHT, 0);
          myGLCD.setFont(SmallFont);
          myGLCD.print(".", CENTER, 0);
          myGLCD.print(".", CENTER, 16);
          myGLCD.print("DEC< Set >INC", CENTER, 40);
          // Set the reading alarm.
          if(Right == true) alarmMin++;
          if(Left == true) alarmMin--;
          if(alarmMin < 0){ alarmMin = 59; alarmHour--; myGLCD.clrScr(); }
          if(alarmMin > 59){ alarmMin = 0; alarmHour++; myGLCD.clrScr(); }
          if(alarmHour < 0) alarmHour = 23;
          if(alarmHour > 23) alarmHour = 0;
          delay(100);
          // Exit.
          if(Exit == true){ Activated = false; myGLCD.clrScr(); }
        }
      }
    }while(Set_Checker == false);
  }
  if(Clock == true){
    do{
      myGLCD.invertText(true);
      myGLCD.print("C.Clock", 0, 32);
      myGLCD.invertText(false);
      // If selected, display date and time on the screen.
      if(OK == true){
        myGLCD.clrScr();
        Activated = true;
        while(Activated == true){
          // Read control variables.
          read_control_buttons();
          // Get the date and time information from the DS3231 RTC Module.
          get_time_rtc();
          myGLCD.setFont(BigNumbers);
          myGLCD.printNumI(t.hour, LEFT, 0);
          myGLCD.printNumI(t.min, RIGHT, 0);
          myGLCD.setFont(SmallFont);
          myGLCD.print(".", CENTER, 0);
          myGLCD.print(".", CENTER, 16);
          myGLCD.print(String(rtc.getTemp()) + "'C", CENTER, 32);
          String d = String(t.date) + "/" + rtc.getMonthStr() + "/" + String(t.year);
          myGLCD.print(d, CENTER, 40);
          // Exit.
          if(Exit == true){ Activated = false; myGLCD.clrScr(); }
        }
      }
    }while(Clock == false);
  }
  if(New_Card == true){
    do{
      myGLCD.invertText(true);
      myGLCD.print("D.New Card", 0, 40);
      myGLCD.invertText(false);
      // If selected, approximate a new card or key tag to scan and save the new UID to EEPROM.
      if(OK == true){
        myGLCD.clrScr();
        Activated = true;
        myGLCD.print("Approximate", 0, 0);
        myGLCD.print("a new card or", 0, 8);
        myGLCD.print("key tag to", 0, 16);
        myGLCD.print("scan and save", 0, 24);
        myGLCD.print("the new UID to.", 0, 32);
        myGLCD.print("EEPROM :)", 0, 40);
        while(Activated == true){
          // Read control variables.
          read_control_buttons();
          // Register a new UID (card or tag) to save it to the EEPROM.
          register_new_card();
          // Exit.
          if(Exit == true){ Activated = false; myGLCD.clrScr(); }
        }
      }
    }while(New_Card == false);
  }
}

void read_control_buttons(){
  // Read the control buttons:
  Right = digitalRead(B_Right);
  OK = digitalRead(B_OK);
  Left = digitalRead(B_Left);
  Exit = digitalRead(B_Exit);
    
}

void send_command_to_MP3_player(int8_t command[], int len){
  Serial.print("\nMP3 Command => ");
  for(int i=0;i<len;i++){ MP3.write(command[i]); Serial.print(command[i], HEX); }
  delay(1000);
}

void get_time_rtc(){
  //  The following lines can be uncommented to set the date and time manually.
  //  rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to Wednesday
  //  rtc.setTime(18, 13, 15);     // Set the time to 12:00:00 (24hr format)
  //  rtc.setDate(17, 10, 2018);   // Set the date to October 17st, 2018

  // Get the current hour and minute from DS3231. // t.hour; and t.min;
  t = rtc.getTime();
}

void register_new_card(){
  // Detect the new card UID. 
  if ( ! mfrc522.PICC_IsNewCardPresent()) { return 0; }
  if ( ! mfrc522.PICC_ReadCardSerial()) { return 0; }

  // Display the new UID.
  for (int i = 0; i < mfrc522.uid.size; i++) { 
    readCard[i] = mfrc522.uid.uidByte[i];
  }
  
  // Save the new UID to EEPROM. 
  // If you want to save another card, use i+4(...) instead i.
  for (int i = 0; i < mfrc522.uid.size; i++){
    EEPROM.write(i, readCard[i]);
  }
 
  mfrc522.PICC_HaltA();
  // Return the success message.
  myGLCD.clrScr();
  myGLCD.print("Registered", 0, 8); 
  myGLCD.print("Successfully!", 0, 24);
  
}

void get_the_registered_UID(){
  // Get the registered UID from EEPROM.
  for(int i=0;i<4;i++){
    registeredUID += EEPROM.read(i) < 0x10 ? " 0" : " ";
    registeredUID += String(EEPROM.read(i), HEX);
  }
  // Arrange registeredUID for comparing.
  registeredUID.trim();
  registeredUID.toUpperCase();

  Serial.println("\nRegistered UID => " + registeredUID);
}

void get_the_last_detected_UID(){
  if ( ! mfrc522.PICC_IsNewCardPresent()){ return 0; }
  if ( ! mfrc522.PICC_ReadCardSerial()){ return 0; }
  for(int i=0;i<mfrc522.uid.size;i++){
    lastRead += mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ";
    lastRead += String(mfrc522.uid.uidByte[i], HEX);
   }
   // Arrange lastRead for comparing.
   lastRead.trim();
   lastRead.toUpperCase();

   Serial.println("\nLast Detected UID => " + lastRead);
}

void home_screen(){
  // Define options.
  myGLCD.print("Menu Commands:", 0, 0);
  myGLCD.print("A.Init Checker", 0, 16);
  myGLCD.print("B.Set Checker", 0, 24);
  myGLCD.print("C.Clock", 0, 32);
  myGLCD.print("D.New Card", 0, 40);
}

void select_menu_commands(){
  // Increase or decrease the option number using Right and Left buttons.
  if(Right == true) selected++;
  if(Left == true) selected--;
  if(selected < 0) selected = 4;
  if(selected > 4) selected = 1;
  delay(300);
  // Depending on the selected option number, change boolean status.
  switch(selected){
    case 1:
      Init_Checker = true;
      Set_Checker = false;
      Clock = false;
      New_Card = false;
    break;
    case 2:     
      Init_Checker = false;
      Set_Checker = true;
      Clock = false;
      New_Card = false;
    break;
    case 3:
      Init_Checker = false;
      Set_Checker = false;
      Clock = true;
      New_Card = false;
    break;
    case 4:
      Init_Checker = false;
      Set_Checker = false;
      Clock = false;
      New_Card = true;
    break;
  }
}


Schematics

project-image
Schematic - 45.1


project-image
Schematic - 45.2

Downloads

Gerber

Download


Fabrication

Download



Serial MP3 Player Manual by OPEN-SMART

Download


Clock (Icon)

Download


Spider-Man (Icon)

Download