Phone Protector

by hsuchiaen.rita in Living > Education

197 Views, 0 Favorites, 0 Comments

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

IMG_6273.jpg

5 wires

1 LED

1 resistance

1 Ultrasonic sensor

1 speaker

Coding

IMG_4211.JPG

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

IMG_6249.jpg

Please follow the picture complete it.

Appearance

IMG_6269.jpg
IMG_6267.jpg
IMG_6268.jpg

Materials you need

1. A box that is suitable for your bread board

2. scissors

3. tape

Finish!