I've seen LOTS of sketches, examples, and diagrams for a 3-wire Hall Effect sensor, but not the 2 wire ABS sensor in my car, which I assume is an inductive sensor. I need a speedometer for one wheel. The ABS sensor is a 2 wire.
There is no available data on the sensor anywhere, but if it helps identify it, here is what I've learned.
There are 2 ways to test if this sensor is working properly, by unhooking it and jumping a multimeter across the 2 pins:
- Measure the Ohms. It will read ~1050 ohm or so.
- Set it to AC voltage and connect to the sensor. Spin the wheel, and it will read mV that increase with wheel speed.
I'm not sure if its a 5v or 12v sensor, but since its a late 80s GM sensor, I went with 12v.
I connected it to the arduino with this diagram:
Before I go any further, I'm using an Arduino NANO and am A TOTAL NOOB AT THIS.
I'm using the following sketch that I found here on a forums, and modified slightly.
I connected the pin from the ABS sensor to either digital 2 or 3 to use interrupts and changed the code accordingly.
When I spin the wheel up to 100+ RPM, I still get no reading at all, even though it is reading extremely quickly with a 47 tooth wheel. I get nothing.
#include <SPI.h>
#include <Wire.h>
#include <NeoHWSerial.h>
#define DEBUG_PORT_TYPE NeoHWSerial
#define DEBUG_PORT NeoSerial
// Variables:
volatile byte rpmCounter = 0; // pulse counter
unsigned long counter = 0; // total number of counting pulses since begining only for debugging
unsigned int rpm = 0; // rotational wheel speed in rpm
unsigned long previousTimeSensor = 0; // end time of the last sensor period in micros
unsigned long previousTimeScreen = 0; // end time of the last screen period in micros
unsigned long currentTime = 0; // actual time in micros
unsigned long deltaTimeSensor = 0;
const long periodSensor = 10000; // time period for pulse counting in micros
const long periodScreen = 300000; // time period for refresch the screen in micros
const int ppr = 47; // pulse per revolution
const float radiusRearWheell = 0.3307; // radius of the wheel in m
const float pi = 3.14159; // pi constant
float Speed = 0; // vehicle speed in km/h
float distance = 0; // travel distance in m
//------------------------------------------------------------------------------------------------//
void rpmCountFun() // function for attachInterrupt
{
rpmCounter++ ; // Update rpm counter
counter++; // Update global counter just for debugging
}
//------------------------------------------------------------------------------------------------//
void updateSensor() // function for attachInterrupt
{
deltaTimeSensor = currentTime - previousTimeSensor;
if (deltaTimeSensor >= periodSensor) {
detachInterrupt(3); // disable interrupt when calculating
rpm = rpmCounter * 6000000 / (ppr * deltaTimeSensor ); // convert frecuency to RPM be carefull period is in micros and need to be multiplied by 6000000 to be converted in min
Speed = 3.6 * radiusRearWheell * rpm * 2 * pi / 60; // speed calculation v=3.6*r*w with w in rad/s
distance = distance + rpmCounter * 2 * pi * radiusRearWheell / ppr; // distance calculation
rpmCounter = 0; // restart the RPM counter
DEBUG_PORT.print(currentTime);
DEBUG_PORT.print("\t \t \t ");
DEBUG_PORT.print(rpm);
DEBUG_PORT.print("\t \t ");
DEBUG_PORT.print(Speed);
DEBUG_PORT.print("\t \t ");
DEBUG_PORT.print(distance);
DEBUG_PORT.print("\t \t \t ");
DEBUG_PORT.println(counter);
previousTimeSensor += periodSensor; // uptade previousTimeSensor
attachInterrupt(3, rpmCountFun, RISING); //enable interrupt
}
}
//------------------------------------------------------------------------------------------------//
void setup() {
DEBUG_PORT.begin(9600);
attachInterrupt(3, rpmCountFun, RISING);
DEBUG_PORT.print("currentTime\t");
DEBUG_PORT.print("\t RPM \t");
DEBUG_PORT.print("\t speed\t");
DEBUG_PORT.print("\t distance\t");
DEBUG_PORT.println("\t global counter\t");
}
//------------------------------------------------------------------------------------------------//
void loop() {
currentTime = micros();
updateSensor();
}
Is it possible I'm going about this in the wrong way? There is almost zero information out there about reading a 2 wire proximity or inductive sensor for RPM