Project showcase
Tooth Fairy's Favorite Arduino Project

Tooth Fairy's Favorite Arduino Project © GPL3+

A Nano powered alarm clock without a real time clock in a floss container...

  • 460 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
4966285
Solder Wire, Lead Free

Apps and online services

About this project

Well, in my earlier adventures of programming Arduino, I wanted to make an alarm clock. I could have made a good one by taking a tutorial, but I've always liked learning with little to no outside help. A young Arduino student, without a tutorial, got cracking.

So, with my strange learning style, (or unhealthy levels of project stubbornness) I decided to start. My design idea was simple: make a very small alarm clock without a display or real time clock. I even wanted to use a Digispark for even smaller size but eventually after code problems and the Spark's limitations I ended up using the Nano.

Anyway, the struggle began. Without using a real time clock (it's technically just a timer now), I would need to make massive delays variables. Note to everyone, I will scream it to the world: Know your data types. I caused myself loads of problems when I maxed out an int probably many times over trying to store huge second time delays.

Anyway, after maybe 3-4 months of programming and designing on and off, I finally got it going somewhere. As you can see, learning without a guide is time consuming, but most likely more memorable. After many, many breadboard attempts, I got a working model going. I Decided to power it on a drone battery, with a simple power bypass to run the Nano on 3.7V. Here's some picture of the circuit I eventually made (yeah it ain't pretty).

Honestly, I didn't need the 10K resistors, I could have just made the code set to have built in resistors turned on, but I didn't really care.

Without a display (would have burned way to much power and lot of wiring) I would need a system of communication. Anyways, here's how it works. Press the increment button to select how many hours you want to wait for until turning on the buzzer for wake up. The code will automatically run for the amount of led flashes (indicating the number of hours) if you don't press the increment button to increase it. When it's time to wake up, the Nano pulses the buzzer. I put a snooze feature into it as well.

The secret part about this project is that it also doubles as a stop watch. Press one button to start the timer, press another to stop, and then it "read" the value in a very steampunk, redundant way. Flash the number of seconds, then a short buzzer tone to indicate decimal point, then continue. Not very efficient at all but fun little add on.

Honestly, it could have been way better, code and hardware choices both. Really this is just a product of what happens when no tutorials and developing skills clash together to create something redundantly beautiful.

Hope you guys like it and tell me what you think!

Code

No RTC alarm clock (just a Timer really)Arduino
Quite a redundant code honestly. Could be way better and optimized.
int ledPin = 3;
int buzzerPin = 2;
int fq = 440;
int startbuttonPin = 12;
int startbuttonPowerPin = 10;
int stopbuttonPin = 8;
int stopbuttonPowerPin = 6;

int val = 6;
int compareval;
int stateofbutton;

const unsigned long sixHour = 21600000;
const unsigned long sevenHour = 25200000;
const unsigned long eightHour = 28800000;
const unsigned long nineHour = 32400000;
const unsigned long tenHour = 36000000;
const unsigned long elevenHour = 39600000;
const unsigned long twelveHour = 43200000;

unsigned long startTime, stopTime, savedTime;
String stringSavedSeconds, stringSavedMilliseconds, selectedChar;
int startState, stopState, s, sIndex, ms, msIndex, msShortIndex, outputNum;

