In this assignment i want to make a switch that closes a circuit that produces sound as output. The switch is an analog sensor that i will connect with a NodeMCU and a breadboard. For the sound as output i will use a Piezo Buzzer.
I will make the switch from cardboard and copper tape. The switch would have to fit in a serie of products as shown in the image below.
For my idea i want to make the switch as an wearable with two rings that will close the circuit whenever they touch eachother.
For prototyping purposes i am using gray cardboard and for the finished version i will use black cardboard.
First i draw some lines and than i cut out the unnecessary space. I leave a strip in the middle that connects the rings with each-other and to make it impossible to lose one ring.
After cutting i rolled up the strips that i will use as rings and secured it with adhesive tape. With a black marker I've marked the spots where i want to secure the copper tape.
This is how it looks like this far.
I taped some copper tape and can now start connecting everything. To make sure the switch works, I try it out with a LED.
Thanks to Kaj and Loes i discovered that i used a 10K ohm resistor and instead i should use a 220 ohm resistor. I switched the resistors and the LED was brighter.
Now comes the tricky part, connecting it with a buzzer instead of a LED and figuring out how to connect everything.
I've drawn a schematic from my first try.
Then the coding started, that was easier because I've worked with Arduino before and still remembered a lot. For the speaker i want it to play Sandstorm by Darude so I searched on the internet for the code of the notes that are in the song. I came across this video and copied the code of the notes that the maker left in the description.
The code was written for the Arduino UNO so i had to change everywhere where he defined "pin 8" to the D2 pin where i connected my buzzer. Then i wrote the code for the switch and used if and else with the sound. If i press the button music will play, else there is no music.
In the top of the code you see that i included a library named "pitches". That is a library with different notes that will come out of the buzzer. Otherwise there will be no sound.
After uploading the code to the NodeMCU it did not work. The speaker was playing the song but the switch was not working. I was sure that there was nothing wrong with the code so i had to figure it out with the cables to make the right circuit.
After almost 2 hours of debugging it finally worked out, sort of, but it was good enough.
I looked in the previous slides from Micky's tutorial with the button and LED and how to connect it with digital pins.
Now my schematic looks like this:
Now i will start with the black cardboard.
First i measured and drew lines where i want to cut.
The result after cutting everything:
I also cut out a piece from the stripes on each side so the rolling will go easier. After that i put some glue on the short sides and rolled it, holding it for a few seconds until it dried.
Now i cut out 2 pieces of copper tape. One is 4cm and the other 3cm. The 4cm piece is the piece what gets two paperclips for connecting. After placing the copper tape i'm done and ready to connect for the final test.
After connecting and turning it on again i discovered that it wasn't working properly. So i tried to switch the D0 to the A0 pin and changing it in the code as-well. I also changed the if and else statements after looking in the serial monitor what the values were. After uploading to the NodeMCU and testing it finally worked how i wanted it to work.
I'm not sure if this was the right way of debugging but it worked.
Video of the final result:
I made another variant of the wearable switch that would fit better with the rest of the series. Instead of cutting the unnecessary space i only cut the strips to make two rings. Now the design is more square and would fit better with the rest. In addition the copper tape goes around the ring.