RFID to let current flow

First of all I apologize for my poor english.
I saw that they only have t.update(); in void loop as in the example at Arduino Playground - Timer Library
I have project where I need to let current through for 1 hour after it detect a smartcard
and to make a countdown until the current is stop after one hour
the method is just like when u scan card to unlock a door
it seems that the countdown didn't works at all

please help me...i need to send this project by this week :sob: :sob: :sob:

unlock2.ino (3.52 KB)

I've never included a library using quotes before, as in "Timer.h".
Is this valid? I ask because I'll bet the Timer lib is where the t.update function lives. I don't have the other MFRC522 lib to check it.

#include "Timer.h"

Timer t;
int pin = 13;

void setup()
{
pinMode(pin, OUTPUT);
t.pulse(pin, 10 * 60 * 1000, HIGH); // 10 minutes
}

void loop()
{
t.update();
}

above is an example from the timer.h in arduino libraries...yes it is valid n i've check b4 with my arduino...but it didn't work in my programming

Right but normally its #include <Timer.h>

Not saying the enclosed quote version can't work, I've just never used it that way or noticed it in any other sketch that way. And the fact that the library folder itself has a typo in it....

So I just downloaded that lib. The quotes do work but then so do the <>. Why buck tradition when you're having a problem: go with the<>
The update() works fine here.

So back to the original problem.
First you don't need the Timer library. The arduino can count up to an hour (and beyond) using the built in millis() function. Once the card triggers an input pin, you sample the current "time" and then everytime through the loop you check it again and subtract the original sample). An hour is 3600000 ms.

While the subtraction = than an hour of milliseconds you can set a pin to high to trigger a relay or transistor or mosfet and let the current flow - remember if you do it directly with the arduino pin, the pin can only deliver 40ma of power (for an Uno for example), that's why you normally need some other circuitry to run stuff in the real world.

Once that subtraction equals an hour of milliseconds, you can set your output pin to low, cutting the current off. You should add a dropping resistor on this pin so that when you tell it to go low, it's guaranteed.

If the system detects another card before the hour is up, you can reset the "clock" by sampling the current time again and the current will flow for another hour from that point on.

The problem with the TIMER lib and using the code you have is that every hour it will turn on and off regardless of user input. In fact if you look into the libraries, what we're doing above is all the Timer library is doing with it's "now" command, each time the update() fires. There are more commands in there you could use to do this but I think the above approach is easier.

Keep in mind that to hold a large number like 3,600,000 you have to use a "long" variable and not just an "int" (and with that Timer lib the variable that holds the period may not be big enough for the numbers you need - even 10 minutes in ms is bigger than an int can hold- you could change that but the millis() command seems to be all you need.)

So:
wait for card input and do nothing else
On card input Set pin high and sample time
check time again repeatedly
does difference = 3,600000?
yes -> set pin low, set time holder variables to 0, wait for card input again
No -> go back and sample time again

thank u so much for your reply..I'm adjusting it right now...

it seems like after i detect a card it only shows 60 minutes left and the time didn't decrease after that...the current also didn't stop after 1 hour...I think there is something wrong with my calculation or after the lock was open the program didn't proceed to calc();

unlock2.ino (3.8 KB)

I think it's because you are calculating the difference in time up in the declaration area. That only happens once, when the program first begins to run.
The calculation "interval = (currentMillis - startMillis) ;" should be happening each time through the main loop once the door open has been triggered. (it could also happen in one of the other functions as long as that function is fired at least once for sure each time through the main loop.

The same goes for the minutes calculation.

That declaration area is to define the kind of variables you are going to be using globally and can also set the initial value of those variables. It doesn't do any good to do a calculation up there because at the time of the "interval" calculation, both currentMillis and startMillis are equal to zero because they were just defined in the previous two lines and had no set value.

You can define a variable anywhere in the code you like, but just remember you may limit what functions can see that variable e.g a variable defined inside a For loop can only be seen inside that For loop.
But variables defined at the beginning can be seen by all functions (with a few exceptions)