top of page
Writer's pictureSanskruti Ashtikar

Digital Speedometer Using PIC Microcontroller

Updated: Nov 27

Introduction


A digital speedometer provides precise speed readings of a vehicle by converting the rotational speed of the wheels into a digital display. Using a PIC Microcontroller to design a digital speedometer offers a customizable and scalable solution for various applications. This article will guide you through the design, implementation, and calibration of a digital speedometer using a PIC Microcontroller.





Components Required


  1. PIC Microcontroller: PIC16F877A or a similar model.

  2. Speed Sensor: Hall Effect sensor or an Optical encoder.

  3. LCD Display: 16x2 or similar for displaying speed.

  4. Resistors and Capacitors: For signal conditioning and circuit stability.

  5. Power Supply: For powering the microcontroller and display.

  6. Connecting Wires and PCB: For assembling the circuit.


System Overview


The digital speedometer will measure the rotational speed of the vehicle’s wheels using a speed sensor. The PIC microcontroller will process the sensor data and display the speed on an LCD.


Circuit Diagram


Here’s a simplified overview of the circuit design:

  1. Speed Sensor: Connect the speed sensor to an interrupt pin on the PIC microcontroller.

  2. PIC Microcontroller: Connect to the LCD display for output and receive data from the speed sensor.

  3. LCD Display: Connect to the microcontroller for displaying the speed.


Speed Sensor Configuration


Hall Effect Sensor: This sensor produces a pulse every time a magnetic field crosses its path. It is often used in speedometers because of its robustness and reliability.

Optical Encoder: This sensor generates pulses based on the rotation of a disk with optical slots. It is also suitable for measuring rotational speed.

Connection: Connect the output of the speed sensor to an interrupt pin of the PIC microcontroller. This allows the microcontroller to detect each pulse from the sensor.


Microcontroller Configuration


The PIC Microcontroller (e.g., PIC16F877A) will handle the pulse counting and speed calculation. Follow these steps:

  1. Pin Configuration: Set up the interrupt pin for the speed sensor and the I/O pins for the LCD display.

  2. Programming: Write code to count pulses from the speed sensor, calculate the speed, and display it on the LCD.





Sample Code


Here’s a sample code snippet to illustrate pulse counting and speed calculation:


#include <xc.h>
#include "lcd.h"
#define _XTAL_FREQ 4000000
#define PULSES_PER_REV 20 // Number of pulses per wheel revolution
volatile unsigned int pulseCount = 0;
float speed = 0;
void interrupt ISR(void) {
    if (INTCONbits.INT0IF) { // Check if interrupt was triggered
        pulseCount++;
        INTCONbits.INT0IF = 0; // Clear interrupt flag
    }
}
void main(void) {
    TRISB0 = 1; // Set RB0 as input for speed sensor
    INTCONbits.INT0IE = 1; // Enable external interrupt
    INTCONbits.GIE = 1; // Global interrupt enable
    LCD_Init();
    LCD_Set_Cursor(1,1);
    
    while(1) {
        unsigned int pulses = pulseCount;
        pulseCount = 0; // Reset pulse count
        
        // Calculate speed in RPM
        speed = (pulses * 60.0) / PULSES_PER_REV;
        
        // Display speed on LCD
        LCD_Clear();
        LCD_Set_Cursor(1,1);
        LCD_Write_String("Speed:");
        LCD_Set_Cursor(2,1);
        LCD_Write_Float(speed);
        LCD_Write_String(" RPM");
        
        __delay_ms(1000); // Update speed every second
    }
}




Working of the System


  1. Initialization: On startup, the microcontroller initializes the LCD and sets up the interrupt for pulse counting.

  2. Pulse Counting: Each pulse from the speed sensor increments a counter in the microcontroller.

  3. Speed Calculation: The microcontroller calculates the speed based on the pulse count and the number of pulses per wheel revolution.

  4. Display Update: The speed is then displayed on the LCD, updated at regular intervals.


Testing and Calibration


  1. Component Testing: Verify the functionality of the speed sensor and LCD individually.

  2. Calibration: Adjust the PULSES_PER_REV value in the code to match the number of pulses generated per revolution of the wheel. This can be done by counting the pulses manually and comparing them to the expected value.

  3. Accuracy Check: Test the speedometer at various speeds to ensure accurate readings and make any necessary adjustments.


Additional Features


To enhance the digital speedometer, consider adding:

  1. Analog Speed Display: Integrate an analog gauge or bar graph for visual representation.

  2. Data Logging: Record speed data for analysis or diagnostics.

  3. Speed Alerts: Implement thresholds for speed warnings or alerts.

  4. Bluetooth Connectivity: For remote monitoring and data transmission.


Conclusion


A Digital Speedometer using a PIC Microcontroller provides an accurate and customizable solution for measuring and displaying vehicle speed. By following this guide, you can design a system that not only displays real-time speed but also offers opportunities for further enhancement and integration.


References


  • PIC16F877A Datasheet: Microchip

  • LCD Module Documentation: [Your LCD Manufacturer's Website]

  • MPLAB X IDE: Microchip


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



10 views0 comments

Related Posts

See All

Comentarios


bottom of page