Project showcase
Motion Direction Detector

Motion Direction Detector © GPL3+

FSM that allows to identify the direction of the object.

  • 1,206 views
  • 0 comments
  • 4 respects

Components and supplies

About this project

The Project consists in the creation of a simple and flexible programming structure that allows the adaptation to several solutions. Although this project specifies a particular application case, it is a simple and cost-effective programming solution that can give rise to several applications covering the commercial, security and industry areas.

As an example of practical application of the project I present one of the possible implementation solutions, which is the detection of sequence on High

way and which still has the following functionality:

  • Detection of the correct direction;
  • Counting vehicles in the right direction;
  • Detection of vehicles in the wrong direction;
  • Immediate generation Alarm of car in the wrong direction ;

Sequence - correct direction

Sensor 1 detects the vehicle. This detection activates a timer and activates sensor 2. If the sensor is activated ahead of time the sequence is considered correct and counts the number of cars passing in the correct direction.

Sequence - incorrect direction

Since sensor 2 only activates after sensor 1 detects an object, the car in the wrong sequence will only be detected by sensor1 for the first time. As sensor 2 will not be activated in the stipulated time after this time, an alarm will be generated.

Entity and Architecture

FSM - The objective of this work was to build a very versatile finite states machine that can "perceive" the direction of the object and generate alarms or orders.

Other possibilities of application of the finite state machine

Security - We can adapt the state machine to generate an alarm when the sequence is detected in the fall of children to a pool.

Control - We can adapt the machine of states and count the number of people that enter and leave a store, as well as the number of people inside.

Domotica - we can see the meaning of a person moving in a corridor and lighting only the necessary lighting. We can also control the direction of the car by opening gates or lighting house lights, etc... It is a machine of states that with small adaptations will be very functional in an intelligent building management system.

Code

Object Direction DetectorC/C++
FSM that detect the direction of the object with the ability to generate alarms or orders. In this particular case of application by way of example, we have chosen a detector of direction of cars in a Highway, and we increased the possibility of counting the cars in the right direction and generating alarms for the cars in the wrong direction
#define trigPin1 2
#define echoPin1 3
#define trigPin2 4
#define echoPin2 5


int Led3=10;
int Led1=11;
int Led2=12;
int sensor1=0;
int sensor2=0;
float duration1,distance1, distance2, duration2;
volatile int FSM1_estado=0;
int contagem=0;
unsigned long tempo =0;
unsigned long r,s,x;



void setup() {
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(Led1, OUTPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
}


void loop() {

  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin1, LOW);

  duration1=pulseIn (echoPin1, HIGH); //tini=micros();
  distance1= (duration1/2)*0.0345;

   digitalWrite(Led1, LOW);
   digitalWrite(Led2, LOW);
   digitalWrite(Led3, LOW);
   if(distance1 >=5 && distance1 <=15){
    sensor1=1;
  
     if (sensor1==1){
        
      FSM1();
      }
   }
   else{sensor1=0;}
  
}




void FSM1(){
int contador;
int s=1000;


switch(FSM1_estado){

 case 0:
   digitalWrite(Led1, LOW);
   digitalWrite(Led2, LOW);
   digitalWrite(Led3, LOW);
  
   FSM1_estado=1;
   break;
 
  
  
  
  case 1:
   r=millis();
   digitalWrite(Led1, HIGH);
   digitalWrite(Led2, LOW);
   digitalWrite(Led3, LOW);
   FSM1_estado=2;
  break;


 case 2:
      
       delay(60);
       digitalWrite(trigPin2, HIGH);
       delayMicroseconds(500);
       digitalWrite(trigPin2, LOW);
       duration2=pulseIn (echoPin2, HIGH);
       distance2= (duration2/2)*0.0344;
        x=millis ()-r;
        
         if ((distance2>=5 && distance2 <15)&&(x<s)){      
                   
            FSM1_estado=3; 
       }       
            else{FSM1_estado=4;}     
   break;


 case 3:
   digitalWrite(Led1, HIGH);
   digitalWrite(Led2, HIGH);
   digitalWrite(Led3, LOW);    
  Serial.println();
  Serial.print("-------------------------------------------");
  Serial.println();
  Serial.print("-----------SEQUENCIA CORRETA-------------- ");
  Serial.println();
  Serial.print("-------------------------------------------");
  Serial.println();
  contagem++;
  Serial.println(contagem);
   FSM1_estado=0;
  break;


 case 4:
  digitalWrite(Led1, LOW);
  digitalWrite(Led2, LOW);
  digitalWrite(Led3, HIGH);    
  Serial.println();
  Serial.print("-------------------------------------------");
  Serial.println();
  Serial.print("-----------INCORRETA ALRME -------------- ");
  Serial.println();
  Serial.print("-------------------------------------------");
  Serial.println();
  delay (200);
   FSM1_estado=0;
  break;
 


}

}




  

Schematics

Schematic
Esquematico page 001 fggb3myjfw

Comments

Similar projects you might like

Motion Detector Clock

Project in progress by Frazer Reid

  • 1,893 views
  • 0 comments
  • 3 respects

Arduino EMF Detector A.K.A Ghost Detector

Project showcase by Patel Darshil

  • 5,761 views
  • 8 comments
  • 15 respects

Android Motion Detector Camera with Arduino/MCU

Project tutorial by Walid Mafuj

  • 7,911 views
  • 10 comments
  • 25 respects

Arduino Burglar

Project showcase by paolo_cravero

  • 2,377 views
  • 2 comments
  • 6 respects

Motion Sensing Alarm With Keypad & Password

Project showcase by thehack904

  • 8,798 views
  • 27 comments
  • 33 respects

BLE Motion Detector - ARTIK Cloud

Project tutorial by Elijah Scheele

  • 2,178 views
  • 0 comments
  • 4 respects
Add projectSign up / Login