arduinomaster5695
Published © GPL3+

Super Sleep Stopper 6000

An awesome alarm clock that wakes you up in the morning and can only be turned off if shot by a nerf gun!

IntermediateShowcase (no instructions)81
Super Sleep Stopper 6000

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×2
Proximity Sensor
×1
Amazon Web Services Nerf Target
×1
Acrylic Sheets 8x10
×1
RGB LCD Shield Kit, 16x2 Character Display
RGB LCD Shield Kit, 16x2 Character Display
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Drill / Driver, 20V
Drill / Driver, 20V

Story

Read more

Custom parts and enclosures

Super Sleep Stopper 6000

Schematics

Sorry no schematics available

Code

Super Sleep Stopper 6000 Code

C/C++
The first Time variable is so i can set it at night if it gets unplugged or something.
/* Code for my Arduino powered nerf target(Super Sleep Stopper Six-Thousand) 
 *  
 * Link to video I made for it: https://www.youtube.com/watch?v=uAIoMbHhPiU&t=11s
 *  
 * Approximately 75% pulled from internet
 * 
 * Rest hand written (Very approximate)
 * 
 */


#include <LiquidCrystal_I2C.h> // include LCD library
#include <Servo.h> // include servo library


Servo myservo;  // create servo object to control a servo

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

int sound = 250;

// Change to 0.5 for a slower version of the song, 1.25 for a faster version
const float songSpeed = 0.5;

int D = 0; // variable to determine if speakers should play 

int Time = 620; //Determines time till alarm sounds
#define trigPin 7
#define echoPin 6
#define buzzer 3
#define NOTE_C4 262  // defines frequency of notes
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_D5 587
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_G5 784
#define NOTE_A5 880
#define NOTE_B5 988

// Music notes of the song, 0 is a rest/pulse
int notes[] = {
    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4,

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4,

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4, 

    NOTE_E4, NOTE_G4, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E5, NOTE_G5, 
    NOTE_E5, NOTE_G5, NOTE_E4, NOTE_G4, 
    NOTE_E4, NOTE_G4, NOTE_E4}; 





    


// Durations (in ms) of each music note of the song
// Quarter Note is 250 ms when songSpeed = 1.0
int durations[] = {

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125,

    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125, 125, 
    125, 125, 125};

 

void setup() {

myservo.attach(12);  // attaches the servo on pin 9 to the servo object
Serial.begin (9600);
pinMode(trigPin, OUTPUT); // initalizes trig pin of proximity sensor as an output
pinMode(echoPin, INPUT); // initializes echo pin of proximity sensor as an input
pinMode(buzzer, OUTPUT); //initialize speaker pin as an output
pinMode(9, OUTPUT); // initialize digital pin 9 as an output.
  lcd.init(); // initialize the lcd
  lcd.backlight();
  myservo.write(-20); // sets servo at 0 degrees
}

void loop() {
  const int totalNotes = sizeof(notes) / sizeof(int);
  // Loop through each note

long duration, distance;
digitalWrite(trigPin, LOW); // runs infrared sensor
delayMicroseconds(2); // pauses for sensor to run
digitalWrite(trigPin, HIGH); // runs infrared sensor
delayMicroseconds(10); // pauses for sensor to run
digitalWrite(trigPin, LOW); // runs infrared sensor
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1; // converts proximity sensor data to centimeters?
lcd.setCursor(1,0);
lcd.print("Triple-S 6000");

  for(int t = 0; t < Time; t++) { // program that counts minutes

    lcd.setCursor(5,1); // displays minutes on screen
    lcd.print(t);
    lcd.setCursor(9,1); // displays total Time it has to count to on screen
    lcd.print(Time);
    delay(60000);
       if(t == Time - 1) { // checks if program has counted enough minutes to start alarm
    
          D = 1; // starts alarm if above is true
  }
}



if (D == 1) { // checks if alarm should start

  for (int i = 0; i < totalNotes; i++) // goes through each note to play
  {
    
    if(D == 1) {
        const int currentNote = notes[i];
        float wait = durations[i] / songSpeed;
        
    if (currentNote != 0) // Play tone if currentNote is not 0 frequency, otherwise pause (noTone)
    {
        tone(buzzer, notes[i], wait); // tone(pin, frequency, duration)
        digitalWrite(9, HIGH); // lights up LED
        digitalWrite(trigPin, LOW); //runs proximity sensor
        delayMicroseconds(2); // pauses for sensor to run
        digitalWrite(trigPin, HIGH); //runs proximity sensor
        delayMicroseconds(10); // pauses for sensor to run
        digitalWrite(trigPin, LOW); //runs proximity sensor
        duration = pulseIn(echoPin, HIGH); //not sure(don't delete, know it does something????)
        distance = (duration/2) / 29.1; // converts sensor data to centimeters


          if(distance <=6) { // checks if sensor is hit
              D = 0; //stops alarm
              Time = 1440;
              delay(1000); // puases for a second to make servo movement cooler
                 for ( int pos = -20; pos <= 80; pos += 1) { // lifts target up using servo
                      // in steps of 1 degree
                      myservo.write(pos);              // tell servo to go to position in variable 'pos'
                      delay(15);                       // waits 15ms for the servo to reach the position
            }
                for ( int pos = 80; pos >= -20; pos -= 1) { // brings servo back down
                      myservo.write(pos);              // tell servo to go to position in variable 'pos'
                      delay(15); // waits 15ms for the servo to reach the position
                      lcd.clear(); // clears lcd screen so words arent written on top of each other
            }   
            
        }
    }
    else
    {
      noTone(buzzer); // doesnt play a sound if a rest is played
    }
        // delay is used to wait for tone to finish playing before moving to next loop
    delay(wait);
    if(i >= totalNotes-1) { //repeats song??
      i = 0;
            }
        }
    }
}


digitalWrite(9,LOW); //turns LED off


delay(500); //pauses?????
}

Credits

arduinomaster5695

arduinomaster5695

0 projects • 0 followers

Comments

Add projectSign up / Login