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

Share | 
 

 Holding tag for specific time to trigger another relay

Go down 
AuthorMessage
thisone08
Newbie
Newbie


Messages : 2
Reputation : 0
Date d'inscription : 2018-03-03

PostSubject: Holding tag for specific time to trigger another relay   Wed 21 Mar - 18:53

I am fairly new to coding and arduino. I am using keyduino with relay shield and an nfc ring to lock and unlock car door. I am using all 4 relays for project but can not figure out how to modify one of the relays on relay sketch to trigger when a tag is held for a specified amount of time. I have set up one tag for lock and one tag for unlock but I also have 2 solenoids that pull on door handles. My sketch is set up as if unlock tag is present trigger relay 1 wait one second trigger relay 2, if lock tag is present trigger relay 4. My question is , is it possible to time how long unlock tag is present and if it is present for 3 seconds to trigger relay 3? Id be happy to email my modified relay sketch if it helps in any way. Thank you in advance, Edward
Back to top Go down
MrStein
KeyDuino TEAM
avatar

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

PostSubject: Re: Holding tag for specific time to trigger another relay   Thu 22 Mar - 13:49

Hi Thisone,
You can use this function to get an estimation of time :

Code:

int detectTagTime() {
int timeDuration = 0;
  while (keyDuino.readTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength)) timeDuration ++;
  return (timeDuration);
}

here is an exemple of use:
Code:
/*
  This sketch is made to be used with any ISO14443-A tag (like Mifare), to read its ID.

  Author: Raymond Borenstein - CITC-EuraRFID

  Compatible with KeyDuino NORMAL / KeyDuino NANO

  Join http://keyduino.forumsactifs.com/ to ask your questions, suggest your ideas, and show your projects!
*/

#include "KeyDuino.h"

KeyDuino keyDuino;

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

void setup(void) {
  Serial.begin(115200);
  keyDuino.begin();
  Serial.println("KeyDuino is ready, please scan a tag.");
}


int detectTagTime() {
  int timeDuration = 0;
  while (keyDuino.readTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength)) {
    timeDuration ++;
    Serial.println(timeDuration);
 
  
  }
  return (timeDuration);
}

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


  if (success) {
    readID = keyDuino.convertUintToString(uid, uidLength);
    Serial.print("Tag found: ");
    Serial.println(readID);
    int timeDuration = detectTagTime();
    Serial.print("Time ");
    Serial.println(timeDuration);

    if (timeDuration < 100) {
      Serial.println("do something 1");
    }
    else if (timeDuration < 200) {
      Serial.println("do something 2");
    }
    else if (timeDuration < 300) {
      Serial.println("do something 3");
    }
    else if (timeDuration < 400) {
      Serial.println("do something 4");
    }
  }
  delay(1);
}

! this function does not return a value in second. but if you want you can use the millis function to return a accurate value of detection.

Tell me if you have any trouble / questions.

Bye,
Pierre
Back to top Go down
http://keyduino.forumsactifs.com
thisone08
Newbie
Newbie


Messages : 2
Reputation : 0
Date d'inscription : 2018-03-03

PostSubject: Re: Holding tag for specific time to trigger another relay   Fri 23 Mar - 4:23

Thank you MrStein for the speedy response. I will tie this into my sketch when time permits and report back with any problems. Edward
Back to top Go down
Sponsored content




PostSubject: Re: Holding tag for specific time to trigger another relay   

Back to top Go down
 
Holding tag for specific time to trigger another relay
Back to top 
Page 1 of 1
 Similar topics
-
» Image of priest's hands holding host or chalice?
» Time Out by CL
» Watching "Genesis of the Daleks" for the first time.
» jml cooking time
» 5 Bites At A Time

Permissions in this forum:You cannot reply to topics in this forum
KeyDuino forum :: KeyDuino informations & questions :: SOFTWARE questions & informations-
Jump to: