manjariiiiiiiiitalasila
Published © GPL3+

Alarm Timer

The user sets a timer and wakes up with colorful flashing LEDs and a loud buzzer that rings until the snooze/off button is pressed.

IntermediateFull instructions provided236
Alarm Timer

Things used in this project

Hardware components

LED (generic)
LED (generic)
×4
Resistor 1k ohm
Resistor 1k ohm
×6
Male/Male Jumper Wires
×1
Tactile Switch, SPST-NO
Tactile Switch, SPST-NO
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1

Story

Read more

Schematics

Circuit Schematic

Code

alarmTimer.ino

Arduino
#include "LowPower.h"

// set the corresponding snooze/off button pin number
const int buttonPin = 2; 

// set the four corresponding LED pin numbers
const int ledPin1 = 4; 
const int ledPin2 = 3;
const int ledPin3 = 5;
const int ledPin4 = 6; 

// set the corresponding piezo buzzer pin
const int alarmPin = 9;

// initialize timer variables
int nappingTime = 0;
String strNappingTime = "";

// initialize the snooze/off button state
int buttonState = 0;  

void setup() {
  // initialize the LED pins as outputs:
  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  
  // initialize the snooze button pin as an input:
  pinMode(buttonPin, INPUT);

  // user inputs napping time
  Serial.println("How long do you want to set the timer for?");
  while (Serial.available() == 0) { }
  strNappingTime = Serial.readString();
  nappingTime = strNappingTime.toInt();
  delay (nappingTime * 60000);
}

void loop() {
  // after time is up, reads the state of the snooze button:
  buttonState = digitalRead(buttonPin);
  
  // checks to see if the snooze/off button is pressed:
  if (buttonState == LOW) {
    // alarm rings
    // LEDs flash
    tone(alarmPin, 3000);
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    delay (500);
    noTone(alarmPin); 
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    delay(500);
  } 
  
  // if the snooze button is pressed
  else {
    // alarm stops
    // turns LEDs off
    noTone(alarmPin); 
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    delay (1000);
    // shuts down until reset button is pressed
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  }
}

Credits

manjariiiiiiiiitalasila
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.