# Sleeping Fighter

37

## Introduction: Sleeping Fighter

I'm going to teach you how to make a sleeping fighter machine. This is a machine that helps to wake you up when you fall asleep. Sometimes we haven't finished our homework, but we are tired so will lie on the desk and rest. At this moment, the speaker will make some noise to wake you up.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Components Required

- Arduino Uno board * 1

- USB cable * 1

- Wire * 8

- Speaker * 1

- Supersonic sensor * 1

- Box * 1

## Step 2: Procedures

Step 1:

Build the Circuit

Step 2:

Step 3:

When you near to the supersonic sensor, the speaker will makes a sound. The music will end until you away from the supersonic sensor.

Step 4:

Find a box to put it and decorate it!

*Make sure you have cut out a part of the box to make the supersonic sensor inducted.

## Step 3: Code

https://create.arduino.cc/editor/Chelsea22/7c0714c...

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 > 40)) return false; return duration; }

void setup(){ // put your setup code here, to run once: digitalWrite( 6 , LOW ); //set ultrasonic sensor trigPin

}

void loop(){ // put your main code here, to run repeatedly: if ( UltrasonicSensorCM( 6 , 7 ) < 20 ) { noTone(11); //stop generating the tone } if ( UltrasonicSensorCM( 6 , 7 ) > 3 ) { tone(11, 1318, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1175, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1318, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1175, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1318, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 988, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1175, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1046, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 880, 1000); //buzzer or speaker frequency delay( 700 ); // waits a few milliseconds tone(11, 534, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 660, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 880, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 988, 1000); //buzzer or speaker frequency delay( 700 ); // waits a few milliseconds tone(11, 660, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 784, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 988, 1000); //buzzer or speaker frequency delay( 300 ); // waits a few milliseconds tone(11, 1046, 1000); //buzzer or speaker frequency delay( 200 ); // waits a few milliseconds } }

5 349
246 17K
112 24K