Doug Domke
Published © GPL3+

An Alarm Clock with No Buttons

Everything about this alarm clock is controlled from your smart phone using the Arduino Cloud. And it sets itself using NTP time.

IntermediateFull instructions provided4 hours1,281

Things used in this project

Hardware components

Arduino Nano ESP32
×1
4 Digit 7 Segment LED Display
×1
Piezo buzzer Module
×1
USB-A to USB C Cable
×1
USB Wall Brick Charger
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Case for Alarm Clock

This is an STL 3D object file - used by 3D slicer software to generate 3D printer file.

Base of Alarm Clock

This is an STL 3D object file - used by 3D slicer software to generate 3D printer file.

Schematics

Alarm Clock Schematic

Code

Arduino Cloud Controlled Alarm Clock

Arduino
This is the main file, where all the user generated code goes. The Arduino Cloud also generated the thingProperties.h and Secret files that are required for the complete software package.
/*
  Arduino IoT Cloud Variables description
  The following variables are automatically generated and updated when changes are made to the Thing

  int alarmHour;
  int alarmMinute;
  int gMToffset;  // Although this is an interger, the dashboard control for it doesn't like negative
  bool alarmOff;  // numbers.  Therefore, we store offset+11 here and subtract it out in getNTPtime.
  bool alarmOn;
  bool alarmSet;
  bool dayLightSaving;
  bool setLocalTime;
  bool twelveHourClock;

*/

#include "thingProperties.h"
#include "time.h"
#include "HT16K33.h"

HT16K33 fourDigits(0x70);  // create 7 segment display object
const char* ntpServer = "pool.ntp.org";
int daylightOffset_sec = 0;
bool alarmSound = false;
int myhour, mymin; // used to check time against alarm setting

void setup() {
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  // Set up 4 digit, 7 segment display
  fourDigits.begin();
  Wire.setClock(100000);
  fourDigits.displayOn();
  fourDigits.setDigits(4);
  // Set up buzzer 
  pinMode(3, OUTPUT);  // pin3 is the alarm buzzer
  digitalWrite(3, HIGH);
  // Set time from NTP server
  getNTPtime();
}

void loop() {
  ArduinoCloud.update();
  // zero the display until local time is available
  if (millis() < 15000) fourDigits.displayTime(0, 0, true, true);
  else displayLocalTime();
  if (alarmSet && myhour == alarmHour && 
     (mymin == alarmMinute || mymin == alarmMinute+1)) alarmSound = true;
  else alarmSound = false;
}

void displayLocalTime() {
  struct tm mytime;
  getLocalTime(&mytime);
  int myHour = mytime.tm_hour;
  int myMins = mytime.tm_min;
  int mySecs = mytime.tm_sec;
  myhour = myHour;
  mymin = myMins;
  if (myHour > 12 && twelveHourClock) myHour -= 12;
  Serial.println(&mytime, "%A, %B %d %Y %I:%M:%S");
  fourDigits.displayTime(myHour, myMins, true, true);
  fourDigits.displayColon(1);
  if (alarmSound) digitalWrite(3, LOW);
  delay(500);
  digitalWrite(3, HIGH);
  fourDigits.displayColon(0);
  while (mySecs == mytime.tm_sec) { // wait until seconds change
    delay(10);
    getLocalTime(&mytime);
  }
  
}

void getNTPtime() {
  if (dayLightSaving == true) daylightOffset_sec = 3600;
  else daylightOffset_sec = 0;
  // gMToffset is the offset+11, to keep it a positive number.  So we have to subtract the 11 here.
  configTime((gMToffset - 11) * 3600, daylightOffset_sec, ntpServer);
}

void onAlarmHourChange()  {
  // Add your code here to act upon AlarmHour change
}
void onAlarmMinuteChange()  {
  // Add your code here to act upon AlarmMinute change
}
void onAlarmOnChange()  {
  if (alarmOn) {
    alarmSet = true;
  }
}
void onAlarmOffChange()  {
  if (alarmOff) {
    alarmSet = false;
  }
}
void onGMToffsetChange()  {
  getNTPtime();
}
void onTwelveHourClockChange()  {
  getNTPtime();
}
void onDayLightSavingChange()  {
  getNTPtime();
}
void onAlarmSetChange()  {
  // Add your code here to act upon AlarmSet change
}

Credits

Doug Domke

Doug Domke

38 projects • 104 followers

Comments