Project tutorial

Talking Clock 2 - New Version (Bilingual: EN-PT) © CC BY-NC-ND

This digital clock speaks the time in two languages (English or Portuguese).

  • 10,708 views
  • 27 comments
  • 42 respects

Components and supplies

Apps and online services

About this project

1) Introduction

The Talking Clock 2 (Bilingual) is the new version of Talking Clock I have published some time ago.

The code was updated to support two languages (English/Portuguese) and new features were introduced into the code:

  • Mode 1: Set the time (hour & minute)
  • Mode 2: The clock talks every minute
  • Mode 3: The clock talks every hour
  • Mode 4: The clock speaks the time when a button is pressed
  • Mode 5: Set the language for English or Portuguese

Note: The language status is stored in Arduino - EEPROM to keep this information even when it is restarted or turned on.

It was introduced as optional a mini amplifier PAM8403 (3W + 3W) for better control of the sound level in the speaker. I am using only one speaker (one sound channel), but you can add another if you want.

Video

2) Components

Note: Details of DFPlayer Mini on: https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

3) Schematics

Important: It is not recommended to use the USB port as a power source in this project. Connect the Arduino to an external power source of 9V x 1A (or higher) because there are power surges when the speaker is working, causing Arduino instability.

4) SD Card & MP3 files

A SD card must be formatted for FAT32 and a folder named "MP3" must be created. In MP3 folder are stored all files of voices (74 in total) in English and Portuguese.

In mode 3, when the clock speaks every hour, there is a "church bell" sound that only works between 08:00 and 18:00. This sound is repeated as many times as the hour of that moment.

Note: All files must be named according to pattern "nnnn.mp3", starting in "0000.mp3".

5) Setup

There are 3 push buttons used for the operation with following functions:

#1:

  • Moves to the next operational mode.

#2:

  • Adjust the hour in Setup Mode
  • Speaks the time in Press Button Mode
  • Set to Portuguese in Language Mode.

#3:

  • Adjust the minute in Setup Mode
  • Speaks the time in Press Button Mode
  • Set to English in Language Mode.

Note: To move to next mode, press the button #1 until the next speech starts (blue LED of DFPlayer is on in this moment).

Code

Talking_Clock_2_English_Portuguese_V1_2.inoArduino
Code for Arduino UNO
/* 
  Project:     Talking Clock 2 (English-Portuguese)
  Hardware:    Arduino UNO R3 - DFRobot DFPlayer Mini MP3
  Revision:    1.2
  Date:        17.Feb.2018
  Author:      LAGSILVA
  License:     CC BY-NC-ND 4.0
               (Attribution-NonCommercial-NoDerivatives 4.0 International)
  ------------------------------------------------------------------------
  Notes:
  1) All MP3 files name must be numered as "/MP3/nnnn.mp3"
     Ex: "/MP3/0000.mp3", "/MP3/0001.mp3", "/MP3/0002.mp3", ...
  2)  ** New Library: DFRobotDFPlayerMini **
  ------------------------------------------------------------------------
*/

//#include <DFPlayer_Mini_Mp3.h>    //Library of DFPlayer (module to play MP3 files)

#include <SoftwareSerial.h>       // Library to support DFPlayer
#include <DFRobotDFPlayerMini.h>  // Library for DFPlayer (module to play MP3 files)
#include <TM1637Display.h>        // Library for TM1637 Display (4 digitis x 7 segments)
#include <Time.h>                 // Time Library
#include <TimeLib.h>
#include <EEPROM.h>               // Library to read/write on EEPROM

SoftwareSerial mySoftwareSerial(3, 4);    // RX, TX
DFRobotDFPlayerMini myMP3;

byte ajustaModo = 7;              // Switch of Mode
byte ajustaHora = 6;              // Switch of Hours
byte ajustaMinuto = 5;            // Switch of Minutes

byte hora, minuto, modo, ultimoMinuto, ultimaHora, dezHora, uniHora, idioma, ultimoIdioma, bloqueio, tipo;

int vol, pinVol = 0;              // Volume Control by POT (Arduino pin: A0)

// Module connection pins (Digital Pins)
#define CLK 10                    // Arduino Conection on Pin #10 = CLK of Display Module
#define DIO 11                    // Arduino Conection on Pin #11 = DIO of Display Module

TM1637Display display(CLK, DIO);

//
//      A
//     ---
//  F |   | B
//     -G-
//  E |   | C
//     ---
//      D
//

uint8_t dataWithColon[] = {
  0b10111111, // 0
  0b10000110, // 1
  0b11011011, // 2
  0b11001111, // 3
  0b11100110, // 4
  0b11101101, // 5
  0b11111101, // 6
  0b10000111, // 7
  0b11111111, // 8
  0b11101111, // 9
  0b00000000, // 10
};


