HAL Sensors for speed measurement

HAL Sensors
Uni- and Bipolar Hall IC Switches for Magnetic Field Applications

TLE 4905L

This hall sensor is an open collector sensor, So how to get the output from this sensor is you need to add a resistor RL 1.2k ohm as a circuit below.

Application Circuit from Datasheet

Signal capture from oscilloscope

Sample Code:

#include <TimerThree.h>

//Speed Sensors
#define speed_r 2
#define speed_l 3
#define length_4pulse 80 //millimeter

volatile int speed_pulse = 0;
volatile float current_speed = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  //Speed Detect
  pinMode(speed_r, INPUT);
  pinMode(speed_l, INPUT);
  attachInterrupt(digitalPinToInterrupt(speed_r), speed_count, RISING);
  Timer3.initialize(100000); // initialize timer3, and set a 1/10 second period
  Timer3.attachInterrupt(speed_calculate);
}

void loop() {
  // put your main code here, to run repeatedly:
  //Correct Data
  Serial.println("----");
  Serial.println(current_speed);
  delay(100);
}

void speed_count(){
  speed_pulse++;
}

void speed_calculate(){
  current_speed = ((float) speed_pulse * length_4pulse / 4) * 10; // multiply 10 by time scaling
  speed_pulse = 0;
}

This code used timer3 and external interrupt for counting and calculate the speed. 

The equation for calculating speed:
Equation for 

We found that if sensors can capture signals 4 pulses then a car is moving 80 millimeters. But in our code we update speed every 100ms, So time scale value is 10.

Reference: Datasheet

Comments

Popular posts from this blog

Sharp 2Y0A21 F 03

CMPS03 Compass Module

Change I2C Address SRF10