vehicle detection

Dependencies:   mbed HCSR04 DHT

Files at this revision

API Documentation at this revision

Comitter:
spriyanka
Date:
Thu Mar 28 19:08:27 2019 +0000
Parent:
2:74cfa9f8251d
Commit message:
vehicle detection

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 74cfa9f8251d -r d520a6ecf90c main.cpp
--- a/main.cpp	Thu Mar 29 18:40:24 2018 +0000
+++ b/main.cpp	Thu Mar 28 19:08:27 2019 +0000
@@ -1,47 +1,67 @@
 #include "mbed.h"
 #include "HCSR04.h"
 
- Serial pc(USBTX,USBRX);
- Serial device(PTC17,NC);     // Create a serial connection to pc through the mbed USB cable
-
- void dist(int distance)
-{
-    //put code here to execute when the distance has changed
-    printf("Distance %d mm\r\n", distance);
-}
-
-HCSR04 sensor(D8,D9);
+Serial pc(USBTX,USBRX);
+Serial device(PTC17,PTC16);
+HCSR04 sensor(D5, D7);
 DigitalOut Green(LED2);
-
+Timer dt;
 int main()
-{
+{   int d;
     pc.baud(115200);
-device.baud(115200);
-   wait_ms(4000);
-
-int echoVal = sensor.echo_duration();
-   Green = 1;
-   
+    device.baud(115200);
+   // Uart.baud(115200);
+    wait_ms(4000);
+    dt.start();
     while(1){
-    int a = sensor.echo_duration();
-    if (a - echoVal > 75 || echoVal - a > 75){
-        Green=0;
-        wait(.2);
-        Green=1;
-        wait(.2);
-    }
-        if(a > 1 and a <= 170)
-         {
-         device.printf("1"); 
-         pc.printf("Object Detected: Value = 0 \r\n");
-         wait(0.5);
-    }
-    else
-       {
-             device.printf("0");
-               pc.printf("No object detected: Value = 1 \r\n");  
-               wait(0.5);
-       }
     wait_ms(1000);
-   }
-   } 
+                
+                d = sensor.distance(1);
+                pc.printf("Distance:%d \r\n",d);
+                dt.reset();
+                /*if(d > 1 and d < 50)
+                {
+                    pc.printf("case2\r\n");
+                    device.printf("2");
+ //                   Uart.putc(2);
+                    }*/
+                if(d>0 and d<100)
+                {
+                    pc.printf("case1\r\n");
+                    device.printf("1");
+     //               Uart.putc(3);
+                    }
+                else if(d>100 and d<200)
+                {
+                    pc.printf("case2\r\n");
+                    device.printf("2");
+            //        Uart.putc(4);
+                }
+                else 
+                {
+                    pc.printf("case3\r\n");
+                    device.printf("3");
+    //                Uart.putc(5);
+                }
+                /*else if(d>300 and d<400)
+                {
+                    pc.printf("case6\r\n");
+                    device.printf("6");
+            //        Uart.putc(6);
+                }
+                else if(d>400 and d<500)
+                {
+                    pc.printf("case7\r\n");
+                    device.printf("7");
+             //       Uart.putc(7);
+                }
+                else
+                {
+                    pc.printf("case0\r\n");
+                    device.printf("0");
+       //             Uart.putc(0);
+                }*/
+                
+                  
+              }
+         }