Introduction: Study Manager


Studying is difficult task. When you cannot concentrate, it is very hard to stay awake. If you are too focused on studying, you might not notice the darkness and damage your eyes. 
Therefore I come up with this device that will manage to keep you awake and maintain good studying environment at same time.
The structure is fairly simple, and you need only few things:

1)Arduino Platform

2)PIR Sensor Rev B
     -This will detect your motion and check if you are present and studying- or at least awake.

3)Photo-resistor
     -This will detect the brightness of the room; good amount of light will protect both environment and your eyes.

4)Speaker
     -This is used for alert. It will also wake you up if necessary.

5)Wires, power sources, 10KΩ resistor, etc.


If everything is prepared, you are ready for putting it together.

Step 1: Place PIR Sensor

Install PIR Sensor
-You should place PIR Sensor at the edge of circuit board, where sensor faces out. 
-Connect each port of the PIR sensor to arduino like circuit diagram shows.
-PIR sensor should be connected to L.

(Circuit diagram is from http://learn.parallax.com/KickStart/555-28027)

Step 2: Place Speaker

Install Speaker
-Place speaker in any part of board where it does not interrupt any other things.
-Connect each end of the speaker to arduino like circuit diagram shows.

Step 3: Place Photoresistor

Install Photoresistor
-Place photoresistor where it is not shaded by anything else
-Connect one end to Digital Pin and power, and other end to resistor and ground.

Step 4: Finish Building

Overal device should look like this.
Check if each wires are connected to correct pin of arduino.

PIR Sensor: D13
Speaker: D12
Photoresistor: A5

If you want to make changes, make sure you also change the numbers in program.

Step 5: Programming

Download arduino software to program the device.
Code is shown in the picture, and text information is in the below.


/*
  WakeUp1
  Reads an analog input on pin0, digital input from pin 12 and 13. Output is from speaker.
  Connect PIR Sensor, Speaker, and photoresistor to arduino.

Created 12/07/13
by marymountparis
*/

int sensorPin = 0;//the analog pin connected to the photoresistor's output
int sensorValue =0;
int pirPin = 5;//the digital pin connected to the PIR sensor's output
int speaker= 12;//the digital pin connected to the Speaker
int ledPin = 13;
int maxval=0;  //minimum value that photoresistor can detect
int minval=1023; //maximum value that photoresister can detect
int i=0;
int m=0;

// the setup routine runs once when you press reset:
void setup(){
    Serial.begin(9600); // initialize serial communication at 9600 bits per second:
      pinMode(sensorPin, INPUT); //set analog pin as input
      pinMode(pirPin, INPUT);  //set digital pin as input
      digitalWrite(pirPin, LOW); //set digital pin as input
    while(i<1000){
      int val=analogRead(sensorPin);  //find the brightness of the room
      if(val>maxval){ 
        //adjust the lower bound of possible range when detecting the less brightnesss
        maxval=val;
      } 
      if(val<minval){ 
        //adjust the upper bound of possible range when detecting the more brightnesss
        minval=val;
      }
      digitalWrite(ledPin,HIGH); 
      //during initialization process, LED attached to arduino's pin13 is on.
      i++;   
    }
    noTone(12);
    digitalWrite(ledPin,LOW); 
    //LED attached to arduino's pin13 will turn off when initialization process finishes.
  }


void loop(){
  // device checks the return from both photoresistor and PIR sensor.
  //the combination of the results change the return of device
     sensorValue= analogRead(sensorPin);
     if(digitalRead(pirPin) == HIGH){
       if(sensorValue>=minval-100){
         m=0;  //resets counter
         //When PIR sensor did detect motion and room is bright, nothing happens
       }
       else{
         tone(speaker,150);
         delay(500);
         noTone(12);
         m=0; //resets counter
         //When PIR sensor did detect motion when room is dark,
         //speaker sets off for few seconds.
         //It continues until room gets bright or PIR sensor stops detecting motion.
       }
     }
     else{
       if(sensorValue>=minval-30){
         if(m>10000){
         tone(speaker,150);
         delay(500);
         noTone(12);
         m=0; //resets counter
         //When PIR sensor did not detect motion and room is bright for certain amount of time,
         //speaker sets off for few seconds.
         //Sound continues until room gets dark or PIR sensor detects motion.
       }
       }
     }
     m=m+1; //adds up the count to counter
  }