vehicle detection

Dependencies:   mbed HCSR04 DHT

main.cpp

Committer:
spriyanka
Date:
2019-03-28
Revision:
3:d520a6ecf90c
Parent:
2:74cfa9f8251d

File content as of revision 3:d520a6ecf90c:

#include "mbed.h"
#include "HCSR04.h"

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);
   // Uart.baud(115200);
    wait_ms(4000);
    dt.start();
    while(1){
    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);
                }*/
                
                  
              }
         }