vehicle detection

Dependencies:   mbed HCSR04 DHT

Committer:
spriyanka
Date:
Thu Mar 28 19:08:27 2019 +0000
Revision:
3:d520a6ecf90c
Parent:
2:74cfa9f8251d
vehicle detection

Who changed what in which revision?

UserRevisionLine numberNew contents of line
khp007 0:a804a58b647b 1 #include "mbed.h"
khp007 0:a804a58b647b 2 #include "HCSR04.h"
khp007 0:a804a58b647b 3
spriyanka 3:d520a6ecf90c 4 Serial pc(USBTX,USBRX);
spriyanka 3:d520a6ecf90c 5 Serial device(PTC17,PTC16);
spriyanka 3:d520a6ecf90c 6 HCSR04 sensor(D5, D7);
khp007 0:a804a58b647b 7 DigitalOut Green(LED2);
spriyanka 3:d520a6ecf90c 8 Timer dt;
khp007 0:a804a58b647b 9 int main()
spriyanka 3:d520a6ecf90c 10 { int d;
saranyachitta 2:74cfa9f8251d 11 pc.baud(115200);
spriyanka 3:d520a6ecf90c 12 device.baud(115200);
spriyanka 3:d520a6ecf90c 13 // Uart.baud(115200);
spriyanka 3:d520a6ecf90c 14 wait_ms(4000);
spriyanka 3:d520a6ecf90c 15 dt.start();
khp007 0:a804a58b647b 16 while(1){
saranyachitta 2:74cfa9f8251d 17 wait_ms(1000);
spriyanka 3:d520a6ecf90c 18
spriyanka 3:d520a6ecf90c 19 d = sensor.distance(1);
spriyanka 3:d520a6ecf90c 20 pc.printf("Distance:%d \r\n",d);
spriyanka 3:d520a6ecf90c 21 dt.reset();
spriyanka 3:d520a6ecf90c 22 /*if(d > 1 and d < 50)
spriyanka 3:d520a6ecf90c 23 {
spriyanka 3:d520a6ecf90c 24 pc.printf("case2\r\n");
spriyanka 3:d520a6ecf90c 25 device.printf("2");
spriyanka 3:d520a6ecf90c 26 // Uart.putc(2);
spriyanka 3:d520a6ecf90c 27 }*/
spriyanka 3:d520a6ecf90c 28 if(d>0 and d<100)
spriyanka 3:d520a6ecf90c 29 {
spriyanka 3:d520a6ecf90c 30 pc.printf("case1\r\n");
spriyanka 3:d520a6ecf90c 31 device.printf("1");
spriyanka 3:d520a6ecf90c 32 // Uart.putc(3);
spriyanka 3:d520a6ecf90c 33 }
spriyanka 3:d520a6ecf90c 34 else if(d>100 and d<200)
spriyanka 3:d520a6ecf90c 35 {
spriyanka 3:d520a6ecf90c 36 pc.printf("case2\r\n");
spriyanka 3:d520a6ecf90c 37 device.printf("2");
spriyanka 3:d520a6ecf90c 38 // Uart.putc(4);
spriyanka 3:d520a6ecf90c 39 }
spriyanka 3:d520a6ecf90c 40 else
spriyanka 3:d520a6ecf90c 41 {
spriyanka 3:d520a6ecf90c 42 pc.printf("case3\r\n");
spriyanka 3:d520a6ecf90c 43 device.printf("3");
spriyanka 3:d520a6ecf90c 44 // Uart.putc(5);
spriyanka 3:d520a6ecf90c 45 }
spriyanka 3:d520a6ecf90c 46 /*else if(d>300 and d<400)
spriyanka 3:d520a6ecf90c 47 {
spriyanka 3:d520a6ecf90c 48 pc.printf("case6\r\n");
spriyanka 3:d520a6ecf90c 49 device.printf("6");
spriyanka 3:d520a6ecf90c 50 // Uart.putc(6);
spriyanka 3:d520a6ecf90c 51 }
spriyanka 3:d520a6ecf90c 52 else if(d>400 and d<500)
spriyanka 3:d520a6ecf90c 53 {
spriyanka 3:d520a6ecf90c 54 pc.printf("case7\r\n");
spriyanka 3:d520a6ecf90c 55 device.printf("7");
spriyanka 3:d520a6ecf90c 56 // Uart.putc(7);
spriyanka 3:d520a6ecf90c 57 }
spriyanka 3:d520a6ecf90c 58 else
spriyanka 3:d520a6ecf90c 59 {
spriyanka 3:d520a6ecf90c 60 pc.printf("case0\r\n");
spriyanka 3:d520a6ecf90c 61 device.printf("0");
spriyanka 3:d520a6ecf90c 62 // Uart.putc(0);
spriyanka 3:d520a6ecf90c 63 }*/
spriyanka 3:d520a6ecf90c 64
spriyanka 3:d520a6ecf90c 65
spriyanka 3:d520a6ecf90c 66 }
spriyanka 3:d520a6ecf90c 67 }