void setup()
{

  idioma = EEPROM.read(0);            // Read the EEPROM the Language Status: (0 = English / 100 = Portuguese)
  ultimoIdioma = idioma;

  mySoftwareSerial.begin(9600);       // Set serial for DFPlayer-mini mp3 module
  myMP3.begin(mySoftwareSerial);      // Begin MP3

  myMP3.volume (28);                  // Set Volume (0-30max)

  myMP3.EQ(DFPLAYER_EQ_ROCK);         // Set EQ
  // myMP3.EQ(DFPLAYER_EQ_NORMAL);
  // myMP3.EQ(DFPLAYER_EQ_POP);
  // myMP3.EQ(DFPLAYER_EQ_JAZZ);
  // myMP3.EQ(DFPLAYER_EQ_CLASSIC);
  // myMP3.EQ(DFPLAYER_EQ_BASS);

  display.setBrightness (10);         // Set Brightness (0 to 15 Max)

  pinMode(ajustaModo, INPUT_PULLUP);
  pinMode(ajustaMinuto, INPUT_PULLUP);
  pinMode(ajustaHora, INPUT_PULLUP);

  modo = 0;
  ultimoMinuto = -1;
  ultimaHora = -1;

  myMP3.playMp3Folder (60 + idioma);  // Play the Setting Mode
  delay(3000);

}


void loop() {

  hora = hour();
  minuto = minute();

  dezHora = hora / 10;
  uniHora = hora % 10;

  display.showNumberDec(dezHora, true, 1, 0);
  display.setSegments(dataWithColon + uniHora, 1, 1);
  display.showNumberDec(minuto, true, 2, 2);

  if (bloqueio == 1) {
    delay(500);
    display.showNumberDec(uniHora, true, 1, 1);
    delay(500);
  }

  if (digitalRead(ajustaHora) == LOW && bloqueio == 0) {    //Setup of hours
    ultimaHora = -1;
    adjustTime(3600);
    delay(200);
  }

  if (digitalRead(ajustaMinuto) == LOW && bloqueio == 0) {  //Setup of Minutes
    ultimoMinuto = -1;
    adjustTime(60);
    delay(200);
  }

  if (digitalRead(ajustaModo) == LOW) { // Mode Setup
    modo += 1;
    modo = modo % 5;
    delay(200);

    if (modo == 0) {                    // Play "Set The Time" mode
      display.setBrightness(10);        // Turn "on" the display
      myMP3.playMp3Folder (60 + idioma);
      delay(4000);
      bloqueio = 0;
    }

    if (modo == 1) {                    // Play "Minute" mode
      display.setBrightness(0);         // Turn "off" the display
      ultimoMinuto = minuto;
      myMP3.playMp3Folder (61 + idioma);
      delay(4000);
      bloqueio = 1;
    }

    if (modo == 2) {                    // Play "Hour" mode
      ultimaHora = hora;
      myMP3.playMp3Folder (62 + idioma);
      delay(4000);
      bloqueio = 1;
    }

    if (modo == 3) {                    // Play "Press to Talk" mode
      myMP3.playMp3Folder (63 + idioma);
      delay(4000);
      bloqueio = 1;
    }

    if (modo == 4) {                    // Setup Language (English or Portuguese)
      myMP3.playMp3Folder (64 + idioma);
      delay(4000);
      bloqueio = 1;
    }

  }

  switch (modo) {

    case 1:                             // Play All Minutes

      if (minuto != ultimoMinuto) {

        ultimoMinuto = minuto;

        display.setBrightness(10);

        display.setSegments(dataWithColon + uniHora, 1, 1);

        tipo = 1;                       // Tipo: (1 = Hour / 0 = Minute)

        fala(hora);

        if (hora > 1) {
          myMP3.playMp3Folder(22 + idioma);     // Play "hours" / "horas"
          delay(1000);
        }

        if (hora <= 1) {
          myMP3.playMp3Folder(21 + idioma);     // Play "hour" / "hora"
          delay(1000);
        }

        if (minuto > 0) {

          myMP3.playMp3Folder(23 + idioma);     // Play "and" / "e"
          delay(500);

          tipo = 0;                     // Tipo: (1 = hour / 0 = minute)

          fala(minuto);

          if (minuto > 1) {
            myMP3.playMp3Folder (25 + idioma);  // Play "minutes"
            delay(1000);
          } else {
            myMP3.playMp3Folder (24 + idioma);  // Play "minute"
            delay(1000);
          }

        }

        display.setBrightness(0);

      }

      break;


    case 2:                         // Play only o'clock Hours

      if (hora != ultimaHora) {
        ultimaHora = hora;

        display.setBrightness(10);

        display.setSegments(dataWithColon + uniHora, 1, 1);

        tipo = 1;                   // Tipo: (1 = hour / 0 = minute)

        fala(hora);

        myMP3.playMp3Folder(26 + idioma);      // Play "o'clock" / "em ponto"
        delay(2000);

        if (hora >= 8 && hora <= 18) {
          for (int k = 1; k <= hora % 12; k++) {
            myMP3.playMp3Folder(65 + idioma); // Play "Bell Church" between 08:00hs to 18:00hs
            delay(2500);
          }
        }

        display.setBrightness(0);

      }

      break;


    case 3:       // Press Button to Talk Mode

      if (digitalRead(ajustaMinuto) == LOW || digitalRead(ajustaHora) == LOW && bloqueio == 1) { // Press button

        display.setBrightness(10);

        display.setSegments(dataWithColon + uniHora, 1, 1);

        tipo = 1;                   // Tipo: (1 = hour / 0 = minute)
        fala(hora);

        if (minuto == 0) {
          myMP3.playMp3Folder(26 + idioma);
        }

        if (minuto != 0) {

          myMP3.playMp3Folder(23 + idioma);     // Play "and" / "e"
          delay(500);

          tipo = 0;                  // Tipo: (1 = hour / 0 = minute)
          fala(minuto);

        }

        display.setBrightness(0);

      }

      break;


    case 4:       // Setup the Language (0 = English / 100 = Portuguese)

      if (digitalRead(ajustaMinuto) == LOW && bloqueio == 1) {  // Setting to English language
        idioma = 0;
        delay(200);
      }

      if (digitalRead(ajustaHora) == LOW && bloqueio == 1) {    // Setting to Portuguese language
        idioma = 100;
        delay(200);
      }

      if (ultimoIdioma != idioma) {
        EEPROM.update(0, idioma);
        ultimoIdioma = idioma;
        myMP3.playMp3Folder (64 + idioma);
        delay(2000);
      }

      break;

  }

}


