Introduction: Device Activator From Sleeping Mode

Since technology has been advancing at an extremely high rate, the majority of the population cannot live without the convenience of such development. As a person who requires devices daily, this Arduino project will present a device activator. This device activator can be applied to window system and old MacBooks, which will reactivate the device from sleeping mode when the user claps. I decided to create this machine due to the inconvenience of constantly reactivating my laptop from sleeping mode. For window system, the users must press a random button to reactivate the device, and this causes inconveniences. For some old MacBooks, this has also been a minor issue. This machine consists of a KY038 sound sensor and an Arduino board. When the sound sensor observes a higher sound compared to the rest of the recorded data, the sensor will be triggered and activates the rest of the machine to reactivate the device.

For window system, the device often automatically endures sleeping mode if the device is not being used. Yet, for instance, the user might be reading through an article or examining certain elements on the device without constantly using the device. With this design, if the user is distanced from the device, by clapping twice, the laptop can be awakened from sleeping mode. This principle can also be applied to several old Mac devices.

Step 1: Supplies


  • Arduino board (Arduino Leonardo)
  • KY038 sound sensor
  • USB cable
  • Wires (*3)
  • A device

Container Design

  • Utility knife
  • Hot-melt adhesive
  • Ruler
  • Cutting Mat (*1)
  • Cardboards (30*30)(*2)

Step 2: Placement of KY038 Sound Sensor on the Arduino Board

For this machine, the only element needed to be connected to the Arduino board is the KY038 sound sensor. In order to have the sound sensor functions correctly, the wires connecting to the Arduino sound sensor must be inserted in the correct spots. Therefore, the machine can function properly.

The different in Arduino boards may leads to unprocessed function. Based on my project, the Arduino board applied is Arduino Leonardo, if you are using a different board, make sure to understand the difference between different Arduino boards.

Consequences of wrong wire connections:

Since the KY038 sound sensor must be connected to the right spots on the Arduino board, when the wires are connected incorrectly, the Arduino sound sensor will not be able to function properly. Therefore, the whole process of reactivating the device won't be executed.

KY038 Sound Sensor:

KY038 sound sensor has four parts that can be connected to the board, yet, in this case, only three parts are required: A0, G, and +. As shown in the diagram provided, the sound sensor must be correctly connected to the three spots on the board. After the three spots are correctly inserted, the KY038 sound sensor is now ready to be activated.

A0 --> A0 on the Arduino board

G --> GND on the Arduino board

+ --> 5V on the Arduino board

For this project, the only element requires to be placed on the board is KY038 sound sensor, yet before entering next step, make sure the connections are correct, preventing all unnecessary issues that can lead to terrible consequences.

Step 3: Code

This code is designed specifically when the user claps twice. The sound sensor takes in the sound and transfer the sound into numbers. The louder the sound is, the larger the number. When the sound sensor detects the higher sound input of the user's clap, the machine will start processing. According to my code, when the KY038 sound sensor detects a sound input higher than 80, the machine will start working. Since I observed a pattern of which under normal conditions, the sound input recorded will never exceeds 80, this ensures the KY038 sound sensor will not be activated without a large sound input.

Examining the code, there are two conditional if-branches to ensure the user must provide two claps in order to successfully activate the machine. Without two claps or two large sound inputs, the machine will not start processing. The first if-branch represents the detection for the first clap, and later another branch detects the second clap.

After the KY038 sound sensor detects the two large sound inputs, the machine will type "WORKING!!!" on the keyboard. Yet in this case, the laptop will be reactivated from sleeping mode since as long as a random element on the keyboard is typed, the device will awake from sleeping mode.

Code: Here

#include<Keyboard.h> // allow the arduino board to act as a keyboard 
int t = 0; // set the initial time to 0
void setup() { 
  pinMode(0, INPUT); // set the pin A0 to input for the sound 
void loop() { //detecting clapping
  if (analogRead(0) > 80) { //detecting first clap
    t = 0;
    bool done = true;
    while (analogRead(0) > 80) { //detecting delaying clap sounds
      t++;// adding 1 milisecond to time
      delay(1);//wait 1 milisecond
    while (analogRead(0) < 80) { //detecting no clap sounds
      t++;//adding 1 milisecond to time
      delay(1);//wait 1 milisecond
      if (t > 5000) { //testing if the time is too long
        done = false;
        break; //breaking out of loop
    Serial.println(t); //print on screen the time
    Keyboard.print("WORKING!!!"); //type in computer WORKING!!!

Step 4: Container Design

After you have successfully enter this stage of the project, the last thing you need to process is the container of your machine. For this project, the container is separated into two parts, the first part is the smaller portion of the container where the KY038 sound sensor is placed. The bigger portion/bottom part of the container is designed for the placement of the Arduino board.

  1. Looking at the photo with labels of the length and width of each part, the four cardboards on the top left are created for the smaller portion of the container. First, use a marker to draw out the shapes on the cardboards. Second, use a utility knife, two 5*6cm, two 9*1.5cm, and two 5*1.5cm cardboards need to be produced in order to build the part of the container designed for the KY038 sound sensor.
  2. Using a hot glue gun, construct the smaller container for the KY038 sound sensor.
  3. The larger portion remaining are the part which the Arduino board is placed. Using a marker, draw out two regular hexagons with sides of 6cm, and a 6-sided tube with each side a length of 23 and a width of 6. After all elements are drew on the cardboards, use a utility knife to cut down the shapes.
  4. Take one of the hexagons and use the utility knife to cut a square with sides of 1.5cm. The square created will be the part where the USB cable will be applied.
  5. Construct the larger container for the Arduino board with the hot glue gun.
  6. After both containers are constructed, use the hot glue gun to place the smaller container on top of the larger container. At this point, the Arduino board and the KY038 sound sensor should be placed in the containers.

The container for this machine does not necessary need to be the same, yet, the container should be capable of storing the Arduino board and the KY038 sound sensor.

Step 5: Conclusion

Hope this project helps you have a better understanding of how Arduino can be applied into real life situation. Through this project, you can learn the proper usage of KY038 sound sensor and develop further extensions on this element of Arduino.

Thank you all so much for reading through my creative Arduino project!