#define TEMPERATURE_PIN 34
#define THERMISTOR_PIN 32 // Changed to GPIO32
#define OIL_SENSOR_PIN 33 // The GPIO pin where the potentiometer wiper is connected
#define OIL_QUALITY_PIN 35 // Pin connected to the potentiometer wiper
const float B = 3950; // Beta parameter
const float referenceResistor = 10000; // Reference resistance (10kΩ)
const float referenceTemperature = 298.15;
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Set the ADC resolution to 12 bits for voltage reading
}
void loop() {
int sensor1Value = analogRead(OIL_QUALITY_PIN); // Read the potentiometer
float qualityPercentage = (float)sensor1Value / 4095.0 * 100.0; // Map to a percentage
Serial.print("Oil Quality: ");
if (qualityPercentage >= 75) {
Serial.println("Good");
} else if (qualityPercentage >= 50) {
Serial.println("Moderate");
} else if (qualityPercentage >= 25) {
Serial.println("Poor");
} else {
Serial.println("Replace Oil");
}
int sensorValue = analogRead(OIL_SENSOR_PIN); // Read the value from the potentiometer
// Convert the sensor reading to a voltage
float voltage = sensorValue * (3.3 / 4095.0);
// Map the voltage to a pressure value (This is just a simulated mapping)
float pressure = map(sensorValue, 0, 4095, 0, 100); // Assuming 0-100 PSI for simulation
Serial.print("Oil Pressure: ");
Serial.print(pressure);
Serial.println(" PSI");
int adc1Value = analogRead(THERMISTOR_PIN); // Read the voltage across the fixed resistor
float voltage1 = adc1Value * (3.3 / 4095.0); // Convert the ADC value to a voltage
// Convert the voltage to a resistance value
float resistance = referenceResistor / ((3.3 / voltage1) - 1.0);
// Calculate the temperature using the Beta parameter equation
float temperature = B / (log(resistance / referenceResistor) + B / referenceTemperature) - 273.15; // Convert Kelvin to Celsius
// Serial.print("Thermistor resistance: ");
// Serial.print(resistance);
// Serial.println(" ohms");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Reading and printing the voltage from GPIO34
int adc2Value = analogRead(TEMPERATURE_PIN); // Read ADC value from GPIO34
float voltage2 = (adc2Value * 5.0) / 4095.0; // Convert ADC value to voltage
Serial.print("Voltage: ");
Serial.print(voltage2);
Serial.println(" V");
delay(1000); // Delay a second before the next read
}