Kai Hung (kmh9)Theo SchweizerBrian Serrata
Published © GPL3+

Un-Sleeping Alarm (USA)

Ever hit snooze on your alarm and never wake up after? Fear not, we present USA, an alarm that yells at you again once you stopped moving.

BeginnerFull instructions provided3 hours43
Un-Sleeping Alarm (USA)

Things used in this project

Story

Read more

Schematics

Schematic

Code

AlarmCode

C/C++
The program underlying the Un-Sleeping Alarm.
const int buzzer = 4;
const int motion_sensor = 2;
const int tilt_switch = 3;
int motionValue;
int tiltValue;
int timer = 0;
int warm_up;
void setup() { //run this code once
  pinMode(buzzer, OUTPUT); //set the buzzer as an output device
  pinMode(motion_sensor, INPUT); //set the motion sensor as an input device
  pinMode(tilt_switch, INPUT); //set the tilt switch as an input device
  Serial.begin(9600);
}

void loop(){ //loop forever...

  motionValue = digitalRead(motion_sensor);
  tiltValue = digitalRead(tilt_switch);
  
  if( tiltValue == LOW ){
    if (motionValue == LOW){
      timer ++;
      delay(1000);
    }
    if (motionValue == HIGH){
      timer = 0;
      analogWrite(buzzer, 0);
      delay(1000);
    }
    if (timer >= 5){
     analogWrite(buzzer, 200);
     Serial.print("active");
    }
  }
  else{
    analogWrite(buzzer, 0);
  }

}

Credits

Kai Hung (kmh9)

Kai Hung (kmh9)

1 project • 0 followers
Theo Schweizer

Theo Schweizer

1 project • 0 followers
Brian Serrata

Brian Serrata

0 projects • 0 followers

Comments