How to create a timer that

Hi am am asking for a little bit of help from you pros out there. I am trying to construct a shake/tilt device that will activate a relay for a certain amount of time… The aim is to construct a relay that will allow power to a hidden GPS tracker when in movement. When the container is stopped the shake switch will go off after 10 minutes. This will save valuable battery. When container moves again the switch will activate the power again. The new locations G values X,Y,Z will become the new setpoint for detecting movment.

My project consist of a
UNO
4*20 row LCD (serial)
Tripple axis Acc from sparkfun (MMA7361)
and a relay.

I need help to figure out how to activate the relay thats stays ON for a certain amount of time in the loop. Right now I am using a LED instead of a relay. One thing I could do is to drive the relay with a 555 timer, but I think it could be solved with the UNO instead.

Here is the code done

// GPS Switch delay skak/tilt/gravitations sensor
// Rev. 1.0
// Test 20101029 /JAS

#include <NewSoftSerial.h>
#include <AverageList.h>

NewSoftSerial mySerial(0, 1);

const byte MAX_NUMBER_OF_READINGS = 25;
float storagex[MAX_NUMBER_OF_READINGS] = {0};
float storagey[MAX_NUMBER_OF_READINGS] = {0};
float storagez[MAX_NUMBER_OF_READINGS] = {0};

AverageList listx = AverageList( storagex, MAX_NUMBER_OF_READINGS );
AverageList listy = AverageList( storagey, MAX_NUMBER_OF_READINGS );
AverageList listz = AverageList( storagez, MAX_NUMBER_OF_READINGS );

int XPin = 3; // X
int YPin = 2; // Y
int ZPin = 1; // Z
int Xangle;
int i;

int output = 2; //digital pin 2 is connected to the transistor base
int threshold = 310; // nominal threshold
int hyst = 10; // on when input above threshold + hyst, off when below threshold - hyst
int samplingDelay = 15000; // higher values for slow changing signals, lower values for faster response
int v;

void setup()
{
mySerial.begin(9600);
pinMode(output, OUTPUT); //initializes pin 2 as an output
// Initierings värde för att aktivera reläet.
threshold = v;
selectLineFour();
mySerial.print("New trigger ");
mySerial.print(threshold);

}

void loop() {
// clearLCD();
backlightOn();
//Print text on each line
selectLineOne();
delay(100);
mySerial.print(“GPSLOGIK AB 2010”);

listx.addValue(int(analogRead(XPin)));
listy.addValue(int(analogRead(YPin)));
listz.addValue(int(analogRead(ZPin)));

selectLineTwo();
mySerial.print("X= “);
mySerial.print(int(listx.getAverage()));
mySerial.print(” Y= “);
mySerial.print(int(listy.getAverage()));
mySerial.print(” Z= ");
mySerial.print(int(listz.getAverage()));

//###################################################
//# Reläet’s hysteres omkoppling kring accelerometerns medelvärde
// read the value
v = int(analogRead(XPin));

// if it’s higher than the on-threshold
if (v > (threshold + hyst)) {
// turn the output high
digitalWrite(output, HIGH);
selectLineFour();
mySerial.print("-");
selectLineThree();
mySerial.print(“Relay=Activated”);
}
// if is’t lower than the off-threshold
else if (v < (threshold - hyst)) {
// turn the output low

digitalWrite(output, HIGH);
selectLineFour();
mySerial.print("-");
selectLineThree();
mySerial.print(“Relay=Activated”);
}
else
{
// turn the output low
selectLineThree();
mySerial.print(“Relay=Off”);
digitalWrite(output, LOW);

}
// Tilldela en timer för frånslagsfördröning

// wait before taking another sample

threshold = v;
selectLineFour();
mySerial.print("New trigger ");
mySerial.print(v);

delay(200);

}

//SerialLCD Functions

void OnceOnly(){
}

void selectLineOne(){ //puts the cursor at line 0 char 0.
mySerial.print(0xFE, BYTE); //command flag
mySerial.print(128, BYTE); //position
}
void selectLineTwo(){ //puts the cursor at line 2 char 0.
mySerial.print(0xFE, BYTE); //command flag
mySerial.print(192, BYTE); //position
}
void selectLineThree(){ //puts the cursor at line 3 char 0.
mySerial.print(0xFE, BYTE); //command flag
mySerial.print(148, BYTE); //position
}
void selectLineFour(){ //puts the cursor at line 4 char 0.
mySerial.print(0xFE, BYTE); //command flag
mySerial.print(212, BYTE); //position
}
void clearLCD(){
mySerial.print(0xFE, BYTE); //command flag
mySerial.print(0x01, BYTE); //clear command.
}
void backlightOn(){ //turns on the backlight
mySerial.print(0x7C, BYTE); //command flag for backlight stuff
mySerial.print(157, BYTE); //light level.
}
void backlightOff(){ //turns off the backlight
mySerial.print(0x7C, BYTE); //command flag for backlight stuff
mySerial.print(128, BYTE); //light level for off.
}
void backlight50(){ //sets the backlight at 50% brightness
mySerial.print(0x7C, BYTE); //command flag for backlight stuff
mySerial.print(143, BYTE); //light level for off.
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
mySerial.print(0xFE, BYTE);
}

Have look at the blink without delay example. Get back to us if you have any questions