Hello, it's my first topic here, I hope it is all right.
I'm developing a simple ECU for my Turbo Diesel Jetta MK2 with Mechanical TDI Engine, to read values from 2 main sensors for now, crankshaft and turbo pressure, and I'm not getting why they aren't working as expected, here is my code
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
//LCD
// You can use any (4 or) 5 pins
// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins. For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define TFT_SCLK 52 //!SCL
#define TFT_MOSI 51 //!SDA
#define TFT_DC 49 //OR cd
#define TFT_RST 47 // you can also connect this to the Arduino reset
#define TFT_CS 45
//#define SD_CS 53
//#define SD_MISO 50
//#define sda 42 //3-AXIS
//#define scl 40 //3-AXIS
//#define sdo 38 //3-AXIS
#define lum 38
#define MAP_SENSOR A1
#define SIGNAL_CRANKSHAFT 2
//COLORS
#define BLUEVW 0x010010
//RPM Sensor
int engineSensorPin = SIGNAL_CRANKSHAFT - 2; // pulse output from the module
unsigned int RPM; // rpm reading
volatile byte pulses; // number of pulses
unsigned long timeOld;
// number of pulses per revolution
// based on your encoder disc
unsigned int pulsesPerTurn = 4;
//MAP SENSORS
float seaPressure = 100.3; //kPa
float mapValue = 0;
float mapValueFinal = 0;
//General
bool startup = true;
int refreshInterval = 0; //refresh interval in miliseconds
int loadTime = 2000; //loading screen time in miliseconds
Adafruit_ST7735 TFT = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
pulses = 0;
RPM = 0;
timeOld = 0;
do {
Serial.begin(115200);
pinMode(SIGNAL_CRANKSHAFT, INPUT);
attachInterrupt(digitalPinToInterrupt(engineSensorPin), counter, FALLING);
TFT.initR(INITR_BLACKTAB);
TFT.setRotation(1);
TFT.fillScreen(ST7735_BLACK);
startup = false;
} while (startup == true);
}
void loop() {
/****************************************************************************************************/
//RPM & TACHOMETER
detachInterrupt(0);
RPM = (60 * 1000 / pulsesPerTurn) / (millis() - timeOld) * pulses;
TFT.setCursor(15, 60);
TFT.setTextColor(ST7735_WHITE, ST7735_BLACK);
TFT.print("RPM: ");
TFT.println(RPM);
/****************************************************************************************************/
/****************************************************************************************************/
//MAP SENSORS
/*
4 bar map values
MPA Range (V) / kPa
0.4509 / 40
0.8337 / 71
2.9204 / 240
3.7106 / 304
4.8959 / 400
**** equation 4 bar ****
volt = 0.0123 * P - 0.0429
P=(x+0.0558)/0.054
*/
float vMap1 = map(analogRead(A0), 0, 1023, 0.4509, 4.8959);
//mapValue1 = ((VoltMap + 0.0123) / 0.0429) - seaPressure;
mapValue1 = map(VoltMap, 0.4509, 4.8959, 40, 400) - seaPressure;
TFT.setCursor(15, 75);
TFT.setTextColor(ST7735_WHITE, ST7735_BLACK);
TFT.print("Map Pressure (kPA): ");
TFT.println(mapValue1);
/****************************************************************************************************/
timeOld = millis();
pulses = 0;
//Restart the interrupt processing
attachInterrupt(digitalPinToInterrupt(engineSensorPin), counter, FALLING);
}
void counter() {
//Update count
pulses++;
}
Image of crankshaft disk

As you can see the engine works with 4 missing tooth at same distance, on the 4th missing the engine has 1 complete turn done, kinda like the old carburetor cars, giving 4 impulses per turn
So I have 2 major problems, ,
- the crankshaft sensor reads wrong rpm
- the map sensor with either formulas read wrong kPa (the map one reads 30kPa the other formula reads -76 kPa when should be 0 for both)
I just got some data from the crankshaft sensor
| Sensor Type: | Rated Voltage: | Tolerance: | Resistance: |
|---|---|---|---|
| Inductive Sensor | 12 V | 10 % | 1200 or 1400 Ohm (not sure) |

Humm I think im doing wrong here, help me out, should I direct induct 12v without any resistor?
What I'm doing is
5v on S pin
Ground on ground
and read from outpin with 1k ohm connected to 5v