SlideShare a Scribd company logo
1 of 8
Listing Program for Smart Door Knocker based on Arduino UNO R3
/* SecretDoor KnockDetectingDoorLock
OriginallyfromSteveHoeferhttp://grathio.comVersion0.1.10.20.10
Updatesby Lee Sonko
LicensedunderCreativeCommonsAttribution-Noncommercial-Share Alike3.0
http://creativecommons.org/licenses/by-nc-sa/3.0/us/
(Inshort: Do whatyou want,justbe sure to include thisline andthe fourabove it,anddon't sell it
or use it inanythingyousell withoutcontactingme.)
Modifiedby:DindaEkaPratiwi (RefrigerationandAirConditioningCollager,PolytechnicState of
Bandung) (November2015)
*/
#include <Servo.h>
Servomyservo;
const intknockSensor=0;
const intprogramSwitch= 3;
const intlockMotor= 6;
const intredLED = 4;
const intgreenLED= 5;
const intbuzzer= 2;
const intthreshold=50;
const intrejectValue=25;
const intaverageRejectValue=15;
const intknockFadeTime =150;
const intlockTurnTime =650;
const intunlockTime =5000;
const intmaximumKnocks=20;
const intknockComplete=1200;
// Variables.
intsecretCode[maximumKnocks] ={50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
intknockReadings[maximumKnocks];
intknockSensorValue =0;
intprogramButtonPressed=false;
voidsetup() {
myservo.attach(lockMotor);
pinMode(lockMotor,OUTPUT);
pinMode(redLED,OUTPUT);
pinMode(greenLED,OUTPUT);
pinMode(programSwitch,INPUT);
pinMode (buzzer,OUTPUT);
Serial.begin(9600);
Serial.println("Programstart.");
digitalWrite(greenLED,HIGH);
}
voidloop() {
knockSensorValue =analogRead(knockSensor);
if (digitalRead(programSwitch) ==HIGH) {
programButtonPressed=true;
digitalWrite(redLED,HIGH);
} else {
programButtonPressed=false;
digitalWrite(redLED,LOW);
}
if (knockSensorValue >=threshold) {
listenToSecretKnock();
}
}
voidlistenToSecretKnock() {
Serial.println("knockstarting");
inti = 0;
for(i = 0; i < maximumKnocks; i++) {
knockReadings[i] =0;
}
intcurrentKnockNumber=0;
intstartTime = millis();
intnow= millis();
digitalWrite(greenLED,LOW);
if (programButtonPressed==true) {
digitalWrite(redLED,LOW);
}
delay(knockFadeTime);
digitalWrite(greenLED,HIGH);
if (programButtonPressed==true) {
digitalWrite(redLED,HIGH);
}
do{
knockSensorValue =analogRead(knockSensor);
if (knockSensorValue>=threshold) {
Serial.println("knock.");
now= millis();
knockReadings[currentKnockNumber] =now - startTime;
currentKnockNumber++;
startTime = now;
digitalWrite(greenLED,LOW);
if (programButtonPressed==true) {
digitalWrite(redLED,LOW);
}
delay(knockFadeTime);
digitalWrite(greenLED,HIGH);
if (programButtonPressed==true) {
digitalWrite(redLED,HIGH);
}
}
now = millis();
} while ((now - startTime <knockComplete) &&(currentKnockNumber<maximumKnocks));
if (programButtonPressed==false) {
if (validateKnock()==true) {
triggerDoorUnlock();
} else {
Serial.println("Secretknockfailed.");
digitalWrite(greenLED,LOW);
for (i = 0; i < 4; i++) {
digitalWrite(redLED,HIGH);
delay(100);
digitalWrite(redLED,LOW);
delay(100);
digitalWrite(2,LOW);
delay(1000);
digitalWrite(2,HIGH);
delay(1000);
}
digitalWrite(greenLED,HIGH);
}
} else {
validateKnock();
Serial.println("New lockstored.");
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);
}
}
}
voidtriggerDoorUnlock(){
Serial.println("Doorunlocked!");
myservo.write(0);
delay(lockTurnTime);
delay(unlockTime);
myservo.write(180);
for(inti = 0; i < 5; i++) {
digitalWrite(greenLED,LOW);
delay(100);
digitalWrite(greenLED,HIGH);
delay(100);
}
}
booleanvalidateKnock(){
inti = 0;
intcurrentKnockCount=0;
intsecretKnockCount=0;
intmaxKnockInterval =0;
for(i = 0; i < maximumKnocks;i++) {
if (knockReadings[i] >0) {
currentKnockCount++;
}
if (secretCode[i] >0) {
secretKnockCount++;
}
if (knockReadings[i] >maxKnockInterval){
maxKnockInterval =knockReadings[i];
}
}
if (programButtonPressed==true) {
for (i = 0; i < maximumKnocks;i++) { // normalize the times
secretCode[i] =map(knockReadings[i],0,maxKnockInterval,0,100);
}
// Andflashthe lightsinthe recordedpatterntoletus know it's beenprogrammed.
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);
if (secretCode[i]>0) {
delay( map(secretCode[i],0,100, 0, maxKnockInterval));
digitalWrite(greenLED,HIGH);
digitalWrite(redLED,HIGH);
}
delay(50);
}
returnfalse;
}
if (currentKnockCount!=secretKnockCount) {
returnfalse;
}
inttotaltimeDifferences=0;
inttimeDiff =0;
for(i = 0; i < maximumKnocks;i++) { // Normalize the times
knockReadings[i] =map(knockReadings[i],0,maxKnockInterval,0,100);
timeDiff =abs(knockReadings[i] - secretCode[i]);
if (timeDiff >rejectValue){ //Individual value toofaroutof whack
returnfalse;
}
totaltimeDifferences+=timeDiff;
}
if (totaltimeDifferences/secretKnockCount>averageRejectValue) {
returnfalse;
}
returntrue;
}

