Step 3Lay Out And Test The Circuit
I've provided both a schematic and a layout diagram for the breadboard. Follow whichever one you're the most comfortable with.
We're going to go slowly and check as we go.
#1: Wire the Piezo Sensor
Solder a pair of 12" (30cm) leads to the Piezo speaker. Connect it between Analog pin 0 and the ground. Also attach the 1M ohm resistor between Analog pin 0 and the ground.
Test: With your Arduino plugged into your computer (via USB or Serial cable) and open the Serial Montor window. (That's the button furthest to the right at the top of the Arduino development environment.) With the Arduino powered on you should see the text "Program start." Tap the piezo speaker and you should see the text "knock starting" and "knock" each time you tap it. Stop for a second or two and you'll probably see "Secret knock failed" or "Door unlocked!"
If you don't see anything or see junk, make sure your serial port is set to 9600 baud and reset the power on the Arduino. If you're sure it's right, then try tapping Shave and a Haircut (Don't forget the two bits. See the video if you don't know it.) and see if you can get the "Door unlocked!" message.
If you get knock messages without tapping it may be too sensitive. If so you'll need to edit the sketch. Around line 27 raise the value of threshold. This can be raised as high as 1032 if you have a very sensitive detector.
const int threshold = 3; // Minimum signal from the piezo to register as a knock
Once you have it working the way you want it you can comment out (or delete) the lines that start with Serial... We shouldn't need them any more.
#2: Wire up the LEDs
Lets wire up some LEDs so we don't have to use a serial cable to see what's going on.
Connect the red LED to digital pin 4 and green LED to digital pin 5 with their corresponding 560* ohm resistors in line.
Test: If you power the circuit the green LED should light. If not, check your connections and make sure the LED is the right way around. Every time you tap the green led should dim. After tapping the correct sequence the green led should blink a few times. Tapping the wrong sequence should blink the red one.
If none of this happens, check the polarity on your LEDs and all of your connections.
* Your LEDs might require different resistance.
#3: Wire the programming button
Solder 8" leads to the button. Connect one side of the button to +5v. The other pin on the button connect to digital pin 2 and, with a 10K resistor to the Ground.
Test: Apply power. When you press the button the red light should come on. Hold down the button and tap a simple sequence. When tapping while programming both LEDs should blink. When you're done the pattern you just tapped should repeat on both lights. After playback is complete, the new knock code is saved and the lights wil alternate red and green to tell you so.
#4: Wire in the motor
Solder 8" of leads to the motor and follow the design/schematic. Be sure to get the diode going the right way and you might want to check the pins on the transistor to be sure they match the diagram. (Some transistors might have the pins in different order.)
Test: Power the circuit. Tap the default "Shave and a Haircut" knock. The motor should run for about half a second. If not, check your connections as well as the polarity of the diode.
Extra Troubleshooting tips:
1) If the motor turns very weakly the diode might be reversed.
2) If you need more power on your motor make the following circuit change: Move the wire that goes from the motor to +5v to the Vin pin on the Arduino. This will supply the motor with 9v (or whatever voltage you're supplying to it.)
Tip: Check which way the motor turns. It should turn the same way as you turn your deadbolt lock to unlock it. If not, switch the motor's leads which should reverse the motor.
Congratulations! You have a working secret knock detector!
Now we have to put it into something more permanent that we can stick on our door.
| « Previous Step | Download PDFView All Steps | Next Step » |


















































http://www.adafruit.com/products/170
Thanks so much :)
Program start.
knock starting
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
knock.
New lock stored.
Every ten seconds. i know that the knoks are the readings and it seems like the program is running a loop. I tried getting the sensitivity threshold up to the limit but any threshold variations dont seem to change anything. Any ideas?
Thanks for such an amazing project and gretings from Mexico! :D
I simply made a quick sketch that continuously read the values coming from that pin and dumped them to the serial port. It's not too different from this or this Arduino tutorial. (Looks like you're using PIC, so you'll have to port or modify the code.)
Depending on the requirements, an easy way to provide more voltage to the motor is to connect the motor (+) to the raw power in pin on the Arduino (or straight to the battery). But check the ratings on your transistor to be sure you're not going to overload it with the motor.
so I put it back to the 5 V pin, and it when I tap shave and a haircut, it shakes a Liiittle bit.. I don't know if I just touched something else in the process or if this killed my motor..
This is a good time to use your multimeter and see what kind of current you're getting through the motor.
This can happen if your diode is in the wrong way. Check the polarity of the diode. Probably wouldn't hurt to check the transistor's pins as well. Don't just mount it by looking at the shape, check the spec sheet and be sure that the pins are going to the right places.