WorkshopWeekendAboutTeachLearnWorkshop Weekend: Arduino / Projects / S การแปล - WorkshopWeekendAboutTeachLearnWorkshop Weekend: Arduino / Projects / S ไทย วิธีการพูด

WorkshopWeekendAboutTeachLearnWorks

WorkshopWeekend
About
Teach
Learn
Workshop Weekend: Arduino / Projects / Secret Door Knocker
Build this project at our next weekend-long Arduino workshop!


Secret Door Knocker
The secret door knocker uses a piezo element to record and detect your secret knock pattern, then turns a servo motor that you can connect to your door lock. Press the button to record a knock pattern, then test it by knocking.

Hardware
1 Arduino. We use the Arduino Uno, but any standard Arduino is appropriate for this project.
1 breadboard.
1 servo. You’ll want to explore different servo options to get the one that best suits what you’re looking for — some servos are more powerful than others!
1 red LED.
1 green LED.
1 tactile button. Any push-button switch will do! This button will let us re-program a new knocking sequence.
1 piezo transducer. You’ll use this to detect knocks.
[1 1M Ω resistor]
[1 1K to 10K Ω resistor]
Wires for wiring.
Wiring
Wire up your Arduino as shown in the image below:

Fritzing diagram

The colors of the wires are purely cosmetic; you don’t need to match the colors shown in the diagram.

Software
Run the following code on your Arduino:

/* Secret Door Knock Detecting Door Lock
Originally from Steve Hoefer http://grathio.com Version 0.1.10.20.10
Updates by Lee Sonko

Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0
http://creativecommons.org/licenses/by-nc-sa/3.0/us/
(In short: Do what you want, just be sure to include this line and the four above it, and don't sell it or use it in anything you sell without contacting me.)

Analog Pin 0: Piezo speaker (connected to ground with 1M pulldown resistor)
Digital Pin 2: Switch to enter a new code. Short this to enter programming mode.
Digital Pin 3: DC gear reduction motor attached to the lock. (Or a motor controller or a solenoid or other unlocking mechanisim.)
Digital Pin 4: Red LED.
Digital Pin 5: Green LED.

*/

#include
Servo myservo; // create servo object to control a servo

// Pin definitions
const int knockSensor = 0; // Piezo sensor on pin 0.
const int programSwitch = 2; // If this is high we program a new code.
const int lockMotor = 3; // Gear motor used to turn the lock.
const int redLED = 4; // Status LED
const int greenLED = 5; // Status LED

// Tuning constants. Could be made vars and hoooked to potentiometers for soft configuration, etc.
const int threshold = 50; // Minimum signal from the piezo to register as a knock
const int rejectValue = 25; // If an individual knock is off by this percentage of a knock we don't unlock..
const int averageRejectValue = 15; // If the average timing of the knocks is off by this percent we don't unlock.
const int knockFadeTime = 150; // milliseconds we allow a knock to fade before we listen for another one. (Debounce timer.)
const int lockTurnTime = 650; // milliseconds that we run the motor to get it to go a half turn.
const int unlockTime = 5000; // milliseconds that the door remains unlocked.

const int maximumKnocks = 20; // Maximum number of knocks to listen for.
const int knockComplete = 1200; // Longest time to wait for a knock before we assume that it's finished.

// Variables.
int secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Initial setup: "Shave and a Hair Cut, two bits."
int knockReadings[maximumKnocks]; // When someone knocks this array fills with delays between knocks.
int knockSensorValue = 0; // Last reading of the knock sensor.
int programButtonPressed = false; // Flag so we remember the programming button setting at the end of the cycle.

