Introduction: Sleeping Machine

For teenagers living in this period when technology impacts our daily life more than we thought, even affecting our sleeping qualities. To prevent teenagers from not having enough sleep while addicting to the mobile phone, this project could force them to turn off the light and have a good night's sleep. This original idea was from https://www.instructables.com/Sleeping-Alarm-Clock/ to innovate the functions, I added another LED light with flashing lights and slightly change the setting of other functions. For the appearance, I designed a different look with the look of an alarm clock.

youtube video:

Supplies

LED*2

Resistance*3

Photoresistor*1

Wire*9

Speaker*1

Breadboard*1

Arduino Leonardo*1

Step 1: Type the Code

Arduino cc:https://create.arduino.cc/editor/dorahsi/86c9e03a-...

void setup(){ // put your setup code here, to run once:
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps pinMode( 5 , OUTPUT); // sets the digital pin as output }

void loop(){ // put your main code here, to run repeatedly: Serial.print(analogRead( A0 )); //print message Serial.print(" "); //print a blank Serial.println(); if ( analogRead( A0 ) > 550 ) { if ( analogRead( A0 ) >= 700 ) { analogWrite(6 , random( 0 , 256 )); //analogWrite values from 0 to 255 for (int i = 0 ; i < 1000 ; ++i ) { digitalWrite( 5 , HIGH ); // sets the digital pin on/off delay( 1000 ); // waits a few milliseconds digitalWrite( 5 , LOW ); // sets the digital pin on/off delay( 1000 ); // waits a few milliseconds digitalWrite( 5 , HIGH ); // sets the digital pin on/off delay( 1000 ); // waits a few milliseconds digitalWrite( 5 , LOW ); // sets the digital pin on/off delay( 1000 ); // waits a few milliseconds } part1(); } else { analogWrite(6 , random( 0 , 125 )); //analogWrite values from 0 to 255 part2(); } } else { analogWrite(6 , 0); //analogWrite values from 0 to 255 analogWrite(5 , 0); //analogWrite values from 0 to 255 noTone(11); //stop generating the tone } delay( 1000 ); // waits a few milliseconds }

void part2() { //customised function tone(11, 100, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds tone(11, 200, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds tone(11, 300, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds tone(11, 400, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds }

void part1() { //customised function tone(11, 600, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds tone(11, 700, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds tone(11, 800, 1000); //buzzer or speaker frequency delay( 500 ); // waits a few milliseconds tone(11, 900, 1000); //buzzer or speaker frequency delay( 1000 ); // waits a few milliseconds }

Step 2: Set All the Supplies on the Breadboard

Step 3: Set Up the Appearance

Step 4: Start and Have a Good Night Sleep