KeyDuino forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.


Un échange d'information autour de la carte KeyDuino
 
HomeHome  Latest imagesLatest images  RegisterRegister  Log inLog in  

 

 NFC lock GIFT box

Go down 
AuthorMessage
MrStein
KeyDuino TEAM
MrStein


Messages : 85
Reputation : 4
Date d'inscription : 2015-10-10
Age : 30
Localisation : Lille, FRANCE

NFC lock GIFT box  Empty
PostSubject: NFC lock GIFT box    NFC lock GIFT box  EmptySat 10 Oct - 16:49


This project is inspired by the NFC box here

Code:

/*
 The goal of this sketch is to unlock a "giftbox" with KeyDuino and a NFC tag, via a servomotor.
 Get the ID of your tag, put it in NFC_KEY below.
 When you scan the right tag with KeyDuino, the servo will unlock the box.
 More information in the video of the project: https://www.youtube.com/watch?v=cIedvE9mYfM
 Author: Mr Stein
 Revised by Raymond Borenstein - CITC-EuraRFID
 Compatible with KeyDuino 5.1
 Join http://keyduino.forumsactifs.com/ to ask your questions, suggest your ideas, and show your projects!
 */

#include <Servo.h> //Servo library is included by default, you should not need to install anything
#include <KeyDuino.h>

#define LED_PIN    13
#define SERVO_PIN  12

KeyDuino keyDuino;

uint8_t uid[] = {
  0, 0, 0, 0, 0, 0, 0 };
uint8_t uidLength;

Servo myServo;  // create servo object to control the servo

String NFC_KEY_1 = "xxxxxxxxxxxx";
String NFC_KEY_2 = "xxxxxxxxxxxx";

//Function to open the servo
void openServo() {
  myServo.write(180);
  delay(8000);
  myServo.write(0);
}

void setup(void) {
  Serial.begin(115200);
  keyDuino.begin();
  myServo.attach(SERVO_PIN);
  myServo.write(0);
  Serial.println("KeyDuino BOX is ready, please scan a NFC tag");
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
}

void loop(void) {
  uint8_t success;
  String readID;
  success = keyDuino.readTargetID(uid, &uidLength);
  if (success){
    readID = keyDuino.convertUintToString(uid, uidLength);

    if (readID == NFC_KEY_1 || readID == NFC_KEY_2){
      openServo();
      digitalWrite(LED_PIN, LOW);
      delay(500);
      digitalWrite(LED_PIN, HIGH);
    }
    else {
      keyDuino.buzz(20);
      keyDuino.buzz(20);
    }
  }
  delay(1);
}
Back to top Go down
https://keyduino.forumsactifs.com
 
NFC lock GIFT box
Back to top 
Page 1 of 1
 Similar topics
-
» NFC drawer lock
» Entry door electronic lock

Permissions in this forum:You cannot reply to topics in this forum
KeyDuino forum :: KeyDuino projects & tutorial :: Tutorials :: Official tutorial-
Jump to: