Un ├ęchange d'information autour de la carte KeyDuino
 
HomeHome  FAQFAQ  RegisterRegister  Log inLog in  

Share | 
 

 NFC lock GIFT box

View previous topic View next topic Go down 
AuthorMessage
MrStein
KeyDuino TEAM
avatar

Messages : 59
Reputation : 3
Date d'inscription : 2015-10-10
Age : 23
Localisation : Lille, FRANCE

PostSubject: NFC lock GIFT box    Sat 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
http://keyduino.forumsactifs.com
 
NFC lock GIFT box
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Line Lock Info needed
» Trunk lock relocation / Shaved trunk lid
» Blue coat Lock up
» (2) oem impala SS trunk lock emblems
» RCA Duel Phono w/amradio a gift

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