Programming: views : 1570

Highway vehicle speed detector or checker Embedded C language code in MikroC AVR Framework also applicable for 8051 Microcontroller

This code is tested on AVR ATmega8 microcontroller with buzzer, 16x2 LCD and IR proximity sensors. In this code, time taken is measured for a vehicle to cross fix distance. And from obtained time and distance, speed is culcutated. Buzzer is used to sound when time measurement is starts and then at the time of crossing the second point where time measurement is ended.


Embedded C language code in mikroc AVR

Note : Pin connection should be in according to code below. if any confusion then ask in comments below... 

//start global variables
char str[10] = "000";
unsigned char body_temp_str[7]="000 ";
unsigned char heart_beat_str[4]="00 0";
unsigned char in_char =0;
unsigned char out_char =0;
float time = 1;
float speed = 0;
// End global variables
// LCD module connections
sbit LCD_RS at PORTB0_bit;
sbit LCD_EN at PORTB1_bit;
sbit LCD_D4 at PORTB2_bit;
sbit LCD_D5 at PORTB3_bit;
sbit LCD_D6 at PORTB4_bit;
sbit LCD_D7 at PORTB5_bit;
sbit LCD_RS_Direction at DDB0_bit;
sbit LCD_EN_Direction at DDB1_bit;
sbit LCD_D4_Direction at DDB2_bit;
sbit LCD_D5_Direction at DDB3_bit;
sbit LCD_D6_Direction at DDB4_bit;
sbit LCD_D7_Direction at DDB5_bit;
// End LCD module connections
//start buttons
#define button_PIN1 PINC
#define button_DDR1 DDRC
#define button_PORT1 PORTC
#define button1_1 2
#define button1_2 3
#define button1_3 4
void init_buttons(){  //initialise buttons
button_DDR1 &= ~((1<<button1_3)|(1& lt;<button1_2)|(1<&l t;button1_1));
button_PORT1 |= (1<<button1_3)|(1< ;<button1_2)|(1<< button1_1);
}
//End buttons
//Start Sensors
#define sensors_PIN1 PINC
#define sensors_DDR1 DDRC
#define sensors_PORT1 PORTC
#define sensor1_0 0
#define sensor1_1 1
//define sensor1_2 2
void init_sensors(){ //initialise sensors
sensors_DDR1 &= ~((1<<sensor1_0)|(1& lt;<sensor1_1));
sensors_PORT1 &= ~((1<<sensor1_0)|(1& lt;<sensor1_1));
}
//End sensors
// Start outputs
#define outputs_PORT1 PORTD
#define outputs_DDR1 DDRD
#define buzzer 0         //pin number
//#define relay 1         //pin number
void init_outputs(){    //initialise outputs
outputs_DDR1 |= 1<<buzzer;
//outputs_DDR1 |= 1<<relay;
}
//End outputs

/********************* ************************** ************************** ******
* MAIN PROGRAM
********************** ************************** ************************** *****/
void main(){
  Lcd_Init();                        // Initialize Lcd
  init_buttons();
  init_sensors();
  init_outputs();
  outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
  Delay_ms(100);                     //wait for UART Initialize
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"HWAY SPD CHECKER");
  Lcd_Out(2,1,"Initiati ng.......");
  Delay_ms(1000);
