Sleeping Fighter

by chelseacheng888 in Circuits > Arduino

194 Views, 0 Favorites, 0 Comments

Sleeping Fighter

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.

Components Required

IMG-4215.JPG

- Arduino Uno board * 1

- USB cable * 1

- Wire * 8

- Speaker * 1

- Supersonic sensor * 1

- Box * 1

Procedures

電路.png
IMG-4225.JPG

Step 1:

Build the Circuit

Step 2:

Download the code from https://create.arduino.cc/editor/Chelsea22/1e90b66...

(create your own music)

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.

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 } }