More Related Content

Similar to Listing program for smart door knocker based on arduino uno r3

Similar to Listing program for smart door knocker based on arduino uno r3 (20)

An introduction to Internet of Things and Maker Movement
An introduction to Internet of Things and Maker MovementAn introduction to Internet of Things and Maker Movement
An introduction to Internet of Things and Maker Movement
 
Jackpot! sbancare un atm con ploutus.d
Jackpot! sbancare un atm con ploutus.dJackpot! sbancare un atm con ploutus.d
Jackpot! sbancare un atm con ploutus.d
 
FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference
 FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference
FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference
 
Internet of Things & Open Hardware (LeanCamp Madrid 2012)
Internet of Things & Open Hardware (LeanCamp Madrid 2012)Internet of Things & Open Hardware (LeanCamp Madrid 2012)
Internet of Things & Open Hardware (LeanCamp Madrid 2012)
 
IRJET - IoT based Anti Theft Detection and Alerting System using Raspberry Pi
IRJET - IoT based Anti Theft Detection and Alerting System using Raspberry PiIRJET - IoT based Anti Theft Detection and Alerting System using Raspberry Pi
IRJET - IoT based Anti Theft Detection and Alerting System using Raspberry Pi
 
IRJET- IOT Dune Buggy –Control it from Anywhere
IRJET-  	  IOT Dune Buggy –Control it from AnywhereIRJET-  	  IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from Anywhere
 
IRJET- IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from AnywhereIRJET- IOT Dune Buggy –Control it from Anywhere
IRJET- IOT Dune Buggy –Control it from Anywhere
 
A LIGHTWEIGHT PAYMENT VERIFICATION USING BLOCKCHAIN ALGORITHM ON IoT DEVICES
A LIGHTWEIGHT PAYMENT VERIFICATION USING BLOCKCHAIN ALGORITHM ON IoT DEVICESA LIGHTWEIGHT PAYMENT VERIFICATION USING BLOCKCHAIN ALGORITHM ON IoT DEVICES
A LIGHTWEIGHT PAYMENT VERIFICATION USING BLOCKCHAIN ALGORITHM ON IoT DEVICES
 
3-ZeroLab_smart_contract-2008.pptx
3-ZeroLab_smart_contract-2008.pptx3-ZeroLab_smart_contract-2008.pptx
3-ZeroLab_smart_contract-2008.pptx
 
Continuous integration with Docker
Continuous integration with DockerContinuous integration with Docker
Continuous integration with Docker
 
Cisco Malware: A new risk to consider in perimeter security designs
Cisco Malware: A new risk to consider in perimeter security designsCisco Malware: A new risk to consider in perimeter security designs
Cisco Malware: A new risk to consider in perimeter security designs
 
IoT Development from Software Developer Perspective
IoT Development from Software Developer PerspectiveIoT Development from Software Developer Perspective
IoT Development from Software Developer Perspective
 
ShinoBOT Suite
ShinoBOT SuiteShinoBOT Suite
ShinoBOT Suite
 
Alberto Mancini - A few benchmark on Android
Alberto Mancini - A few benchmark on AndroidAlberto Mancini - A few benchmark on Android
Alberto Mancini - A few benchmark on Android
 
Verification of Security for Untrusted Third Party IP Cores
Verification of  Security for Untrusted Third Party IP CoresVerification of  Security for Untrusted Third Party IP Cores
Verification of Security for Untrusted Third Party IP Cores
 
IoT Programmable Block
IoT Programmable BlockIoT Programmable Block
IoT Programmable Block
 
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoEchelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
 
FBI & Secret Service- Business Email Compromise Workshop
FBI & Secret Service- Business Email Compromise WorkshopFBI & Secret Service- Business Email Compromise Workshop
FBI & Secret Service- Business Email Compromise Workshop
 
IThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOpsIThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOps
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 