< div style="background:#eeeeee; border:1px solid #cccccc; padding:5px 10px">  while(1){
////////////////////// /////////////ENTRY start///////////////////// //////////////
  unsigned time = 1;
  unsigned int speed = 0;
  if((sensors_PIN1 & (1<< sensor1_1)))
     {   outputs_PORT1 |= (1<<buzzer); //buzzer ON
         Lcd_Out(2,1,"SP D calculating..");
         Delay_ms(10);
         outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
         while(1) {
              time++;
              if((sensors_PIN1 & (1<< sensor1_0))) {
                   break;
              }
              Delay_ms(10);
         }
        speed = (1000/time);
        FloatToStr(speed, str);
        Lcd_Cmd(_LCD_CLEAR);               // Clear display
        Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
        Lcd_Out(1,1,"HWAY SPD CHECKER");
        Lcd_Out(2,1,"SPEED=&q uot;);
        Lcd_Out(2,7,"          ");
        Lcd_Out(2,7,str);
        Delay_ms(2000);
        
        
        if(!(button_PIN1 & (1<< button1_1))) {
          if(speed < 41) {
             Lcd_Cmd(_LCD_CLEAR);               // Clear display
             Lcd_Cmd(_LCD_CURSOR_ OFF);          // Cursor off
             Lcd_Out(1,1,"HI GHWAY SPD CHECKER");
             Lcd_Out(2,1,"SP EED =");
             Lcd_Out(2,7,"          ");
             Lcd_Out(2,7,str);
             Lcd_Out(2,13,"L OW ");
             outputs_PORT1 |= (1<<buzzer); //buzzer ON
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
             goto start;
          }
        }
        else {
             if(speed > 60) {
             Lcd_Cmd(_LCD_CLEAR);               // Clear display
             Lcd_Cmd(_LCD_CURSOR_ OFF);          // Cursor off
             Lcd_Out(1,1,"HI GHWAY SPD CHECKER");
             Lcd_Out(2,1,"SP EED =");
             Lcd_Out(2,7,"          ");
             Lcd_Out(2,7,str);
             Lcd_Out(2,13,"H IGH");
             outputs_PORT1 |= (1<<buzzer); //buzzer ON
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
             goto start;
          }
       }
     }
     start:
     Lcd_Out(2,1,"NO VEHICLE detected");
  }
}
/********************* ************************** ************************** ******
* End of File
********************** ************************** ************************** *****/


1570 views Write Comment
Share this page with your friends
share via Whatsapp

Posted By :
Mahesh Nigam
(Scientist)
2019-09-27 17:13
See Author's other Published Topics

Airtel cheating ther customers by incomplete description of recharge pack of Big companies like Airtel, also cheating their customers by providing incomplete or confusing description of their recharge plans
Big companies like Airtel, also cheating their customers by providing incomplete or confusing description of their recharge plans
साहस और धैर्य का प्रतिक कारगिल विजय दिवस  of साहस और धैर्य का प्रतिक कारगिल विजय दिवस
साहस और धैर्य का प्रतिक कारगिल विजय दिवस
Vaisakhi  of Vaisakhi
Vaisakhi
3 मार्च - विश्व वन्यजीव दिवस of 3 मार्च - विश्व वन्यजीव दिवस
3 मार्च - विश्व वन्यजीव दिवस
1 मार्च- विश्व प्रशंसा दिवस of 1 मार्च- विश्व प्रशंसा दिवस
1 मार्च- विश्व प्रशंसा दिवस
1 मार्च- विश्व नागरिक सुरक्षा दिवस of 1 मार्च- विश्व नागरिक सुरक्षा दिवस
1 मार्च- विश्व नागरिक सुरक्षा दिवस
1 मार्च - शून्य भेदभाव दिवस of 1 march शून्य भेदभाव दिवस
1 march शून्य भेदभाव दिवस
करती रही of पूरा नही बस थोड़ा सा ही समझा होता ....
पूरा नही बस थोड़ा सा ही समझा होता ....
वैलेंटाइन of वैलेंटाइन डे मनाने के पीछे एक रोचक तथ्य व 7 से 14 तक वैलेंटाइन सेलिब्रेट करने की सूची
वैलेंटाइन डे मनाने के पीछे एक रोचक तथ्य व 7 से 14 तक वैलेंटाइन सेलिब्रेट करने की सूची
National Test Agency of UGC NET December 2023 results and download its subject wise cut-off
UGC NET December 2023 results and download its subject wise cut-off
परीक्षा पे चर्चा  of परीक्षा पे चर्चा युवाओं के लिए तनाव मुक्त माहौल बनाने के लिए प्रधान मंत्री नरेंद्र मोदी के नेतृत्व में बड़े आंदोलन - 'एग्जाम वॉरियर्स' का हिस्सा है।
परीक्षा पे चर्चा युवाओं के लिए तनाव मुक्त माहौल बनाने के लिए प्रधान मंत्री नरेंद्र मोदी के नेतृत्व में बड़े आंदोलन - 'एग्जाम वॉरियर्स' का हिस्सा है।

Peoples

Comments...

Prajna: Can you explain the program once please?

Reply 17:13 2019-09-27

