sensing hand swipe direction

Hi guys, I need help regarding a project to sense hand swipe direction. The code I have currently is to record the time whereby the sensor switches off. Any idea to modify the code to record the time whereby the sensor switches on? Appreciate your feedbacks thanks!
#define sIRA 10
#define sIRB 8
#define sIRC 9

#define LED1 3
#define LED2 4
#define LED3 5
char orders[3] = {'0','0','0'};
int indexOrder = 0;
//speed of detection Ms
int Captspeed = 1;

long tA;
long tB;
long tC;

void setup() {
Serial.begin (9600);
for(int i = 8;i<=10;i++)
pinMode(i, INPUT);
for(int i = 3;i<=5;i++)
pinMode(i, OUTPUT);
}
void loop() {
//Reset Command after 800 Msecond
if(millis()%1000 > 800)
ResetCommand();
//If we have 3 signals , Calculate Command
if(tA > 0 && tB> 0 && tC>0)
{
int command = CalculateCommand();
if(command <=0)
DoCommand(command);
}
//check for sensors
if(indexOrder > 2)
indexOrder = 0;

int vA = digitalRead(sIRA);
if(tA == 0 && vA == 0) tA = millis();

int vB = digitalRead(sIRB);
if(tB == 0 && vB == 0) tB = millis();

int vC = digitalRead(sIRC);
if(tC==0 && vC == 0) tC = millis();
//Stop Command
if(vA == 0 && vB == 0 && vC == 0 )
{
// DoCommand(0);
}
delay(Captspeed);
}
int CalculateCommand(void)
{
Serial.print("tA = ");
Serial.println(tA);
Serial.print("tB = ");
Serial.println(tB);
Serial.print("tC = ");
Serial.println(tC);
delay(1);

if((tA <= tB) && tA <= tC)
return -3 ;// FORWRD
if((tB <= tC) && tB <= tA)
return -2 ;// LEFT
if((tC <= tB) && tC <= tA)
return -1 ;//RIGHT
//Etc
return 1;

}

void DoCommand(int command)
{
switch (command)
{
case 0: Serial.println("Stopped");delay(500);break;
case -1: Serial.println("Turn RIGHT ");digitalWrite(LED1,HIGH); delay(1000);break;
case -2: Serial.println("Turn LEFT ");digitalWrite(LED2,HIGH); delay(1000);break;
case -3: Serial.println("GO FORWARD ");digitalWrite(LED3,HIGH); delay(1000);break;
case -4: Serial.println(" GO BACK "); delay(1000);break;
default : Serial.println("NO Command detected");break;
}
ResetCommand();
}
void ResetCommand()
{
for(int i = 3;i<=5;i++)
{
digitalWrite(i,LOW);//ALL LEDs
}
tA = 0;//Reset time A
tB = 0;//Reset time B
tC = 0;//Reset time C
}

Why do you use the values in tA, tB, and tC and THEN assign values to them? Putting the cart on the right end of the horse is usually better.

Hi, how are you going to detect hand swipe direction with one sensor, you can detect left then right then left.
What about left, left left left, right.
Two sensors would be needed, the sweep of the hand activates both sensors but one after the other.
sensor1 then sensor2 activated is a swipe in one direction.
sensor2 then sensor1 activated is a swipe in the other direction.

Tom..... :slight_smile:

thanks for replying. To reset the time back to 0? if not what do you suggest i should do. Any idea to record the time when the sensor is first activated?

Hi I am currently using three sensors. I get your point but any idea how to modify the code to record the time when the sensor is first activated?

Hi, a diagram of how you have your sensor mounted would be worth a thousand words.
Tom..... :slight_smile:

My project is in school ): the 3 sensors are lined up horizontally with a distance of about 5cm away from each other. So if I were to swipe my hand from left to right, the left sensor will be first to be activated, followed by the middle and then the right, and I want to set the code to record the timing that the sensors are first activated. Any idea how to modify the code?

@noobcake91, do not cross-post. Other thread removed.

Hi, simple you don't need to time.
if sensor on left is first then it must be a sweep to the right.
if sensor on the right is first then it must be a sweep to the left.

Tom........ :slight_smile: