Arduino Simple Hand Motion V1

Arduino simple hand motion.
Detect hand motion direction and speed.
Can be used to control any device... I let you the magic  imagination 

You will need:
-1 *Arduino (Uno)
-3 or 5 or ... IR switch ( I used E18D80NK)  ( 6€ )
-wires.
-3* 1k resistors
- 3* LEDs. 

The code :
---------------------------------------
#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
}

Share

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest

    7 Discussions

    0
    None
    arishy

    2 months ago

    While waiting for the parts....I thought I try to understand the code above.
    To emulate the code hardware, I had some TOUCH sensors I thought it can help me out to understand the code.

    The results were very flaky and the timing was also bad.

    Let me expand. emulating the inputs I touched the three sensors according to the shape of the triangle Some time I succeed and most of the time not.

    The author of the code did a lot of messaging of the time delays etc to ensure proper capturing. It did not work either in my case Most of the time the input is IGNORED.

    Someone mention to me that sensor type does not matter in pursuit of motion direction, so why I am facing these odd behaviour.

    0
    None
    ChetanP10

    2 years ago

    Simple and elegant project. Good work.

    Can you just add a new picture showing detailed layout and electriical connections. Thanks.

    0
    None
    Andym84

    4 years ago

    I'm sure it's just a Rookie/Amateur mistake on my part :S

    0
    None
    Andym84

    4 years ago

    Pic

    2013 16:46.jpg
    0
    None
    Andym84

    4 years ago

    Hey affiaymen,
    amazing instructable, just what I've searched for all over the net and your/this instructable is very practical. I haven't had much experience with arduino and have relatively basic experience in electronics and have hit a wall trying to get this set up to work, maybe you can see what/where my problem lies? On the IR sensors (same ones as you used) I understand pinout as follows:- RED/Power, BLACK/Gnd, YELLOW/Signal. I've all 3 x REDS tinned together and soldered onto 1 x male header pin (1K resistor in line on each of 3 wires). I've all 3 x BLACKS tinned together and soldered onto 1 x male header pin. I have each YELLOW tinned separately and soldered on to separate male pin each of their own. LED's have all BLACKS tinned together and soldered onto 1 x male header pin, each RED wire from LED's are tinned separately and soldered onto separate male header pin off their own. I'm not entirely sure where to locate my GND's from IR LED's and regular LED's and also where to put RED/pwr from IR LED's on Arduino UNO. See photo for better understanding, thank you very much if you are able to have the time to read this and have a look :)

    0
    None
    affiaymen

    5 years ago

    Hi Saterk,
    Im actually I'm using it now for commanding my tv.. So no need to change channel and volume with remote ...:)
    In your case you can attach it to a servo and play with frequency ..so you can ovoid obstacle .
    I'm trying always to make quit simple construct with minimum of components.
    I will notify you for my next video , how to hack a simple IR switch (6€) and use it as distance range sensor (30€) with almost nada!! ;)

    When reading the title I was expecting something with an accelerometer, but this is elegant and simple, and embedded in some kind if "artefact" or magical device this could be really cool.

    I wonder... One of my many ideas (on ice) was a hammer that would light up when it hit something (or, for the sake of not destroying things, when it came close). I was thinking of using an accelerometer for that, but maybe I could use your approach...

    Thanks for sharing!