 This right here is a tap sensor. It's used to check for vibrations or taps that could be made by a knock or something as simple as a very light shape. Just before we start I want to say that if this video helped you out there's so many more coming onto the channel and there's ones that we've made before so all you have to do is hit that subscription button, like the video and if it does help you out please do watch until the end. If there's any other sensors you want to see me review or break down or teach just let me know in the comments. This tap sensor isn't one that we typically see around the house like the things we've reviewed previously on this channel but a cool project you could do with this is set it up on a door or a cabinet with all your hidden snacks that you want to hide from everyone and make some sort of secret knock pattern that when it activates it will unlock the door using the sensor or you can put it on something that should never move. If it ever moves this sensor will feel that vibration and let you know right away and you could set it up with an alarm or something cool like that. There are a lot of different versions of this specific sensor right here but they're all very similar because of the way they work which we're going to go over in a sec so just make sure that when you're following along that you set up your pins with your little cables the way that it's meant for your board and not for mine if you have a different model but the code and everything like that should still work for your model even if it's not the same as mine. It's going to be a little bit hard for me to show you exactly how this works but inside this plastic piece right here there's a spring. One side is holding the spring and the other side the spring is loosened the air to fling around. Now where it flings around there's a metal contact patch either inside the spring or at the bottom of it or at the top somewhere that when the spring moves it will touch one of those pieces of metal closing the electrical circuit and letting electricity flow through the spring from one metal prong which I can show you actually on the back right here so if you look right here under this piece of plastic you'll see two pieces of metal let me focus it up here so right here there's one piece of metal and there's one right there and then the spring connects them both when it vibrates and touches one of the pads so using that spring we're able to detect vibrations because the spring will always return back to its straight and natural position as long as nothing's broken in there meaning that this switch will turn on and off with vibrations. Now this will not sense sensitivity but you can sense other things like how long the spring has been touching the pad or maybe a pattern which is what I was saying earlier that if you knock and then you wait two seconds and you start knocking again you can detect those patterns of knocks and vibrations and then turn it into something to unlock a door to whatever you would like. All right so to connect it up we're going to need a couple of different things we're going to need the sensor itself we're going to need an Arduino it doesn't matter what type of Arduino you use a replica is what I'm using you can use other types of boards the code should work for all of them you're just going to have to set it up a little bit differently but these are fine Arduino micro mega whatever the other variations are called those work too then you got some cables that you need I got three with three different colors and then the sensor itself as I said I also have a cable here which I'm going to use to plug in everything to my computer so I can upload the code to the board so before we do that let's grab our Arduino let's grab our sensor and let's connect it all up on the sensor itself as you saw earlier there was three pins I'm going to move it up here one more time there's three pins we have an s pin a plus and a minus plus and minus is our power and on the plus and then minus is our ground and s is our signal that's the one that's going to tell the board all the information we need yours if it's not the same exact one as mine might have a different order so just make sure that you connect yours properly for your board otherwise everything's the same so for us we're going to be plugging in the black in the minus the red in the middle on the plus and then the yellow on the s it's also important to look at what kind of power your board can take or you're sorry your sensor can take this one can take both five volts and three volts I want to use three volts just to be safe so there we go we plug it in our black we're going to plug it into our Arduino black should be ground as always red we're going to plug into three volts and yellow I'm going to plug into seven seven on the digital line on digital PWM that's what they're called so once that's plugged in we can plug it into our Arduino just make sure everything's good you don't want to burn your little sensor we're going to plug that into the computer right there and now we can see the lights turn on on our board and we have some power so then we're going to open up our Arduino editor here and the first thing we want to do is declare our variables so we're going to go and declare an integer and call it pin and make that equal to seven because that's where we plugged in our yellow cable on the Arduino board that's our signal cable that's where our information will be coming from then we have to declare another one and that's going to be tap status you can call this whatever you want I just called it tap status so I remember what it is then we have to go into our setup and we have to do two things first we have to tell it that seven which is the number we picked earlier is going to be an input pin so we're going to put the pin and then we're going to put the word input in capitals that lets the program know that seven will be our input pin so everything should be pushed to there then we need to do something called serial we need to tell it to begin and then we're just going to give it a frequency to run on 9600 so when we print out messages we can read them like if we want to every time we tap we can have the sensor tell us that it's being tapped with actual English words instead of random numbers then we can go straight into our loop and this is where we have like the functional stuff so we're going to first take our tap status and we're going to set equal to digital read which is us reading the pen digital read and inside of that we're going to put our pin number seven because as we declare to appear pin mode pin input we're going to read from an input pin on number seven it might look a little confusing but it makes it a lot more organized instead of putting seven here and seven here because then when you want to change it you can just go to the top and change it once instead of all these different places so we did that now we can go and let's do what we said earlier actually let's go and make a little if statement and then inside of here we're going to say tap status and then under that we can do serial dot print line and inside of there we can say a message like now one thing that's important to know is with this specific sensor on is off and off is on it's not that weird you can try it like this but then it's always going to say tap until you tap and then it's never going to say tap so what we're going to do is we're just going to put this little exclamation point which just reverses the input so we can go and save that if you'd like I'm not going to save it let's make sure in the tools at the top here that we have our type of board selected so just make sure you selected whatever board you're using and then you have to go and select the ports that it's connected to if you don't know you can try them all usually it takes two minutes so we're going to do that and we're going to go and open up our serial monitor we're going to upload this I'm not going to save that one more time we're going to open up our serial monitor and now it shouldn't say anything now when we tap our sensor it should say I've been tapped so let's try it out we didn't see anything let's try one more time on the side here there we go I need to be a little bit harder on this because it's not connected to anything but maybe I could just smack it lightly along along the table here see that you'll see that it does catch it like four or five times per tap so if I do it again here see how it catches it like five six times that's normal because the spring does touch the contact patch for a couple of loops before it let's go again that's your loop right here so you could do a couple different things like you can go and make your loop have a little delay in it so we can delay here with like a really tiny number like this let's say 50 milliseconds let's upload that but what I'd rather do is get an average number does it usually show five or six taps and then and then in your code you can write it for that five to six taps to be equal to one because it's normal that it's going to stick to it for a little bit of time so let's actually clean this here let's tap it one more time oh and now I broke it now it's not working at all see that so let's get rid of our delay and instead whenever you're sensing for taps you can you can figure out a smart way to to consider six or five taps at once to be equal to one if you want to do a pattern if you just want to sense it tap in general it really doesn't matter how many there are as long as there's more than one or I'm sorry more than zero so there's a taps one more time let's go open up our serial monitor let's clear that there we go now we're working again and you see now it's two now it's five now it's three now it's four so it seems like the harder I hit it usually the more it is because that spring kind of stays for the tiniest amount of time on that little platform but other than that that's pretty much it that's how you use a tap sensor if you enjoyed the video if it helped you out please do give it a like and check out the next video that's going to be coming out either tomorrow or whatever the next day is on another sensor if you have any sensors you want me to look at please do let me know I'm going to run out of sensors at one point and I need the help from you guys to find more