התחל במצב לא מקוון עם האפליקציה Player FM !
פודקאסטים ששווה להאזין
בחסות


1 The Road Back to Country With Blake Shelton 25:13
How to make a secret knock detector to trigger anything with only an Arduino and a few cheap components
Manage episode 269164105 series 2774299
There are a couple good use-case scenarios for making a secret knock detector using an Arduino.
- You are a spy who needs to authenticate your cohorts
- You are a super hero who wants a secret knock to open the entrance to your lair
Whatever the reason - by the end of this tutorial you will know how to use an Arduino, a piezo transducer and a couple other cheap components to make secret knock detector.
Here is an overview of exactly what we will talk about in this lesson:- The components you will need and how to set up this simple circuit.
- The concept of operation of this secret knock detector
- A thorough description of each block of code in the Arduino sketch
- Why North American grizzly bears love piezo transducers
For this secret knock detector circuit you need:
- Arduino (I use the Arduino Uno) [1]
- Solderless breadboard [1]
- 1 Mohm Resistor [1]
- Piezo transducer (aka buzzer) [1]
- Jumper wires [4]
- 5.1V Zener diode (for extra protection) [1]
- No spill stopper for a “to-go” coffee cup
This is a really simple circuit to setup, below are step-by-step instructions and a breadboard diagram.
- Place the piezo transducer on the breadboard, with the positive lead and the negative lead on separate rails.
- Connect the positive lead to pin A0 on the Arduino and the other lead to ground.
- Finally, use the 1Mohm resistor to connect the leads of the piezo transducer.
- As an additional level of protection, you might consider adding a 5.1V zener diode between the leads to protect against high voltage spikes from frying your input pin - you might call it a cheap insurance policy.
Here is the basic concept of how this will work.
We want something to happen when you tap out a secret code.
We will create a sequence of soft and hard taps - this will be our secret code which will be represented as 0’s and 1’s in an array.
For example:
secretKnock[secretKnockLength] = {0, 0, 1, 0};The code above represents a secret code of soft , soft , hard, soft .
The piezo transducer will turn the mechanical pressure created by the tap into a signal that the Arduino analog pin can read. The level of the signal will determine whether a tap gets characterized as soft or hard.
The threshold of a soft vs hard tap need to be determined empirically, once you have the circuit built - it will depend on what you have the piezo transducer attached to - I have mine taped to a piece of paper.
You should start with the default threshold values provided in the sketch and change them to suit your specific setup.
Once a tap signal is picked up by the Arduino, the sketch will compare the entered sequence of taps to the secret code, one tap at a time.
If the code is entered correctly, then we will trigger an action on the output pin. In this code below, we trigger an LED to turn on for a couple seconds - but you could trigger a servo arm, a pump, or whatever you might need.
If the code is entered incorrectly - nothing happens.
Here is the code for your hacking enjoyment:
/* A simple sketch to detect a secret knock using a piezo transducer Created JUL 2015 by Michael James http://www.programmingelectronics.com/ This code is in the public domain */ const int outputPin = 6; // led indicator connected to digital pin const int knockSensor = A0; // the piezo is connected to an analog pin const int thresholdHIGH = 150; // threshold value to decide when the detected knock is hard (HIGH) const int thresholdLOW = 120; // threshold value to decide when the detected knock is gentle (LOW) const int secretKnockLength = 4; //How many knocks are in your secret knock /* This is the secret knock sequence * 0 represents a LOW or quiet knock * 1 represents a HIGH or loud knock * The sequence can be as long as you like, but longer codes increase the difficulty of matching */ const int secretKnock[secretKnockLength] = {0, 0, 1, 0}; int secretCounter = 0; //this tracks the correct knocks and allows you to move through the sequence int sensorReading = 0; // variable to store the value read from the sensor pin void setup() { //Set the output pin as an OUTPUT pinMode(outputPin, OUTPUT); //Begin Serial Communication. Serial.begin(9600); } void loop() { // read the piezo sensor and store the value in the variable sensorReading: sensorReading = analogRead(knockSensor); // First determine is knock if Hard (HIGH) or Gentle (LOW) //Hard knock (HIGH) is detected if (sensorReading >= thresholdHIGH) { //Check to see if a Hard Knock matches the Secret Knock in the correct sequence. if (secretKnock[secretCounter] == 1) { //The Knock was correct, iterate the counter. secretCounter++; Serial.println("Correct"); } else { //The Knock was incorrect, reset the counter secretCounter = 0; Serial.println("Fail - You are a spy!"); }//close if //Allow some time to pass before sampling again to ensure a clear signal. delay(100); //Gentle knock (LOW) is detected } else if (sensorReading >= thresholdLOW) { //Check to see if a Gentle Knock matches the Secret Knock in the correct sequence. if (secretKnock[secretCounter] == 0) { //The Knock was correct, iterate the counter. secretCounter++; Serial.println("Correct"); } else { //The Knock was incorrect, reset the counter. secretCounter = 0; Serial.println("Fail - You are a spy!"); }//close if //Allow some time to pass before sampling again to ensure a clear signal. delay(100); }//close if else //Check for successful entry of the code, by seeing if the entire array has been walked through. if (secretCounter == (secretKnockLength) ) { Serial.println("Welcome in fellow Illuminante!"); //if the sececret knock is correct, illuminate the LED for a couple seconds digitalWrite(outputPin, HIGH); delay(2000); digitalWrite(outputPin, LOW); //Reset the secret counter to 0. secretCounter = 0; }//close success check }//close loopIf you enjoyed this lesson, you should join our free Arduino Crash Course - it has 19 Video Training lessons all about using Arduino (you can sign up below).
61 פרקים
Manage episode 269164105 series 2774299
There are a couple good use-case scenarios for making a secret knock detector using an Arduino.
- You are a spy who needs to authenticate your cohorts
- You are a super hero who wants a secret knock to open the entrance to your lair
Whatever the reason - by the end of this tutorial you will know how to use an Arduino, a piezo transducer and a couple other cheap components to make secret knock detector.
Here is an overview of exactly what we will talk about in this lesson:- The components you will need and how to set up this simple circuit.
- The concept of operation of this secret knock detector
- A thorough description of each block of code in the Arduino sketch
- Why North American grizzly bears love piezo transducers
For this secret knock detector circuit you need:
- Arduino (I use the Arduino Uno) [1]
- Solderless breadboard [1]
- 1 Mohm Resistor [1]
- Piezo transducer (aka buzzer) [1]
- Jumper wires [4]
- 5.1V Zener diode (for extra protection) [1]
- No spill stopper for a “to-go” coffee cup
This is a really simple circuit to setup, below are step-by-step instructions and a breadboard diagram.
- Place the piezo transducer on the breadboard, with the positive lead and the negative lead on separate rails.
- Connect the positive lead to pin A0 on the Arduino and the other lead to ground.
- Finally, use the 1Mohm resistor to connect the leads of the piezo transducer.
- As an additional level of protection, you might consider adding a 5.1V zener diode between the leads to protect against high voltage spikes from frying your input pin - you might call it a cheap insurance policy.
Here is the basic concept of how this will work.
We want something to happen when you tap out a secret code.
We will create a sequence of soft and hard taps - this will be our secret code which will be represented as 0’s and 1’s in an array.
For example:
secretKnock[secretKnockLength] = {0, 0, 1, 0};The code above represents a secret code of soft , soft , hard, soft .
The piezo transducer will turn the mechanical pressure created by the tap into a signal that the Arduino analog pin can read. The level of the signal will determine whether a tap gets characterized as soft or hard.
The threshold of a soft vs hard tap need to be determined empirically, once you have the circuit built - it will depend on what you have the piezo transducer attached to - I have mine taped to a piece of paper.
You should start with the default threshold values provided in the sketch and change them to suit your specific setup.
Once a tap signal is picked up by the Arduino, the sketch will compare the entered sequence of taps to the secret code, one tap at a time.
If the code is entered correctly, then we will trigger an action on the output pin. In this code below, we trigger an LED to turn on for a couple seconds - but you could trigger a servo arm, a pump, or whatever you might need.
If the code is entered incorrectly - nothing happens.
Here is the code for your hacking enjoyment:
/* A simple sketch to detect a secret knock using a piezo transducer Created JUL 2015 by Michael James http://www.programmingelectronics.com/ This code is in the public domain */ const int outputPin = 6; // led indicator connected to digital pin const int knockSensor = A0; // the piezo is connected to an analog pin const int thresholdHIGH = 150; // threshold value to decide when the detected knock is hard (HIGH) const int thresholdLOW = 120; // threshold value to decide when the detected knock is gentle (LOW) const int secretKnockLength = 4; //How many knocks are in your secret knock /* This is the secret knock sequence * 0 represents a LOW or quiet knock * 1 represents a HIGH or loud knock * The sequence can be as long as you like, but longer codes increase the difficulty of matching */ const int secretKnock[secretKnockLength] = {0, 0, 1, 0}; int secretCounter = 0; //this tracks the correct knocks and allows you to move through the sequence int sensorReading = 0; // variable to store the value read from the sensor pin void setup() { //Set the output pin as an OUTPUT pinMode(outputPin, OUTPUT); //Begin Serial Communication. Serial.begin(9600); } void loop() { // read the piezo sensor and store the value in the variable sensorReading: sensorReading = analogRead(knockSensor); // First determine is knock if Hard (HIGH) or Gentle (LOW) //Hard knock (HIGH) is detected if (sensorReading >= thresholdHIGH) { //Check to see if a Hard Knock matches the Secret Knock in the correct sequence. if (secretKnock[secretCounter] == 1) { //The Knock was correct, iterate the counter. secretCounter++; Serial.println("Correct"); } else { //The Knock was incorrect, reset the counter secretCounter = 0; Serial.println("Fail - You are a spy!"); }//close if //Allow some time to pass before sampling again to ensure a clear signal. delay(100); //Gentle knock (LOW) is detected } else if (sensorReading >= thresholdLOW) { //Check to see if a Gentle Knock matches the Secret Knock in the correct sequence. if (secretKnock[secretCounter] == 0) { //The Knock was correct, iterate the counter. secretCounter++; Serial.println("Correct"); } else { //The Knock was incorrect, reset the counter. secretCounter = 0; Serial.println("Fail - You are a spy!"); }//close if //Allow some time to pass before sampling again to ensure a clear signal. delay(100); }//close if else //Check for successful entry of the code, by seeing if the entire array has been walked through. if (secretCounter == (secretKnockLength) ) { Serial.println("Welcome in fellow Illuminante!"); //if the sececret knock is correct, illuminate the LED for a couple seconds digitalWrite(outputPin, HIGH); delay(2000); digitalWrite(outputPin, LOW); //Reset the secret counter to 0. secretCounter = 0; }//close success check }//close loopIf you enjoyed this lesson, you should join our free Arduino Crash Course - it has 19 Video Training lessons all about using Arduino (you can sign up below).
61 פרקים
כל הפרקים
×
1 How to make a secret knock detector to trigger anything with only an Arduino and a few cheap components 12:57

