Lambda calculation

Lambda calculation added to the loop with the conversion of an analog
value to a 0 to 5 voltage to return the lambda value.
This commit is contained in:
Martin Girard committed 2026-09-15 11:13:35 +02:00
1 parent a21bf160bc
commit 55f271f6ce
1 file changed
+16
+16
View File
@@ -3,9 +3,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include <Arduino.h> #include <Arduino.h>
const byte interruptPin = 2; const byte interruptPin = 2;
const byte lambdaPin = A0;
volatile unsigned long timestamp1 = 0; volatile unsigned long timestamp1 = 0;
volatile unsigned long timestamp2 = 0; volatile unsigned long timestamp2 = 0;
volatile bool new_rpm = false; volatile bool new_rpm = false;
const unsigned long deltat_lambda = 100000;
unsigned long last_lambda = 0;
void interrupt(){ void interrupt(){
unsigned long now = micros(); unsigned long now = micros();
@@ -18,6 +21,7 @@ void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(115200); Serial.begin(115200);
pinMode(interruptPin, INPUT); pinMode(interruptPin, INPUT);
pinMode(lambdaPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin),interrupt,FALLING); attachInterrupt(digitalPinToInterrupt(interruptPin),interrupt,FALLING);
} }
@@ -27,8 +31,20 @@ void loop() {
unsigned long deltat = timestamp1 - timestamp2; unsigned long deltat = timestamp1 - timestamp2;
float rpmhz = 500000.0 / deltat; float rpmhz = 500000.0 / deltat;
new_rpm = false; new_rpm = false;
Serial.print("Speed: ");
Serial.println(rpmhz); Serial.println(rpmhz);
} }
unsigned long now = micros();
if (now > last_lambda + deltat_lambda){
float output = analogRead(lambdaPin);
float voltage = output / 204.6;
float lambda = 0.56030161*voltage + 0.43969839;
last_lambda = now;
Serial.print("Voltage: ");
Serial.println(voltage);
Serial.print("Lambda:");
Serial.println(lambda);
}
} }