#include <Servo.h>
const int sensorPin = A0; // Analog pin for lambda sensor
const int servoPin = 9; // Digital PWM pin for servo control
const int potentiometerPin1 = A1; // Analog pin for first potentiometer
const int potentiometerPin2 = A2; // Analog pin for second potentiometer
Servo airValveServo; // Servo object
void setup() {
airValveServo.attach(servoPin);
Serial.begin(9600);
}
void loop() {
// Read the analog voltage from the lambda sensor
int sensorValue = analogRead(sensorPin);
// Convert the sensor value to a voltage (assuming 5V reference)
float voltage = sensorValue * (5.0 / 1023.0);
// Read the potentiometer values for tuning
int tune_min = analogRead(potentiometerPin1);
int tune_max = analogRead(potentiometerPin2);
// Map the potentiometer values to the desired range (0 to 90 degrees)
tune_min = map(tune_min, 0, 1023, 0, 1023); // Adjust as needed
tune_max = map(tune_max, 0, 1023, 0, 1023); // Adjust as needed
// Print the sensor and tuning values to the Serial Monitor
Serial.print("Sensor Voltage: ");
Serial.println(voltage, 2); // Print with 2 decimal places
Serial.print("Tune Min: ");
Serial.println(tune_min);
Serial.print("Tune Max: ");
Serial.println(tune_max);
// Map the sensor value to a servo angle value based on tuning variables
int servoAngle = map(sensorValue, tune_min, tune_max, 0, 90);
if(servoAngle > 90){servoAngle = 90;}
else return
// Control the air valve servo based on the sensor voltage
airValveServo.write(servoAngle);
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
Serial.println(' ');
delay(100); // Adjust as needed
}