Real Life Dramatic Moment Device
Abstract: This device dramatizes the everyday life with your own choice of soundtrack!
Why: Why not? We deserve to live life in silver-screen quotations.
Use: Whenever and wherever appropriate and inappropriate.
Schematic:
Arduino code:
————————————————————————————–
int sensor = 0; //IR read-in pin :: analogue
int pinOut = 7; //relay-control pinĀ :: digital
int counter = 0;
int play_time = 1500;
int add_num_reading = 14;
int delay_rate = 300; //1/3 of a second :: 10/30 frames
int lowEnd = 280; //the low end of the proximity reading
int highEnd = 1100; //the high end of the proximity reading
void setup()
{
pinMode(pinOut, OUTPUT);
}
void loop()
{
int val = 0;
val = readVal(sensor);
//the following condition forces the target to be in porximity for a set amount of time
if(isValid(val))
{
counter++;
}
else
{
if(counter>0)
{
counter–;
}
}
delay(300); //wait 1/3 of a second :: 10/30 frames to initialize another sampling
if(counter>6) //make sure the object is in proximity for some duration; avoid passing objects
{
digitalWrite(pinOut, HIGH); //turn on iPod
delay(play_time); //leave the iPod on for the durration of play_time
if(!isValid(readVal(sensor)))
{
counter = 0; //reset counter
digitalWrite(pinOut, LOW);//turn off iPod
}
}
}
int readVal(int sensorNum) //mass sampling function
{
int readVal;
readVal = analogRead(sensorNum); //initial reading
for(int i=0;i<add_num_reading;i++) //addtional number of samplings
{
readVal += analogRead(sensorNum);
}
return (readVal/add_num_reading+1); //return the average of (the initial readi + additiona; readings) :: smooth out noise
}
boolean isValid(int input) //this function verifies whether of not an object is in proximity
{
if(input>lowEnd && input<highEnd)
{
return true;
}
else
{
return false;
}
}
