mPelectronic
Published © CC BY-NC

Arduino DIY Clock

Arduino DIY Clock with energy saving mode and a 3D printed case!

IntermediateShowcase (no instructions)2,653
Arduino DIY Clock

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Real Time Clock (RTC)
Real Time Clock (RTC)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Just for the case, not necessary
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

STL files

Schematics

Librarys

Code

The code:

C/C++
/*
 *    1.0
 *  : 1.4
 * :  
*/

#include <LowPower.h>
#include <Adafruit_GFX_rus.h>
#include <Adafruit_PCD8544_rus.h>
Adafruit_PCD8544 nokia = Adafruit_PCD8544(4, 3, 6, 7, 8); //CLK, DIN, DC, CE, RST

/*
 * : 
 *
 *   -->   
 *(1)RST    -->   8 pin
 *(2)CE     -->   7 pin
 *(3)DC     -->   6 pin
 *(4)DIN    -->   3 pin
 *(5)CLK    -->   4 pin
 *(6)VCC    -->   10 pin     !!!     !!!
 *(7)LIGHT  -->   -----     (     . 
 *                                .      .)
 *(8)GND    -->   GND
 *
 *  2 .
 *
*/

/*
 *    :
 *    IC:
 *    -->   
 * SDA      -->     A4
 * SCL      -->     A5
 * ====   ====
 * VCC      -->     3.3V
 * GND      -->     GND
*/

extern uint8_t logo[];

#include <iarduino_RTC.h>                            //   iarduino_RTC      .
iarduino_RTC time(RTC_DS1307);                       //   time    RTC     DS3231,    I2C

//=================   ===================
volatile int sec = 15;
volatile int minute = 8;
volatile int hour = 15;
volatile int date = 22;
volatile int Month = 6;
volatile int Year = 18;
volatile int weekDay = 5;
//==================================================


int day;
int month;
volatile boolean sleep = false;

#define powerBtn 2
#define dispPower 10

void setup() {
  delay(3000);              // !      5. 
                            //       ,  5   
  pinMode(dispPower, OUTPUT);
  digitalWrite(dispPower, HIGH);
  pinMode(powerBtn, INPUT_PULLUP);
  
  delay(300);                                                            //      
  time.begin();                                                          //    .
  time.settime(sec,minute,hour,date,Month,Year,weekDay);                 //    : 0 , 51 , 21 , 27, , 2015 , .
  
  nokia.begin();
  nokia.clearDisplay(); 
  nokia.setContrast(55);
  nokia.drawBitmap(0, 0, logo, 84, 48, BLACK);       //  Pe
  nokia.display();
  delay(1500);
  nokia.clearDisplay();
  nokia.drawLine(0, 20, 84, 20, BLACK);
  nokia.display();
}

//==========     !!!  =========
void wake_up() {
  digitalWrite(dispPower, HIGH);
  sleep = false;
  nokia.begin();
  nokia.clearDisplay(); 
  nokia.setContrast(55);
  nokia.display();
  detachInterrupt(0);
  nokia.drawBitmap(0, 0, logo, 84, 48, BLACK);       //  Pe
  nokia.display();
}
//===========================================================

void loop() {
  //==========          ==========
  if (sleep == false && digitalRead(powerBtn) == 0) {
    nokia.clearDisplay();
    nokia.drawBitmap(0, 0, logo, 84, 48, BLACK);       //  Pe
    nokia.display();
    delay(1000);
    digitalWrite(dispPower, LOW);
    sleep = true;
    delay(1000);
    attachInterrupt(0, wake_up, LOW);
    if (sleep == true) {LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);}
  }
  //=========================================================================

  LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF);       //      250 

  //==========    ==========
  nokia.clearDisplay();
  nokia.drawLine(4, 25, 80, 25, BLACK);                 //  
  time.gettime();                                       //   
  nokia.setTextSize(2);                                 //   2 
  nokia.setCursor(5,5);                                 //  (5     5  y)
  nokia.print(time.Hours);                              // 
  nokia.setTextSize(3);                                 //   3 
  nokia.setCursor(25,2);                                // 
  nokia.print(":");
  nokia.setTextSize(2);
  nokia.setCursor(40,5);
  nokia.print(time.minutes);                            // 
  nokia.setTextSize(1);
  nokia.setCursor(68,5);
  nokia.print(time.seconds);                            // 
  //=====================================

  //================     ===================
  nokia.setCursor(13,30);
  time.gettime();
  //================  )))  =================
  day = time.weekday;
  switch (day) {
    case 0: 
      nokia.print(",");
      break;
    case 1: 
      nokia.print(",");
      break;
    case 2:
      nokia.print(",");
      break;
    case 3:
      nokia.print(",");
      break;
    case 4:
      nokia.print(",");
      break;
    case 5:
      nokia.print(",");
      break;
    case 6:
      nokia.print(",");
      break;
  }
  //====================================================
  nokia.setCursor(40,30);
  nokia.print(time.gettime("d.m"));
  nokia.setCursor(10,40);
  month = time.month;
  switch (month) {
    case 1: 
      nokia.print(", ");
      break;
    case 2: 
      nokia.print(", ");
      break;
    case 3:
      nokia.print(", ");
      break;
    case 4:
      nokia.print(", ");
      break;
    case 5:
      nokia.print(", ");
      break;
    case 6:
      nokia.print(", ");
      break;
    case 7:
      nokia.print(", ");
      break;
    case 8:
      nokia.print(", ");
      break;
    case 9:
      nokia.print(", ");
      break;
    case 10:
      nokia.print(", ");
      break;
    case 11:
      nokia.print(", ");
      break;
    case 12:
      nokia.print(", ");
      break;
  }

  nokia.print(time.gettime("Y"));
  //===================================================
  
  nokia.display();
}

Credits

mPelectronic

mPelectronic

3 projects • 23 followers

Comments