Listing program for smart door knocker based on arduino uno r3

  • 1. Listing Program for Smart Door Knocker based on Arduino UNO R3 /* SecretDoor KnockDetectingDoorLock OriginallyfromSteveHoeferhttp://grathio.comVersion0.1.10.20.10 Updatesby Lee Sonko LicensedunderCreativeCommonsAttribution-Noncommercial-Share Alike3.0 http://creativecommons.org/licenses/by-nc-sa/3.0/us/ (Inshort: Do whatyou want,justbe sure to include thisline andthe fourabove it,anddon't sell it or use it inanythingyousell withoutcontactingme.) Modifiedby:DindaEkaPratiwi (RefrigerationandAirConditioningCollager,PolytechnicState of Bandung) (November2015) */ #include <Servo.h> Servomyservo; const intknockSensor=0; const intprogramSwitch= 3; const intlockMotor= 6; const intredLED = 4; const intgreenLED= 5; const intbuzzer= 2; const intthreshold=50; const intrejectValue=25; const intaverageRejectValue=15; const intknockFadeTime =150; const intlockTurnTime =650; const intunlockTime =5000;
  • 2. const intmaximumKnocks=20; const intknockComplete=1200; // Variables. intsecretCode[maximumKnocks] ={50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; intknockReadings[maximumKnocks]; intknockSensorValue =0; intprogramButtonPressed=false; voidsetup() { myservo.attach(lockMotor); pinMode(lockMotor,OUTPUT); pinMode(redLED,OUTPUT); pinMode(greenLED,OUTPUT); pinMode(programSwitch,INPUT); pinMode (buzzer,OUTPUT); Serial.begin(9600); Serial.println("Programstart."); digitalWrite(greenLED,HIGH); } voidloop() { knockSensorValue =analogRead(knockSensor); if (digitalRead(programSwitch) ==HIGH) { programButtonPressed=true; digitalWrite(redLED,HIGH);
  • 3. } else { programButtonPressed=false; digitalWrite(redLED,LOW); } if (knockSensorValue >=threshold) { listenToSecretKnock(); } } voidlistenToSecretKnock() { Serial.println("knockstarting"); inti = 0; for(i = 0; i < maximumKnocks; i++) { knockReadings[i] =0; } intcurrentKnockNumber=0; intstartTime = millis(); intnow= millis(); digitalWrite(greenLED,LOW); if (programButtonPressed==true) { digitalWrite(redLED,LOW); } delay(knockFadeTime); digitalWrite(greenLED,HIGH); if (programButtonPressed==true) {
  • 4. digitalWrite(redLED,HIGH); } do{ knockSensorValue =analogRead(knockSensor); if (knockSensorValue>=threshold) { Serial.println("knock."); now= millis(); knockReadings[currentKnockNumber] =now - startTime; currentKnockNumber++; startTime = now; digitalWrite(greenLED,LOW); if (programButtonPressed==true) { digitalWrite(redLED,LOW); } delay(knockFadeTime); digitalWrite(greenLED,HIGH); if (programButtonPressed==true) { digitalWrite(redLED,HIGH); } } now = millis(); } while ((now - startTime <knockComplete) &&(currentKnockNumber<maximumKnocks)); if (programButtonPressed==false) { if (validateKnock()==true) { triggerDoorUnlock(); } else {
  • 5. Serial.println("Secretknockfailed."); digitalWrite(greenLED,LOW); for (i = 0; i < 4; i++) { digitalWrite(redLED,HIGH); delay(100); digitalWrite(redLED,LOW); delay(100); digitalWrite(2,LOW); delay(1000); digitalWrite(2,HIGH); delay(1000); } digitalWrite(greenLED,HIGH); } } else { validateKnock(); Serial.println("New lockstored."); 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);
  • 6. } } } voidtriggerDoorUnlock(){ Serial.println("Doorunlocked!"); myservo.write(0); delay(lockTurnTime); delay(unlockTime); myservo.write(180); for(inti = 0; i < 5; i++) { digitalWrite(greenLED,LOW); delay(100); digitalWrite(greenLED,HIGH); delay(100); } } booleanvalidateKnock(){ inti = 0; intcurrentKnockCount=0; intsecretKnockCount=0; intmaxKnockInterval =0;
  • 7. for(i = 0; i < maximumKnocks;i++) { if (knockReadings[i] >0) { currentKnockCount++; } if (secretCode[i] >0) { secretKnockCount++; } if (knockReadings[i] >maxKnockInterval){ maxKnockInterval =knockReadings[i]; } } if (programButtonPressed==true) { for (i = 0; i < maximumKnocks;i++) { // normalize the times secretCode[i] =map(knockReadings[i],0,maxKnockInterval,0,100); } // Andflashthe lightsinthe recordedpatterntoletus know it's beenprogrammed. 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); if (secretCode[i]>0) { delay( map(secretCode[i],0,100, 0, maxKnockInterval)); digitalWrite(greenLED,HIGH);
  • 8. digitalWrite(redLED,HIGH); } delay(50); } returnfalse; } if (currentKnockCount!=secretKnockCount) { returnfalse; } inttotaltimeDifferences=0; inttimeDiff =0; for(i = 0; i < maximumKnocks;i++) { // Normalize the times knockReadings[i] =map(knockReadings[i],0,maxKnockInterval,0,100); timeDiff =abs(knockReadings[i] - secretCode[i]); if (timeDiff >rejectValue){ //Individual value toofaroutof whack returnfalse; } totaltimeDifferences+=timeDiff; } if (totaltimeDifferences/secretKnockCount>averageRejectValue) { returnfalse; } returntrue; }