Mahesh Nigam(Scientist): @Prajna: ok, where do you getting problem?

Reply 02:30 2019-09-29

Rohit: I need a circuit diagram... would you help me with that?

Reply 13:21 2019-10-30

Admin: Circuit diagram is very simple, go through above codes and note down which pin is connected to which pin of the components. Main components are ir obstacle detector (2pcs port C0 and C1), buzzer (port D0), relay (port D1), button micro switch (port C3) and 16x2LCD (port B0-B5)

Reply 21:19 2019-10-30

Prem kumar: Can you please send me the circuit diagram.

Reply 10:18 2022-03-29

Atharv: Can you give the circuit diagram and more simplified code,?

Reply 14:09 2022-10-14

Write Your Comment

Related to Programming

Latest topics




More Categories
latest mobile phones ireps.gov.in irctc.co.in Working Principle Viral Discussion True Love quotes True Love Today is Celebrated For Tips for better life Tips and Hacks Technology News Teachers Day Quotes Study Materials Self Motivating Quotes Science Sad Lines (Sayeri) Romantic shayari quotes Robotics Reviews Results Questions_and_Answers Programming Problem Resolved PHP Codes PCB Design Online Works New Year Quotes Shayari Status My World My Responsibilities Motivational lines Mobile Issues Microcontrollers Lucknow Local News Latest Technology Iphone Homeopathy Historical place in India Heart Touching Love Quotes Health Good Night Quotes Good Morning Quotes GeM.gov.in GST portal Funny Lines (Sayeri) Friendship Quotes Food Recipes Exam Time Table Engineering Project Ideas Electronics Electronic and electrical project making ideas Electricals Educations Desh Bhakti Shayeri Criminal Love Cricket News Corona Updates Christmas Quotes Shayari Status CBSE Updates/Circulars Breaking News Breaking Heart Shayeri Break Up Lines (Sayeri) BirthDay Wishes Best kitchen Tips Best Valentine quotes Shayeri Beauty Hacks Basic Knowledges Attitude quotes shayari Attitude quotes Attitude quotes Assembly Election 2022
Go to top

Legal Links

  • Privacy Policy
  • Terms & Conditions
  • Return, Refund and Cancellation Policy
  • Shipping Policy
  • Disclaimer
  • Important Links

  • Contact Us
  • About Us
  • All copyright © 2020 are reserved by Groomix - designed by Groomix

    MORE

    Programming >
    latest mobile phones >
    ireps.gov.in >
    irctc.co.in >
    Working Principle >
    Viral Discussion >
    True Love quotes >
    True Love >
    Today is Celebrated For >
    Tips for better life >
    Tips and Hacks >
    Technology News >
    Teachers Day Quotes >
    Study Materials >
    Self Motivating Quotes >
    Science >
    Sad Lines (Sayeri) >
    Romantic shayari quotes >
    Robotics >
    Reviews >
    Results >
    Questions_and_Answers >
    Problem Resolved >
    PHP Codes >
    PCB Design >
    Online Works >
    New Year Quotes Shayari Status >
    My World My Responsibilities >
    Motivational lines >
    Mobile Issues >
    Microcontrollers >
    Lucknow Local News >
    Latest Technology >
    Iphone >
    Homeopathy >
    Historical place in India >
    Heart Touching Love Quotes >
    Health >
    Good Night Quotes >
    Good Morning Quotes >
    GeM.gov.in >
    GST portal >
    Funny Lines (Sayeri) >
    Friendship Quotes >
    Food Recipes >
    Exam Time Table >
    Engineering Project Ideas >
    Electronics >
    Electronic and electrical project making ideas >
    Electricals >
    Educations >
    Desh Bhakti Shayeri >
    Criminal Love >
    Cricket News >
    Corona Updates >
    Christmas Quotes Shayari Status >
    CBSE Updates/Circulars >
    Breaking News >
    Breaking Heart Shayeri >
    Break Up Lines (Sayeri) >
    BirthDay Wishes >
    Best kitchen Tips >
    Best Valentine quotes Shayeri >
    Beauty Hacks >
    Basic Knowledges >
    Attitude quotes shayari >
    Attitude quotes >
    Attitude quotes >
    Assembly Election 2022 >

    Peoples

    Latest Comments