void setup() {

myservo.attach(lockMotor); // attaches the servo on pin lockMotor to the servo object
// myservo.write(10); // rotate servo into locked position
pinMode(lockMotor, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(programSwitch, INPUT);

Serial.begin(9600); // Uncomment the Serial.bla lines for debugging.
Serial.println("Program start."); // but feel free to comment them out after it's working right.

digitalWrite(greenLED, HIGH); // Green LED on, everything is go.
}

void loop() {
// Listen for any knock at all.
knockSensorValue = analogRead(knockSensor);

if (digitalRead(programSwitch) == HIGH) { // is the program button pressed?
programButtonPressed = true; // Yes, so lets save that state
digitalWrite(redLED, HIGH); // and turn on the red light too so we know we're programming.
} else {
programButtonPressed = false;
digitalWrite(redLED, LOW);
}

if (knockSensorValue >= threshold) {
listenToSecretKnock();
}
}

// Records the timing of knocks.
void listenToSecretKnock() {
Serial.println("knock starting");

int i = 0;
// First lets reset the listening array.
for (i = 0; i < maximumKnocks; i++) {
knockReadings[i] = 0;
}

int currentKnockNumber = 0; // Incrementer for the array.
int startTime = millis(); // Reference for when this knock started.
int now = millis();

digitalWrite(greenLED, LOW); // we blink the LED for a bit as a visual indicator of the knock.
if (programButtonPressed == true) {
digitalWrite(redLED, LOW); // and the red one too if we're programming a new knock.
}
delay(knockFadeTime); // wait for this peak to fade before we listen to the next one.
digitalWrite(greenLED, HIGH);
if (programButtonPressed == true) {
digitalWrite(redLED, HIGH);
}
do {
//listen for the next knock or wait for it to timeout.
knockSensorValue = analogRead(knockSensor);
if (knockSensorValue >= threshold) { //got another knock...
//record the delay time.
Serial.println("knock.");
now = millis();
knockReadings[currentKnockNumber] = now - startTime;
currentKnockNumber ++; //increment the counter
startTime = now;
// and reset our timer for the next knock
digitalWrite(greenLED, LOW);
if (programButtonPressed == true) {
digitalWrite(redLED, LOW); // and the red one too if we're programming a new knock.
}
delay(knockFadeTime); // again, a little delay to let the knock decay.
digitalWrite(greenLED, HIGH);
if (programButtonPressed == true) {
digitalWrite(redLED, HIGH);
}
}

now = millis();

//did we timeout or run out of knocks?
} while ((now - startTime < knockComplete) && (currentKnockNumber < maximumKnocks));

//we've got our knock recorded, lets see if it's valid
if (programButtonPressed == false) { // only if we're not in progrmaing mode.
if (validateKnock() == true) {
triggerDoorUnlock();
} else {
Serial.println("Secret knock failed.");
digitalWrite(greenLED, LOW); // We didn't unlock, so blink the red LED as visual feedback.
for (i = 0; i < 4; i++) {
digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);
delay(100);
}
digitalWrite(greenLED, HIGH);
}
} else { // if we're in programming mode we still validate the lock, we just don't do anything with the lock
validateKnock();
// and we blink the green and red alternately to show that program is complete.
Serial.println("New lock stored.");
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
for (i = 0; i < 3; i++) {
delay(100);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
}
}

// Runs the motor (or whatever) to unlock the door.
void triggerDoorUnlock() {
Serial.println("Door unlocked!");

// unlock the door!
myservo.write(0);

delay(lockTurnTime);
delay(unlockTime);

// lock the door again!
myservo.write(180);

// Blink the green LED a few times for more visual feedback.
for (int i = 0; i < 5; i++) {
digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(greenLED, HIGH);
delay(100);
}

}

// Sees if our knock matches the secret.
// returns true if it's a good knock, false if it's not.
// todo: break it into smaller functions for readability.
boolean validateKnock() {
int i = 0;

// simplest check first: Did we get the right number of knocks?
int currentKnockCount = 0;
int secretKnockCount = 0;
int maxKnockInterval = 0; // We use this later to normalize the times.

for (i = 0; i < maximumKnocks; i++) {
if (knockReadings[i] > 0) {
currentKnockCount++;
}
if (secretCode[i] > 0) { //todo: precalculate this.
secretKnockCount++;
}

if (knockReadings[i] > maxKnockInterval) { // collect normalization data while we're looping.
maxKnockInterval = knockReadings[i];
}
}

// If we're recording a new knock, save the info and get out of here.
if (programButtonPressed == true) {
for (i = 0; i < maximumKnocks; i++) { // normalize the times
secretCode[i] = map(knockReadings[i], 0, maxKnockInterval, 0, 100);
}
// And flash the lights in the recorded pattern to let us know it's been programmed.
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
delay(1000);
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, HIGH);
delay(50);
for (i = 0; i < maximumKnocks ; i++) {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
// only turn it on if there's a delay
if (secretCode[i] > 0) {
delay( map(secretCode[i], 0, 100, 0, maxKnockInterval)); // Expand the time back out to what it was. Roughly.
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, HIGH);
}
0/5000
จาก: -
เป็น: -
ผลลัพธ์ (ไทย) 1: [สำเนา]
คัดลอก!
WorkshopWeekendเกี่ยวกับสอนเรียนรู้วันอบรม: สืบ / โครงการ / ความลับประตู Knockerสร้างโครงการนี้ใน workshop ที่สืบช่วงวันหยุดยาวต่อไปประตูลับ Knockerการใช้ประตูลับ knocker piezo องค์ประกอบการบันทึก และตรวจสอบรูปแบบของลับเคาะ แล้วเปลี่ยนเซอร์โวมอเตอร์ที่คุณสามารถเชื่อมต่อกับกลอนของคุณ กดปุ่มเพื่อบันทึกรูปแบบเคาะ แล้วทดสอบ ด้วยการเคาะฮาร์ดแวร์สืบ 1 เราใช้ Uno สืบ แต่การสืบมาตรฐานเหมาะสมสำหรับโครงการนี้โพรโทบอร์ด 11 servo คุณจะต้องสำรวจตัวเลือก servo ต่าง ๆ ได้ที่เหมาะสมกับสิ่งที่คุณต้องการเช่น servos บางจะมีประสิทธิภาพมากกว่าผู้อื่นLED สีแดง 1LED สีเขียว 1เพราะปุ่ม สวิตช์กดใด ๆ จะทำ ปุ่มนี้จะให้เราโปรแกรมลำดับ knocking หมายใหม่อีกครั้ง1 piezo พิกัด คุณจะใช้รหัสผ่านนี้เพื่อตรวจหาบาง[1 1M Ωตัวต้านทาน][1 1K 10K Ωตัวต้านทาน]สายสำหรับสายสายไฟสายสืบของคุณดังที่แสดงในภาพด้านล่าง:Fritzing ไดอะแกรม สีของสายไฟมีเครื่องสำอางหมดจด คุณไม่จำเป็นต้องตรงกับสีที่แสดงในแผนภาพซอฟต์แวร์เรียกใช้รหัสดังต่อไปนี้บนสืบของคุณ:/ * ประตูลับเคาะตรวจกลอน เดิมจาก Steve Hoefer ที่ http://grathio.com รุ่น 0.1.10.20.10 ปรับปรุง โดย Lee Sonko ได้รับอนุญาตภายใต้ Creative Commons แสดงที่มาไม่กัน 3.0 http://creativecommons.org/licenses/by-nc-sa/3.0/us/ (ในระยะสั้น: ทำสิ่งที่คุณต้อง เพียงตรวจสอบให้แน่ใจว่าบรรทัดนี้ประกอบด้วย 4 ด้าน และไม่ขาย หรือใช้ในสิ่งที่คุณขาย โดยติดต่อผม) แบบแอนะล็อก Pin 0: ลำโพง Piezo (เชื่อมต่อกับพื้นดินที่มีตัวต้านทาน pulldown 1 เมตร) ดิจิตอล Pin 2: สวิทช์ป้อนรหัสใหม่ สั้นนี้จะป้อนโหมดการเขียนโปรแกรม ดิจิทัล Pin 3: DC เกียร์กับล็อคมอเตอร์ลดลง (หรือตัวควบคุมมอเตอร์ หรือเป็น solenoid หรืออื่น ๆ mechanisim ปลดล็อก) 4 Pin ดิจิทัล: ไฟ LED สีแดง 5 Pin ดิจิทัล: ไฟ LED สีเขียว */#include Servo myservo สร้างวัตถุ servo ควบคุม servoข้อกำหนด pinknockSensor int ค่า const = 0 เซนเซอร์ Piezo ใน pin 0programSwitch int ค่า const = 2 ถ้าเป็นสูง เราโปรแกรมรหัสใหม่lockMotor int ค่า const = 3 เกียร์มอเตอร์ที่ใช้ในการเปิดการล็อกค่า const int redLED = 4 สถานะ LEDgreenLED int ค่า const = 5 สถานะ LEDปรับแต่งค่าคงที่ สามารถกับ vars และ hoooked potentiometers โครงอ่อน ฯลฯขีดจำกัดของ int ค่า const = 50 สัญญาณต่ำสุดจาก piezo ที่ลงเคาะrejectValue int ค่า const = 25 ถ้าการเคาะแต่ละจะปิดตามเปอร์เซ็นต์ของเคาะเราไม่ปลดล็อค...averageRejectValue int ค่า const = 15 ถ้าระยะเวลาเฉลี่ยของบางถูกปิดนี้เปอร์เซ็นต์เราไม่ปลดล็อกknockFadeTime int ค่า const = 150 มิลลิวินาทีที่เราอนุญาตให้เคาะจางก่อนเราฟังอีก (Debounce จับเวลา)lockTurnTime int ค่า const = 650 มิลลิวินาทีที่เราเรียกใช้มอเตอร์เข้าไปครึ่งเปิดunlockTime int ค่า const = 5000 มิลลิวินาทีที่ประตูจะปลดล็อคค่า const int maximumKnocks = 20 จำนวนสูงสุดของบางฟังสำหรับknockComplete int ค่า const = 1200 เวลายาวนานที่สุดเพื่อรอการเคาะก่อนเราคิดว่า มันเสร็จตัวแปรint secretCode [maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ตั้งค่าเริ่มต้น: "โกนและตัดเส้นผม สองบิต"int knockReadings [maximumKnocks]; เมื่อคน knocks เรย์นี้กรอกข้อมูล มีความล่าช้าระหว่างบางint knockSensorValue = 0 อ่านล่าสุดของเซ็นเซอร์เคาะint programButtonPressed = false ค่าสถานะเพื่อให้เราจดจำการตั้งค่าปุ่มเขียนในตอนท้ายของรอบ{ยกเลิก setup() myservo.attach(lockMotor) แนบ servo ใน pin lockMotor วัตถุ servo myservo.write(10) servo หมุนไปยังตำแหน่งล็อค pinMode (lockMotor แสดงผล), pinMode (redLED แสดงผล), pinMode (greenLED แสดงผล), pinMode (programSwitch ป้อนข้อมูล); Serial.begin(9600) Uncomment บรรทัด Serial.bla สำหรับการดีบัก Serial.println ("โปรแกรมเริ่มต้น"); แต่รู้สึกคิดออกหลังจากนั้นทำงานอยู่ digitalWrite (greenLED สูง); เขียวไฟบน ทุกอย่างเป็นไป}{ยกเลิก loop() ฟังการเคาะใด ๆ เลย knockSensorValue = analogRead(knockSensor) ถ้า (digitalRead(programSwitch) ==สูง) { / / กดปุ่มโปรแกรมได้หรือไม่ programButtonPressed = true ใช่ เพื่อให้บันทึกสถานะนั้น digitalWrite (redLED สูง); เปิดไฟสีแดงเกินไปเพื่อให้เรารู้ว่า เรากำลังเขียนโปรแกรม } {อื่น programButtonPressed = false digitalWrite (redLED ต่ำ), } ถ้า (knockSensorValue > =ขีดจำกัด) { listenToSecretKnock() }}บันทึกเวลาของตกหล่น{ยกเลิก listenToSecretKnock() Serial.println ("เคาะราคาเริ่มต้น"); int ฉัน = 0 ก่อน ทำให้รีเรย์ฟัง สำหรับ (ฉัน = 0 ฉัน < maximumKnocks; i ++) { knockReadings [i] = 0 } int currentKnockNumber = 0 Incrementer ในอาร์เรย์ เวลาเริ่มต้นเวลา int = millis() การอ้างอิงสำหรับเมื่อเริ่มเคาะนี้ int = millis() เดี๋ยวนี้ digitalWrite (greenLED ต่ำ), เรากะพริบไฟ LED จะเป็นตัวบ่งชี้ที่ภาพของการเคาะ ถ้า (programButtonPressed ==จริง) { digitalWrite (redLED ต่ำ), และสีแดงเกินไปถ้าเรากำลังเขียนโปรแกรมเคาะใหม่ } delay(knockFadeTime) รอช่วงนี้จางก่อนเราฟังถัดไป digitalWrite (greenLED สูง); ถ้า (programButtonPressed ==จริง) { digitalWrite (redLED สูง); } ทำ{ ฟังเสียงเคาะถัดไป หรือรอให้ถึงเวลา knockSensorValue = analogRead(knockSensor) ถ้า (knockSensorValue > =ขีดจำกัด) {//got อีกเคาะ... บันทึกเวลาที่ล่าช้า Serial.println("knock.") ตอนนี้ = millis() knockReadings [currentKnockNumber] =วันนี้ - เวลาเริ่มต้นเวลา currentKnockNumber ++; เพิ่มค่าตัวนับ เวลาเริ่มต้นเวลา =ตอนนี้ และตั้งค่าเวลาสำหรับเคาะถัดไปของเรา digitalWrite (greenLED ต่ำ), ถ้า (programButtonPressed ==จริง) { digitalWrite (redLED ต่ำ), และสีแดงเกินไปถ้าเรากำลังเขียนโปรแกรมเคาะใหม่ } delay(knockFadeTime) อีก น้อยเลื่อนให้ผุเคาะ digitalWrite (greenLED สูง); ถ้า (programButtonPressed ==จริง) { digitalWrite (redLED สูง); } } ตอนนี้ = millis() ไม่เราหมดเวลาหรือเรียกใช้จากบาง } ขณะ ((วันนี้ - เวลาเริ่มต้นเวลา < knockComplete) & & (currentKnockNumber < maximumKnocks)); เราได้เคาะเราบันทึก ให้ดูว่า มันถูกต้อง ถ้า (programButtonPressed == false) { / / ถ้าเราไม่ได้อยู่ในโหมด progrmaing เท่านั้น ถ้า (validateKnock() ==จริง) { triggerDoorUnlock() } {อื่น Serial.println ("ลับเคาะล้มเหลว"); digitalWrite (greenLED ต่ำ), เราไม่ได้ปลดล็อค กะพริบไฟ LED สีแดงเป็นคำติชมภาพดังนั้น สำหรับ (ฉัน = 0 ฉัน < 4; i ++) { digitalWrite (redLED สูง); delay(100) digitalWrite (redLED ต่ำ), delay(100) } digitalWrite (greenLED สูง); } } อื่น { / / ถ้าเราอยู่ในโหมดการเขียนโปรแกรม เรายังตรวจสอบล็อค เราเพียงแค่ไม่ได้ทำอะไรกับล็อค validateKnock() และเรากะพริบสีเขียว และสีแดงสลับการแสดงโปรแกรมที่เสร็จสมบูรณ์ Serial.println ("ใหม่ล็อคเก็บ"); digitalWrite (redLED ต่ำ), digitalWrite (greenLED สูง); สำหรับ (ฉัน = 0 ฉัน < 3; i ++) { delay(100) digitalWrite (redLED สูง); digitalWrite (greenLED ต่ำ), delay(100) digitalWrite (redLED ต่ำ), digitalWrite (greenLED สูง); } }}ทำงานมอเตอร์ (หรืออะไรก็ตาม) เพื่อปลดล็อคประตู{ยกเลิก triggerDoorUnlock() Serial.println ("ประตูปลดล็อค"); ปลดล็อคประตู myservo.write(0) delay(lockTurnTime) delay(unlockTime) ล็อคประตูอีกครั้ง myservo.write(180) กะพริบไฟ LED สีเขียวกี่ครั้งสำหรับผลป้อนกลับภาพเพิ่มเติม สำหรับ (int ฉัน = 0 ฉัน < 5; i ++) { digitalWrite (greenLED ต่ำ), delay(100) digitalWrite (greenLED สูง); delay(100) }}เห็นว่า เคาะของเราตรงกับความลับคืนค่าจริงถ้าเคาะดี ไม่เท็จtodo: แบ่งออกเป็นฟังก์ชันย่อย ๆ สำหรับการอ่าน{validateKnock() บูลีน int ฉัน = 0 ง่ายที่สุดตรวจสอบก่อน: เราไม่ได้รับหมายเลขของตกหล่นหรือไม่ int currentKnockCount = 0 int secretKnockCount = 0 int maxKnockInterval = 0 เราใช้หลังเวลาปกติ สำหรับ (ฉัน = 0 ฉัน < maximumKnocks; i ++) { ถ้า{(knockReadings [i] > 0) currentKnockCount ++ } ถ้า (secretCode [i] > 0) { / / todo: precalculate นี้ secretKnockCount ++ } ถ้า (knockReadings [i] > maxKnockInterval) { / / รวบรวมข้อมูลการฟื้นฟูในขณะที่เรากำลังมีการวนรอบ maxKnockInterval = knockReadings [i]; } } ถ้าเรากำลังบันทึกเคาะใหม่ บันทึกข้อมูล และออกจากที่นี่ ถ้า (programButtonPressed ==จริง) { สำหรับ (ฉัน = 0 ฉัน < maximumKnocks; i ++) { / / ปกติเวลา secretCode [i] =แผนที่ (knockReadings [i], 0, maxKnockInterval, 0, 100); } และแฟลชไฟในรูปแบบการบันทึกให้เราทราบการโปรแกรม digitalWrite (greenLED ต่ำ), digitalWrite (redLED ต่ำ), delay(1000) digitalWrite (greenLED สูง); digitalWrite (redLED สูง); delay(50) สำหรับ (ฉัน = 0 ฉัน < maximumKnocks; i ++) { digitalWrite (greenLED ต่ำ), digitalWrite (redLED ต่ำ), เพียง เปิดใช้ถ้ามีการเลื่อนเวลา ถ้า{(secretCode [i] > 0) ความล่าช้า (แผนที่ (secretCode [i], 0, 100, 0, maxKnockInterval)); ขยายเวลากลับออกไปมันก็ อย่างคร่าว ๆ digitalWrite (greenLED สูง); digitalWrite (redLED สูง); }
การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 2:[สำเนา]
คัดลอก!
WorkshopWeekend เกี่ยวกับสอนเรียนรู้การประชุมเชิงปฏิบัติการวันหยุดสุดสัปดาห์: Arduino / โครงการ / ความลับเคาะประตู! สร้างโครงการนี้ในการประชุมเชิงปฏิบัติการ Arduino ยาววันหยุดสุดสัปดาห์ของเราต่อไปลับเคาะประตูเคาะประตูลับใช้องค์ประกอบแบบpiezo ที่จะบันทึกและตรวจสอบรูปแบบเคาะลับของคุณจากนั้นก็หันเซอร์โว มอเตอร์ที่คุณสามารถเชื่อมต่อกับล็อคประตูของคุณ กดปุ่มเพื่อบันทึกรูปแบบเคาะแล้วทดสอบโดยการเคาะ. ฮาร์ดแวร์1 Arduino เราใช้ Arduino Uno แต่มาตรฐานใด ๆ Arduino มีความเหมาะสมสำหรับโครงการนี้. 1 ชนบท. 1 เซอร์โว คุณจะต้องการที่จะสำรวจตัวเลือกที่แตกต่างกันเซอร์โวจะได้รับหนึ่งที่เหมาะสมกับสิ่งที่ดีที่สุดสิ่งที่คุณกำลังมองหา! - เซอร์โวบางส่วนมีประสิทธิภาพมากขึ้นกว่าคนอื่น ๆ1 ไฟ LED สีแดง. 1 ไฟ LED สีเขียว. 1 ปุ่มสัมผัส สวิทช์ปุ่มกดใด ๆ ที่จะทำ! ปุ่มนี้จะช่วยให้เราอีกครั้งโปรแกรมลำดับเคาะใหม่. 1 แปลงสัญญาณแบบ piezo คุณจะใช้วิธีนี้ในการตรวจสอบเคาะ. [1 ตัวต้านทาน 1M Ω] [1 1K จะต้านทาน 10K Ω] สายไฟสำหรับการเดินสาย. สายไฟลวดขึ้น Arduino ของคุณตามที่แสดงในภาพด้านล่าง: Fritzing แผนภาพสีของสายไฟที่มีเครื่องสำอางอย่างหมดจด; คุณไม่จำเป็นต้องให้ตรงกับสีที่แสดงในแผนภาพ. ซอฟแวร์การเรียกใช้รหัสต่อไปนี้บน Arduino คุณ: / * ลับเคาะประตูตรวจจับล็อคประตูมีพื้นเพมาจากสตีฟHoefer http://grathio.com รุ่น 0.1.10.20.10 ปรับปรุงโดย ลีโกได้รับใบอนุญาตภายใต้Creative Commons Attribution-Noncommercial-Share Alike 3.0 http://creativecommons.org/licenses/by-nc-sa/3.0/us/ (ในระยะสั้น: ทำในสิ่งที่คุณต้องการเพียงให้แน่ใจว่าจะรวมถึงบรรทัดนี้และ สี่ข้างต้นนั้นและไม่ได้ขายหรือใช้ในสิ่งที่คุณขายโดยไม่ต้องติดต่อฉัน). อะนาล็อกขา 0: ลำโพง Piezo (เชื่อมต่อกับพื้นดินที่มีความต้านทาน 1M แบบเลื่อนลง) ดิจิตอลพิน 2: เปลี่ยนไปใส่รหัสใหม่ สั้น ๆ นี้เพื่อเข้าสู่โหมดการเขียนโปรแกรม. ดิจิตอลขาที่ 3: DC มอเตอร์เกียร์ลดแนบมากับล็อค (หรือตัวควบคุมมอเตอร์หรือขดลวดแม่เหล็กไฟฟ้าหรือปลดล็อค mechanisim อื่น ๆ .) ดิจิตอลพิน. 4: LED สีแดงดิจิตอลพิน. 5: LED สีเขียว* / #include
















































Servo myservo; // สร้างวัตถุเซอร์โวการควบคุมเซอร์โว// คำจำกัดความขาconst int knockSensor = 0; // เซ็นเซอร์ Piezo บนขา 0. const int programSwitch = 2; // ถ้าเป็นสูงเราเขียนโปรแกรมรหัสใหม่. const int lockMotor = 3; // เกียร์มอเตอร์ที่ใช้ในการเปิดล็อค. const int redLED = 4; // LED แสดงสถานะconst int greenLED = 5; // LED แสดงสถานะ// ค่าคงที่การปรับแต่ง อาจจะทำ vars และ hoooked เพื่อมิเตอร์สำหรับการตั้งค่าที่อ่อนนุ่ม ฯลฯconst เกณฑ์ int = 50; // สัญญาณขั้นต่ำจากแบบ piezo ที่จะลงทะเบียนเป็นผู้เคาะconst int rejectValue = 25; // หากเคาะแต่ละปิดโดยร้อยละของการเคาะนี้เราไม่ปลดล็อค .. const int averageRejectValue = 15; // ถ้าระยะเวลาเฉลี่ยของการเคาะปิดร้อยละนี้เราไม่ปลดล็อค. const int knockFadeTime = 150; // มิลลิวินาทีเราอนุญาตให้เคาะจะจางหายไปก่อนที่เราจะฟังอีกคนหนึ่ง (. จับเวลา debounce) const int lockTurnTime = 650; // มิลลิวินาทีที่เราเรียกใช้มอเตอร์ที่จะได้รับมันไปเปิดครึ่ง. const int unlockTime = 5000; // มิลลิวินาทีที่ประตูยังคงปลดล็อค. const int maximumKnocks = 20; // จำนวนสูงสุดของเคาะฟัง. const int knockComplete = 1200; // เวลาที่ยาวที่สุดที่จะรอให้เคาะก่อนที่เราคิดว่ามันเสร็จ. // ตัวแปร. int SECRETCODE [maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0}; // ตั้งค่าเริ่มต้น: ". และโกนผมตัดสองบิต" int knockReadings [maximumKnocks]; // เมื่อมีคนเคาะอาร์เรย์นี้อบอวลไปด้วยความล่าช้าระหว่างเคาะ. int knockSensorValue = 0; // อ่านล่าสุดของเซ็นเซอร์เคาะ. int programButtonPressed = false; // ธงเพื่อให้เราจำไว้ว่าการตั้งค่าปุ่มการเขียนโปรแกรมในตอนท้ายของวงจรที่. ติดตั้งเป็นโมฆะ () {myservo.attach (lockMotor); // เซอร์โวยึดติดอยู่กับขา lockMotor ไปยังวัตถุเซอร์โว// myservo.write (10); // หมุนเซอร์โวลงในตำแหน่งล็อคpinMode (lockMotor, OUTPUT); pinMode (redLED, OUTPUT); pinMode (greenLED, OUTPUT); pinMode (programSwitch, INPUT); Serial.begin (9600); // Uncomment สาย Serial.bla สำหรับการดีบัก. Serial.println ("เริ่มต้นโปรแกรม."); . // แต่รู้สึกอิสระที่จะแสดงความคิดเห็นออกมาหลังจากที่พวกเขาจะทำงานที่เหมาะสมdigitalWrite (greenLED, HIGH); // สีเขียว LED บนทุกอย่างเป็นไป.} ห่วงเป็นโมฆะ () {// ฟังเคาะใด ๆ . knockSensorValue = analogRead (knockSensor); if (digitalRead (programSwitch) == HIGH) {// เป็นปุ่มกดโปรแกรม ? programButtonPressed = true; // ใช่เพื่อช่วยให้บันทึกว่ารัฐdigitalWrite (redLED, HIGH); // และเปิดไฟสีแดงเช่นกันเพื่อให้เรารู้ว่าเรากำลังเขียนโปรแกรม.} else {programButtonPressed = false; digitalWrite (redLED, ต่ำ);} ถ้า (knockSensorValue> = เกณฑ์) {listenToSecretKnock ();}} // ระเบียน . ระยะเวลาของการเคาะโมฆะlistenToSecretKnock () {Serial.println ("เคาะเริ่มต้น"); int i = 0; // แรกให้ตั้งค่าอาร์เรย์ฟัง. สำหรับ (i = 0; i <maximumKnocks ผม ++) {knockReadings [ผม] = 0;} int currentKnockNumber = 0; // Incrementer สำหรับอาร์เรย์. int startTime = MILLIS (); . // อ้างอิงสำหรับเมื่อเคาะเริ่มint ตอนนี้ = MILLIS (); digitalWrite (greenLED, ต่ำ); // เรากระพริบไฟ LED สำหรับบิตเป็นตัวบ่งชี้ที่มองเห็นของเคาะ. ถ้า (programButtonPressed == จริง) {digitalWrite (redLED, ต่ำ); . // และสีแดงเกินไปถ้าเราเขียนโปรแกรมเคาะใหม่} ล่าช้า (knockFadeTime); // รอจุดสูงสุดนี้จะจางหายไปก่อนที่เราจะฟังอย่างใดอย่างหนึ่งต่อไป. digitalWrite (greenLED, HIGH); if (programButtonPressed == จริง) {digitalWrite (redLED, HIGH);} ไม่ {// ฟังเคาะถัดไปหรือรอ มันหมดเวลา. knockSensorValue = analogRead (knockSensor); if (knockSensorValue> = เกณฑ์) {// ได้เคาะอื่น ... // บันทึกเวลาล่าช้า. Serial.println ("เคาะ."); ตอนนี้ = MILLIS () ; knockReadings [currentKnockNumber] = ตอนนี้ - startTime; currentKnockNumber ++; // เพิ่มเคาน์เตอร์startTime = ตอนนี้; // และตั้งค่าตัวจับเวลาของเราต่อไปเคาะdigitalWrite (greenLED, ต่ำ); if (programButtonPressed == จริง) {digitalWrite (redLED, ต่ำ); . // และสีแดงเกินไปถ้าเราเขียนโปรแกรมเคาะใหม่} ล่าช้า (knockFadeTime); // อีกครั้งล่าช้าเล็ก ๆ น้อย ๆ ที่จะปล่อยให้ผุเคาะ. digitalWrite (greenLED, HIGH); if (programButtonPressed == จริง) {digitalWrite (redLED, HIGH);}} ตอนนี้ = MILLIS (); // พวกเราหมดเวลาหรือเรียกใช้ ออกจากความทุกข์?} ในขณะที่ ((ตอนนี้ - startTime <knockComplete) && (currentKnockNumber <maximumKnocks)); // เราได้มีการเคาะของเราบันทึกช่วยให้ดูว่ามันถูกต้องถ้า(programButtonPressed == เท็จ) {// เฉพาะในกรณีที่เรา กำลังไม่ได้อยู่ในโหมด progrmaing. ถ้า (validateKnock () == จริง) {triggerDoorUnlock ();} else {Serial.println ("เคาะลับล้มเหลว."); digitalWrite (greenLED, ต่ำ); // เราไม่ได้ปลดล็อคเพื่อให้กระพริบไฟ LED สีแดงเป็นข้อเสนอแนะภาพ. สำหรับ (i = 0; i <4 ผม ++) {digitalWrite (redLED, HIGH); ล่าช้า (100); digitalWrite (redLED, ต่ำ); ล่าช้า (100);} digitalWrite (greenLED, HIGH);}} else {// ถ้าเราอยู่ในโหมดการเขียนโปรแกรมเรายังคงตรวจสอบล็อคเราก็ไม่ได้ทำอะไรกับล็อคvalidateKnock (); // และเรากระพริบตา สีเขียวและสีแดงสลับกันเพื่อแสดงโปรแกรมที่สมบูรณ์. Serial.println ("ล็อคใหม่เก็บไว้."); digitalWrite (redLED, ต่ำ); digitalWrite (greenLED, HIGH) สำหรับ (i = 0; i <3 ฉัน ++) {ล่าช้า(100); digitalWrite (redLED, HIGH); digitalWrite (greenLED, ต่ำ); ล่าช้า (100); digitalWrite (redLED, ต่ำ); digitalWrite (greenLED, HIGH);}}} // วิ่งมอเตอร์ (หรืออะไรก็ตาม ) เพื่อปลดล็อคประตู. เป็นโมฆะ triggerDoorUnlock () {Serial.println () "ประตูปลดล็อค!"; // ปลดล็อคประตู! myservo.write (0); ล่าช้า (lockTurnTime); ล่าช้า (unlockTime); // ล็อคประตู ! อีกครั้งmyservo.write (180); // Blink ไฟ LED สีเขียวไม่กี่ครั้งสำหรับความคิดเห็นของภาพมากขึ้น. สำหรับ (int i = 0; i <5; ฉัน ++) {digitalWrite (greenLED, ต่ำ); ล่าช้า (100); digitalWrite (greenLED, HIGH); ล่าช้า (100);}} // เห็นถ้าเคาะของเราตรงกับความลับ. // ผลตอบแทนจริงถ้ามันเคาะดีเท็จหากยังไม่ได้. // สิ่งที่ต้องทำ: ทำลายมันลงไปในฟังก์ชั่นที่มีขนาดเล็กสำหรับการอ่านบูล validateKnock () {int i = 0; // ง่ายตรวจสอบครั้งแรก: พวกเราได้รับจำนวนเคาะขวาของint currentKnockCount = 0; int secretKnockCount = 0; int maxKnockInterval = 0; // เราใช้นี้ในภายหลังที่จะปรับครั้ง. สำหรับ (i = 0; i <maximumKnocks ผม ++) {if (knockReadings [ผม]> 0) {currentKnockCount ++;} ถ้า (SECRETCODE [ผม]> 0) {// สิ่งที่ต้องทำ : precalculate นี้. secretKnockCount ++;} ถ้า (knockReadings [ผม]> maxKnockInterval) {// การเก็บรวบรวมข้อมูลการฟื้นฟูขณะที่เรากำลังวนลูป. maxKnockInterval = knockReadings [ผม];}} // ถ้าเราบันทึกเคาะใหม่บันทึก ข้อมูลและได้รับการออกจากที่นี่. ถ้า (programButtonPressed == จริง) {สำหรับ(i = 0; i <maximumKnocks ผม ++) {// ปกติครั้งSECRETCODE [ผม] = แผนที่ (knockReadings [ผม], 0, maxKnockInterval, 0 100);} // และกระพริบไฟในรูปแบบที่บันทึกไว้เพื่อให้เรารู้ว่ามันถูกตั้งโปรแกรม. digitalWrite (greenLED, ต่ำ); digitalWrite (redLED, ต่ำ); ล่าช้า (1000) digitalWrite (greenLED, HIGH); digitalWrite (redLED, HIGH); ล่าช้า (50); สำหรับ (i = 0; i <maximumKnocks ผม ++) {digitalWrite (greenLED, ต่ำ); digitalWrite (redLED, ต่ำ); // เพียงเปิดถ้ามีความล่าช้าถ้า( SECRETCODE [ผม]> 0) {ล่าช้า(แผนที่ (SECRETCODE [ผม], 0, 100, 0, maxKnockInterval)); // ขยายเวลากลับออกมากับสิ่งที่มันเป็น . ประมาณdigitalWrite (greenLED, HIGH); digitalWrite (redLED, HIGH);}















































































































































































































การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 3:[สำเนา]
คัดลอก!
He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.He wants to listen this song.
การแปล กรุณารอสักครู่..
 
ภาษาอื่น ๆ
การสนับสนุนเครื่องมือแปลภาษา: กรีก, กันนาดา, กาลิเชียน, คลิงออน, คอร์สิกา, คาซัค, คาตาลัน, คินยารวันดา, คีร์กิซ, คุชราต, จอร์เจีย, จีน, จีนดั้งเดิม, ชวา, ชิเชวา, ซามัว, ซีบัวโน, ซุนดา, ซูลู, ญี่ปุ่น, ดัตช์, ตรวจหาภาษา, ตุรกี, ทมิฬ, ทาจิก, ทาทาร์, นอร์เวย์, บอสเนีย, บัลแกเรีย, บาสก์, ปัญจาป, ฝรั่งเศส, พาชตู, ฟริเชียน, ฟินแลนด์, ฟิลิปปินส์, ภาษาอินโดนีเซี, มองโกเลีย, มัลทีส, มาซีโดเนีย, มาราฐี, มาลากาซี, มาลายาลัม, มาเลย์, ม้ง, ยิดดิช, ยูเครน, รัสเซีย, ละติน, ลักเซมเบิร์ก, ลัตเวีย, ลาว, ลิทัวเนีย, สวาฮิลี, สวีเดน, สิงหล, สินธี, สเปน, สโลวัก, สโลวีเนีย, อังกฤษ, อัมฮาริก, อาร์เซอร์ไบจัน, อาร์เมเนีย, อาหรับ, อิกโบ, อิตาลี, อุยกูร์, อุสเบกิสถาน, อูรดู, ฮังการี, ฮัวซา, ฮาวาย, ฮินดี, ฮีบรู, เกลิกสกอต, เกาหลี, เขมร, เคิร์ด, เช็ก, เซอร์เบียน, เซโซโท, เดนมาร์ก, เตลูกู, เติร์กเมน, เนปาล, เบงกอล, เบลารุส, เปอร์เซีย, เมารี, เมียนมา (พม่า), เยอรมัน, เวลส์, เวียดนาม, เอสเปอแรนโต, เอสโทเนีย, เฮติครีโอล, แอฟริกา, แอลเบเนีย, โคซา, โครเอเชีย, โชนา, โซมาลี, โปรตุเกส, โปแลนด์, โยรูบา, โรมาเนีย, โอเดีย (โอริยา), ไทย, ไอซ์แลนด์, ไอร์แลนด์, การแปลภาษา.

Copyright ©2026 I Love Translation. All reserved.

E-mail: