Phone Protector
This is an object that would alarm when you take away the phone while you were studying. The purpose of this is to let students would concentrate when they are studying, and won't get distracted by phones.
Prepare Materials
5 wires
1 LED
1 resistance
1 Ultrasonic sensor
1 speaker
Coding
int UltrasonicSensorCM(int trigPin, int echoPin) //Ultrasonic Sensor Code
Auto Generated Return CM max distance 200
{
long duration;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
duration = duration / 59;
if ((duration < 2) || (duration > 200)) return false;
return duration;
}
void setup(){ // put your setup code here, to run once:
digitalWrite( 11 , LOW ); //set ultrasonic sensor trigPin
pinMode( 10 , OUTPUT); // sets the digital pin as output
}
void loop(){ // put your main code here, to run repeatedly:
if ( UltrasonicSensorCM( 11 , 12 ) < 5 ) {
digitalWrite( 10 , LOW ); // sets the digital pin on/off
noTone(8); //stop generating the tone
}
if ( UltrasonicSensorCM( 11 , 12 ) > 5 ) {
digitalWrite( 10 , HIGH ); // sets the digital pin on/off
tone(8, 440, 1000); //buzzer or speaker frequency
}
}
Bread Board
Please follow the picture complete it.
Appearance
Materials you need
1. A box that is suitable for your bread board
2. scissors
3. tape