MORE RELATED

GROOMIX INFO
Blogs & Articles
MENU
. . .

programming

views : 153

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
********************** ************************** ************************** *****/

Posted By :
Mr. Unique

2016-08-09/20:52:41

Share this Page

Comments...

More :programming

programming
Arduino UNO tachometer coding with variable resistor and DC motor speed control
views :183

p

programming
Here is the code to interface 2 serial devices with AVR
views :162

p

programming
Software Uart for AVR microcontroller tested on 1200 baud rate
views :611

p

programming
ATMEL STUDIO-While loop conditioning issues
views :229

p

programming
ATMEL STUDIO-While loop is not working using interrupt incremented conditioning
views :293

p

programming
Copy and paste code for facebook share button in your websites
views :352
programming
How to program atmel 8051 family microcontroller? (step by step)
views :245
programming
Embedded program code in C language for Digital Voltmeter for AVR microcontroller
views :315
programming
Assemby program code for Automatic Door Opening System (8051 family microcontroller)
views :228
programming
Very simple and accurate Seven Segment Display program Code in Embedded C language
views :261

p

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

p

programming
Assembly program for accurate 1 second delay function
views :182
programming
What is Embedded system programming?
views :157

Latest Updates

kya transformer dc pe work kr skta h..?
views :0

kya transformer dc pe work kr skta h..?
views :137

kya transformer dc pe work kr skta h..?
views :0
Breaking News
Best internet Recharge Plans than jio..!
views :214
Engineering Project Ideas
Vehicle Theft Protection Using Gsm
views :191
Engineering Project Ideas
DTMF Controlled Robot or Mobile Controlled Robot
views :139
Engineering Project Ideas
Digital Clock With Home Appliances Control Using Microcontroller
views :100
Engineering Project Ideas
Cooking Monitor
views :196
Engineering Project Ideas
Boundary Security System(Wireless)
views :145
Engineering Project Ideas
Automatic Garage Parking System
views :138

---More To Do---

This pages is developed to give users a genuine web materials of all types throughout the world. Many articles, by experts are publishing here, every hours. You can publish your topics as well as you can comment on all posted topics and learn more. Many types of topics are published here like Technology based ( Electronics, Electricals, Mechanicals, civil engineering, computer science, programming and software development, Assemply language codings), Health like medicine, healthy diets, Homeopathy etc) and many types of latest news updates.


All content, design, and layout are Copyright © 2016 - Digital Photography Review All Rights Reserved. Reproduction in whole or part in any form or medium without specific written permission is prohibited.

MORE TO DO