1 Arduino Pseudo Random Non-Consecutive Number Generator 11:13

1 How to Use and Understand the Arduino Reference 12:48

1 Using Red-Green-Blue (RGB) LEDs with Arduino (Common Cathode Type) 14:47

1 Using Random Numbers with Arduino 13:02

1 How to Make One Button Have the Functionality of Two or More with Arduino 15:40

1 Understanding HIGH and LOW Arduino Pin States 12:31

1 Floating Pins, Pull-Up Resistors and Arduino 10:29

1 Throw out your breadboard! Dr. Duino: An Arduino Shield for debugging and developing Arduino projects 11:35

1 Shorthand Arithmetic :: Using Compound Operators (+= , -= , *= , /= ) with Arduino 12:43

1 Understanding Boolean Data Types and Using the Boolean NOT (!) operator to Switch Arduino Pin States 8:11

1 What to do when you just don't know :: Arduino, ADXL345 triple axis accelerometer and an RGB LED 14:04

1 3 Ways to Use Acceleration in an Arduino Sketch 17:37

1 Understanding the Arduino uber functions loop() and setup() 10:26

1 Functions: Let's make programming Arduino as easy as possible 11:00

1 Data Types: One size does not fit all 11:15

1 Syntax; the spelling and grammar of programming 11:32

1 Arduino Board Hardware overview for people like me 10:38

1 Everything you need to know about the Arduino IDE (for now) 11:09

1 How to read voltages with analogRead() 14:44

1 analogRead() and the Serial Port 12:02

1 digitalRead() and the Serial Port 21:22

1 How to Blink an LED with Arduino 14:39
ברוכים הבאים אל Player FM!
Player FM סורק את האינטרנט עבור פודקאסטים באיכות גבוהה בשבילכם כדי שתהנו מהם כרגע. זה יישום הפודקאסט הטוב ביותר והוא עובד על אנדרואיד, iPhone ואינטרנט. הירשמו לסנכרון מנויים במכשירים שונים.