Sound Pulsing Switch

Introduction: Sound Pulsing Switch

Ever have the problem when you staying on bed, but suddenly realise that the lights are still on. However, you are so tired that you do not want to walk down the bed to turn off the lights, nor spending eighty dollars to buy a Philip Hue ambient light, which would allow you to turn off the lights using your phone. If you are using a traditional light with a switch, why not check out this novel, yet easy Arduino project to resolve your laziness!

I started to have the idea of this project at approximately a year ago, when I moved to my new home, finding out that my light switch is nowhere near my bed, forcing me to leave my bed every night when I laid on my bed tiring, just for TURNING THE LIGHT OFF (which irritates me every night)! However, after doing this project, I have been benefited massively throughout, and hope to share this idea to all INSTRUCTABLE users, who currently also suffers under the far light switch issue.

The basic idea of this Sound Pulsing Switch is to trigger the KY-037 Sound Detector Sensor for doing a set of actions, including to turn on the servo motor for hitting the actual light switch in order to turn it off. So, how exactly does the KY-037 Sound Detector Sensor work: basically, it detects the intensity of sound in the environment, in this case, every 20 milliseconds (this can be set in the coding section, step 5), and when it finds out an unusually loud soundwave in its Oscilloscope Trace, it will then trigger the count, whereas when it reaches two counts, it will then activate the servo motor, further turning off the lights.

Step 1: Supplies

In order to create this Sound Pulsing Switch, we need certain supplies such as in below:

Electronics:

Decorating Model Supplies:

  • Cardboard (or wood, if doing laser cutting)

Others

Step 2: Assemble the Electronic Components

Before actually constructing the model, we have to assemble the electronic components, which is very simple, and can be done in a few steps as such:

  1. Solder the 9V battery connector the Arduino Nano board. This might be a little difficult for people who are not familiar with any soldering techniques, but this is essential for succeeding to make this project because if the board is not supplied by enough power, it might not function properly or well. For soldering, connect the red wire to the VIN pin; and the black wire to the GND pin, which both stands on the right-hand side of the board.
  2. Connect the jumper wires onto the Arduino Nano board. In this project, we will only contribute to the A0, D2, the GND pin and the 5V pin.
    • Using the breadboard to connect the pins, we need to connect the G pin from the KY-037 Sound Detector Sensor Module to the breadboard; on the same column (beware of this, if not on the same column, your final project would not function), connect the black wire from the servo motor, and the black wire from your external power supply (you need to do this for the GND pin but not the 5V pin because that the external power supply would need to make a common ground in case of not burning your Arduino), then connect another Male to Female jumper wire onto the same column and to your Nano respectively.
    • Next, connect the “+” pin from the KY-037 Sound Detector Sensor Module to one of the holes on the same column, then take another Male to Female jumper wire connecting to the same column on the breadboard and the other side to the Nano board.
    • After that, connect the red wire on the servo motor to another column despite the used ones, and place the red wire from the external power supply to the same column also, to power the battery bank. Indeed, connect the USB-sub head to the power bank in order to make it powering the servo motor.
    • Also, crossing beyond the two columns where the GND and the 5V pin stand, place the capacitance’s two legs on both columns, to create a relatively stable environment for the KY-037 Sound Detector Sensor.
    • Lastly, connect the white wire on the servo motor to the D2 pin on the Nano. And connect A0 to A0 from the KY-037 Sound Detector Sensor Module to the Arduino Nano board respectively.

And you are done with all the electronics!

Step 3: The Design of the Model

For this project, the model building is extremely easy, as we only have to create a box with six sides. However, the design had to be as certain as the AutoCAD file, I have provided underneath.

If you really want to make this project well and precise, continue reading to discover the design idea of this project.

This Sound Pulsing Switch contains a box, which has six sides, the holes on the sides each represented a space for placing the electronic components, as to make the device function.

  1. For the top, there is a hole of length 3 * width 2, for placing the servo motor, giving it space to function and hit the button;
  2. Next as the opposite bottom, we note that this is just a rectangle base, that contains no holes to hold everything in it nice and confirm; then for the right side, we need a hole for the external power supply wire to come out for connecting to the power bank in order to power the power bank;
  3. Afterwards, for the left-hand side, it looks identical to right left-hand side but without the hole;
  4. Lastly, for the front, we need actually more holes, one for the 9V battery connector to be out of the box, so that we can change the battery easily when we go out of power, as to switch off the switch to prevent any waste of battery power, the other is for the microphone of the KY-037, to ensure that the device could detect the change of the sound in the environment;
  5. Also as the bottom, the backside contains no holes, just to hold everything nice and affirm

Step 4: Building the Model