void stopWatch(){
startState = digitalRead(startbuttonPin);
stopState = digitalRead(stopbuttonPin);
digitalWrite(buzzerPin, LOW);
if (startState == HIGH){
  startTime = millis();
  delay(200); // debounce, very needed
  digitalWrite(ledPin, HIGH);
}
if (stopState == HIGH){
  stopTime = millis();
  delay(200); // debounce
  digitalWrite(ledPin, LOW);
  delay(1000);
  savedTime = stopTime - startTime;
  createTime();
  stringSavedSeconds = String(s);   //convert int s to string
  sIndex = stringSavedSeconds.length(); //find length, use as index
  for (unsigned int x = 0; x < sIndex; x++){
    selectedChar = stringSavedSeconds.charAt(x);// find certain number
    outputNum = selectedChar.toInt();  // change string number to int
    indicate(outputNum);
    delay(1000);    //delay between numbers          
    }
    delay(500);
    decimalPoint();
    delay(500);
  stringSavedMilliseconds = String(ms);
  msIndex = stringSavedMilliseconds.length();
  msShortIndex = msIndex - 2; // dont need high precision
    for (unsigned int y = 0; y < msShortIndex; y++){
    selectedChar = stringSavedMilliseconds.charAt(y);
    outputNum = selectedChar.toInt();
    indicate(outputNum);
    delay(1000);    //delay between numbers
    }
  }
}
void createTime(){
  s = int(savedTime/1000); // create seconds
  ms = int(savedTime%1000); //create ms from remainder of saved time
}
void decimalPoint(){
   tone(buzzerPin,fq);// short beep to show decimal point
   delay(25); 
   noTone(buzzerPin);
   digitalWrite(buzzerPin, LOW);
}
void snoozeButton(){    
   if (startState == HIGH){  
   delay(120000); // 2 minutes
  }
}
void indicate(int Nblink)
{
  for (int i = 0; i < Nblink; i++)
  {
    digitalWrite(ledPin,HIGH); 
    delay(400);
    digitalWrite(ledPin,LOW);
    delay(400);
  }
}
void setAlarm(int readyDelay){
digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(100);
digitalWrite(ledPin,HIGH);// double quick blink, indicating setAlarm has started 
delay(100);

digitalWrite(ledPin,LOW);// making sure I'm not using extra power from battery
digitalWrite(buzzerPin,LOW);
if (readyDelay == 6){
delay(sixHour);
}
if (readyDelay == 7){ // probably needs a switch statment
delay(sevenHour);
}
if (readyDelay == 8){
delay(eightHour);
}
if (readyDelay == 9){
delay(nineHour);
}
if (readyDelay == 10){
delay(tenHour);
}
if (readyDelay == 11){
delay(elevenHour);
}
if (readyDelay == 12){
delay(twelveHour); 
}
   for (int w = 0; w <= 50; w++)
   {
   tone(buzzerPin,fq);
   delay(400);
   noTone(buzzerPin);
   delay(400);
   snoozeButton();
   }
}

void setup() {
pinMode(ledPin,OUTPUT);
pinMode(buzzerPin,OUTPUT);
pinMode(startbuttonPin, INPUT);
pinMode(stopbuttonPin, INPUT);

pinMode(startbuttonPowerPin, OUTPUT);
pinMode(stopbuttonPowerPin, OUTPUT);
digitalWrite(startbuttonPowerPin, HIGH);
digitalWrite(stopbuttonPowerPin, HIGH);

digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(2000);
}

void loop() {
delay(1000);
startState = digitalRead(startbuttonPin);
stopState = digitalRead(stopbuttonPin);
if (stopState == HIGH){
  digitalWrite(ledPin, HIGH);
  delay(50);
  digitalWrite(ledPin, LOW);
  delay(3000);
  while(true){
    stopWatch();
    }
  }
  else{
  compareval = val;
  indicate(val);
  delay(2000);
  startState = digitalRead(startbuttonPin);
  if (startState == HIGH){   
    compareval = val;
    val = val + 1;
  }
  else{
  setAlarm(val); 
}
indicate(val);
delay(2000);
  startState = digitalRead(startbuttonPin);
  if (startState == HIGH){   
    compareval = val;
    val = val + 1;
  }
  else{
  setAlarm(val);  
  }
  if( val > 12){
    val = 6;
    }
  }
}

Comments

Similar projects you might like

Pomodoro Timer Using Arduino

Project tutorial by Amal Mathew and FEBIN

  • 4,759 views
  • 0 comments
  • 3 respects

Tetris Shield on an Arduino Mega

Project showcase by Sherwin Chiu

  • 2,865 views
  • 1 comment
  • 11 respects

Arduino Controlled LED Multi-Player Game on Arduino "Shield"

Project tutorial by 22warehamD

  • 4,512 views
  • 3 comments
  • 14 respects

Arduino Button Troubleshooting

Project showcase by 3 developers

  • 4,053 views
  • 1 comment
  • 0 respects

Doggo Water Bowl Refill Monitor/Indicator - Part 1

Project tutorial by HeathenHacks

  • 2,754 views
  • 2 comments
  • 8 respects

RFID Desk Lamp with RGB Color Scheme Lock

Project tutorial by Kutluhan Aktar and JLCPCB

  • 2,405 views
  • 1 comment
  • 4 respects
Add projectSign up / Login