Knock Lock: Using the piezo input feature to create a coded lock
The basis of this project was based on using the piezo as an input device, rather than the output one used in previous projects. The piezo used here scans for three consecutive knocks in order for the lock to be turned off.
There were a large amount of parts used in this project, with the most important three being the piezo, the three LED's, and the servo motor. The piezo is connected to the analog 0 pin, using the analog input to properly display the loudness of the knock. The outputs are connected to the LED's in digital pins 3, 4, and 5. When the switch pressed connected to 2, it will move the servo to the locked position. When three knock are knocked on the piezo, the yellow LED will flash for each knock, and if properly done, then the green LED will turn on and the servo will move into the unlocked position.
The code works by setting up the piezo, switch, LED's, and servo/capacitor to their pins as needed, and their correct input/output functions. The loop function constantly checks the current locked bool, and determines if it is locked or unlocked. If it is unlocked (which it will always start off as as done in setup), the code will check for the push of the switch, which will turn on the red LED and move the servo into the locked position. If it is in the locked position, then the piezo will scan for knocks, using the checkForKnocks function, and see if the knocks exceed the limit requirement, and if they hit the necessary three needed to unlock. If the both the requirements are hit, then the servo will unlock.
I had a big difficulty in the project due to how I hooked up the servo. I didn't realize that you can stick wires directly into the servo pins, and then just place them onto the board. I initially tried to use the pre-made pins that came with the Arduino, but I couldn't place them properly due to their rigidness. But this project was not to difficult to complete besides that, and showed a good use for the piezo "secondary" input function.






Comments
Post a Comment