After we had made our plan thoroughly, we now will have to move onto the process of actually building up the model. However, this process will be extraordinarily easy compared to the previous step, as just do this:

  1. Cut out the six sides in the scale provided in the AutoCAD file with the cardboard or use laser cut
  2. Take the tacky glue and paste it on the sides of the pieces to assemble them together, but still leave the backside out that we could still arrange the components within it
  3. Stuck your 9V battery connector into the hole that we have cut in the front side of the model
  4. Stuck your KY-037 Sound Detector Sensor Module into the hole that we have cut, but remember to cut a little wider, the diameter I provided is an approximate value for "my" component, which might vary in different ones, also the rectangular part might hit the side, causing it not to be tucked well enough, be in mind
  5. Tear off the sticker behind your breadboard and stick it behind the front piece of your model
  6. Place your servo motor well into the hole that we had cut out on the top of the model
    • Try to place some of the sticky clay behind the servo motor against the side to strengthen it
    • Also, remember to put the double-sided tape to make it stronger
  7. Pull your external USB cable out of the hole we had cut out on the right-hand side of the structure, and connect it to the power bank
  8. Glue your backside onto the model, but if you are not certain about your work and might still need to arrange or repair your device, use some of the Scotch tapes to stick it first, that you could easily tear it off

Step 5: Coding

And nowhere is the fun yet most essential part in this project, without coding, your device would never work, not soever how good you had built up your model or the accuracy of making the circuit, without coding, this is nothing. So, down here, I wrote a code just for this project, and explained what every line means in the comment section in the code, that however, if anyone still has any problems, feel free to leave a comment underneath that I would be happy to reply instantly (I believe).

In this code, I chose to let the servo motor to turn ninety degrees and a hundred and eight degrees, however, this can be arranged due to the different switch everyone got at home, and I believe that this is free for all to be changed. While looking at my code, keep bearing in mind that this device is for "automatically" switch off the light using the method of sound, that please do not be confused, and if you are confused, feel free to refer back to the video at the very beginning. You can now see the code down below or through this Arduino Create Website link.

Arduino Create Link

In addition, if enough people asked about any clarification of the code, I might think about it LOL...

Arduino-Sound-Pulsing-Switch

#include //include the library for the servo motor
int MIC = A0; //sound detect component connected to A0 leg
boolean toggle = false; //recording the initial version of the toggle
int micVal; //record the detected volume
Servo servo; //set the Servo motor's name as servo
unsigned long current = 0; //record the current time stamp
unsigned long last = 0; //record the last time stamp
unsigned long diff = 0; //record the difference of time in between the two time stamps
unsigned int count = 0; //record the count of toggles
void setup() { //run for once
servo.attach(2); //initialize the servo to connect to D-pin leg 2
Serial.begin(9600); //initialize the serial
servo.write(180); //make the servo turn to its initial angle
}
void loop() { //loop forever
micVal = analogRead(MIC); //read the analog output
Serial.println(micVal); //print out the value of the environment sound
delay(20); //every twenty seconds
if (micVal > 180) { //if over the limit, which I had set to 180 here
current = millis(); //record the current time stamp
++count; //add one to counted toggles
//Serial.print("count="); //output the toggled times, open it if you feel like
//Serial.println(count); //print out the number, open it if you feel like
if (count >= 2) { //if the toggled count is already more than or equal than two, determine if the two time stamps lasted between 0.3~1.5 second
diff = current - last; //calculate the difference of time in between the two time stamps
if (diff > 300 && diff < 1500) { //determine if the two time stamps lasted between 0.3~1.5 second
toggle = !toggle; //revert the current condition of the toggle
count = 0; //make the count zero, get ready to test again
} else { //if the time does not last in between the constrained counts, then revert the count to one
count = 1; //do not count the count
}
}
last = current; //use the current time stamp to update the last time stamp for the next comparison
if (toggle) { //determine if the toggle is on
servo.write(90); //servo will turn to 90 degrees for opening the light
delay(3000); //delay 5 seconds
servo.write(180); //servo will turn back to its original spot
delay(1000); //delay another 5 seconds
count = 0; //set count to initial number to recount
}
else {
servo.write(180); //if the toggle does not work, than just stay at the initial 180 degrees
}
}
}

Step 6: Completion

Now you have finished the project that you may now play with the Sound Pulsing Switch to turn off your light, indicating your laziness will never be an issue any more! And remember if you have done this project, share it online to me, and to the world, that to show the wonderfulness of the project!

Be curious, and keep exploring! Good luck!

Arduino Contest 2020

Participated in the
Arduino Contest 2020

Be the First to Share

    Recommendations

    • Rocks, Gems, and Stones Speed Challenge

      Rocks, Gems, and Stones Speed Challenge
    • Space Contest

      Space Contest
    • Micro:bit Contest

      Micro:bit Contest

    2 Comments

    0
    seamster
    seamster

    1 year ago

    Clever and useful! : )

    0
    iceideii
    iceideii

    Reply 1 year ago

    Thank you very much for the compliment!