void fala(byte tempo) {                         // Speak the Time

  byte dezTempo = tempo / 10 * 10;
  byte uniTempo = tempo % 10;


  if (idioma == 0) {                            // English language

    if (tempo <= 19) {
      myMP3.playMp3Folder(tempo + idioma);
      delay(1000);
    }

    if (tempo >= 20) {

      myMP3.playMp3Folder(dezTempo + idioma);
      delay(1000);

      if (tempo % 10 != 0) {
        myMP3.playMp3Folder(uniTempo + idioma);
        delay(1000);
      }

    }

  }


  if (idioma == 100) {                          // Portuguese language

    if (tipo == 0) {                            // Play Minutes in Portuguese - Tipo: (1 = hour / 0 = minute)

      if (tempo <= 19) {
        myMP3.playMp3Folder(tempo + idioma);
        delay(1000);
      }

      if (dezTempo >= 20) {
        myMP3.playMp3Folder(dezTempo + idioma);
        delay(1000);

        if (tempo % 10 != 0) {                      // If language is Portuguese
          myMP3.playMp3Folder(123);                 // Play "e"
          delay(500);
          myMP3.playMp3Folder(uniTempo + idioma);
          delay(1000);
        }

      }

    }


    if (tipo == 1) {                                // Play Hours in Portuguese

      if (tempo > 2 && tempo <= 20 || tempo == 0) {
        myMP3.playMp3Folder(tempo + idioma);
        delay(1000);
      }

      if (tempo == 1 || tempo == 2) {               // Play "uma" - "duas"
        myMP3.playMp3Folder(126 + uniTempo);
        delay(1000);
      }

      if (tempo >= 21) {
        myMP3.playMp3Folder(dezTempo + idioma);
        delay(1000);

        myMP3.playMp3Folder(123);                   // Play "e"
        delay(500);

        if (tempo == 21 || tempo == 22) {
          myMP3.playMp3Folder(126 + uniTempo);
          delay(1000);
        } else {
          myMP3.playMp3Folder(uniTempo + idioma);
          delay(1000);
        }

      }

    }

  }

}

Custom parts and enclosures

Voice Files in MP3
Voice files in MP3
uploads2ftmp2f2911eb72-74bb-4a54-a42e-1210766de1c52fmp3_Ht6zjhguw2.zip

Comments

Similar projects you might like

Analog Clock with LED Matrix and Arduino

Project tutorial by LAGSILVA

  • 12,245 views
  • 8 comments
  • 39 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 12,679 views
  • 11 comments
  • 50 respects

4-Stroke Digital Clock With Arduino

Project showcase by LAGSILVA

  • 11,105 views
  • 9 comments
  • 39 respects

Adjusting Dual Clock using DS3231 on 1.8" ST7735 Display

Project showcase by FLORICA Tudor-Nicusor

  • 3,968 views
  • 2 comments
  • 11 respects

Talking Clock

Project tutorial by Team moty

  • 2,702 views
  • 1 comment
  • 6 respects

Tri-Mode Digital Clock With ATtiny85 And RTC

Project showcase by LAGSILVA

  • 5,207 views
  • 0 comments
  • 19 respects
Add projectSign up / Login