baby and child alarm clock

Arduino alarm clock for baby

Arduino alarm clock for baby

The purpose of this post was to create an alarm clock form my 2 year old son. I’m lucky he is sleeping well but is waking up before I do and generally call me and mum to go out of the bed, then play in his room … So the problem is that he never know if can wake up and play or if it is too early and have to stay in the bed. For this reason I created this alarm clock to easily indicate him if it is sleep or play time.

The system is quite simple : you program the number of hour you want him to sleep. During sleep time a led display a pink color. After this configured duration, the color change for green. When green, my son is allowed to wake up and play in his room

The post describe how to do it based on an arduino nano.

What is needed to do this arduino based alarm clock ?

  • an Arduino Mini (any arduino by-the-way)
  • a RGB led
  • 3 x 330 ohm resitor
  • 1 push switch

Schematics

 

arduino alarm clock

arduino alarm clock

Basically the system is managing a RGV led with 3 GPIO and have a push button on a fourth one to configure the sleeping time.

How will it works (Mum functional analysis) ?

The system will boot and flash 3 times in blue to indicate it is starting. Then it will wait the next 10 seconds to enter the number of hour of sleeping time. If you do nothing, the default sleeping time will be 12 hours. If you click on the button, the number of click will be the number of hours. The end of the setting will be detected if no click append in the last 5 seconds.

Once set, the number of sleeping hour will be displayed by blinking the led for every hour in a pink color.

If you are not satisfied by this setting the system will wait for 5 more second to get a new sleeping time by counting new button push.

Once the sleeping time accepted, the color will change for a purple fixed color indicating the sleeping period. The led will switch to green at the end of the sleeping time.

The system will be reseted by pushing the button once in this state.

Take a look to some code

int vert = 3;
int rouge = 4;
int bleu = 5;
int bouton = 7;
int sommeil = 12;


/* ------------------------------------------
 * Setup - configure the different pins
 *       - get the sleeping time
 * ------------------------------------------
 */
void setup() {
  // GPIO Setup
  pinMode(vert,OUTPUT);
  pinMode(bleu,OUTPUT);
  pinMode(rouge,OUTPUT);
  pinMode(bouton,INPUT_PULLUP);

  // switch led off
  digitalWrite(vert,HIGH);
  digitalWrite(bleu,HIGH);
  digitalWrite(rouge,HIGH);
 
  // blink 3 time for fun
  startup();

  // Get the number of hour of the sleeping period by counting
  // clicks on button
  int init = 1;
  boolean notConfigured = true;
  while ( notConfigured ) { 
    // In the first 10 second, user is suppose to click to
    // indicate the number of hour or default will be used
    for ( int i = 0 ; i < 10 ; i++ ){
      if ( litBouton() ) {
         sommeil = dureeSommeil(init);
         break;
      }
    }
    // Let have the led blinking the configured time for
    // feedback and control
    for (int i=0 ; i < sommeil ; i++){
       clignotte();
    }
    // if user click at this time it means we must reconfigure again
    // If no button click on the next 5 sec = ok ; otherwize restart count
    notConfigured = false;
    for ( int i = 0 ; i < 5 ; i++ ){
      if ( litBouton() ) {
          init = 2;
          notConfigured = true;
          break;
      }
    }
  }
}

void startup() {
  digitalWrite(bleu,LOW);
  delay(500);
  digitalWrite(bleu,HIGH);
  delay(500);
  digitalWrite(bleu,LOW);
  delay(500);
  digitalWrite(bleu,HIGH);
  delay(500);
  digitalWrite(bleu,LOW);
  delay(500);
  digitalWrite(bleu,HIGH);
}

/* -------------------------------------
 * Manage button
 * -------------------------------------

// count the number of time the button is pressed
// if not pressed in the last 5 seconds it means the
// user have finished to selected the duration
int dureeSommeil(int init) {
  int tempo = 0;
  int count = init; // on a deja appuy une fois pour arriver la
 
  while ( tempo < 5 ) {
     if ( litBouton() ) {
        count++;
        tempo=0;
     } else {
       tempo++;
     }
  }
  return count;
}

// Active scan on the button, we are scanning 10 times
// with a 100ms period stopping as soon as a press is detected
// right after a 500ms delay to let user time to stop pressing
// the button
boolean litBouton() {
  int i = 0; 
  while ( i < 10 ) {
     if ( digitalRead(bouton) == LOW ) {
       delay(500);
         return true;
     }
     i++;
     delay(100);  
  }
  return false; 
}

/* -------------------------------------
 * Led display Management
 * -------------------------------------
 */

// set color during sleeping time
void dormir()
{
   analogWrite(vert,0xff);
   analogWrite(bleu,0x90);
   analogWrite(rouge,0x60);  
}

// set color during wakeup time
void reveil()
{
   analogWrite(vert,0x30);
   analogWrite(bleu,0xff);
   analogWrite(rouge,0xff);  
}

void clignotte(){
   analogWrite(vert,0xE0);
   analogWrite(bleu,0xE0);
   analogWrite(rouge,0x20);  
   delay(500);
   digitalWrite(vert,HIGH);
   digitalWrite(bleu,HIGH);
   digitalWrite(rouge,HIGH);
   delay(500);
}

/* --------------------------------------------
 * Main loop ... wait .. wait.. sleep ... KILL
 * --------------------------------------------
 */
void loop() {
  // sleep color
  dormir();
  
  // wait for expected number of hours
  for (int h = 0; h < sommeil ; h++ ) {
    for (int m = 0 ; m < 60 ; m++) {
      for (int s = 0; s < 60 ; s++) {
        delay(1000);
      }
    }
  }
  // wake up color
  reveil();

  // wait for reset then ARAKIRI ! (bourin non ? efficace oui !)
  while(1) {
    if (litBouton()) {
       asm volatile ("  jmp 0");
    }
  }  
}

Have fun with a nice box !

The last part was to create a 3d printed box to protect this circuit. You can get the stl files attached here  !

alarmclockbox

 

3d printed box for arduino alarm clock

3d printed box for arduino alarm clock

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.