#include <WiFi.h>
#include <HTTPClient.h>
const int rtdPin = 34; // Analog pin connected to potentiometer we have taken for demonstration where input as a voltage is variable
void setup() // Beginning of the program
{
Serial.begin(115200);
}
void loop() {
// Read analog voltage from the resistor network
int sensorValue = analogRead(rtdPin);
Serial.print("pin value: ");
Serial.println(sensorValue);
// Convert analog reading to voltage
float voltage = sensorValue * (3.3 / 4095); // Assuming ESP32 ADC resolution of 12 bits and Vref of 3.3V
// Calculate resistance based on voltage using Ohm's Law
// Replace R1 and R2 with the values of the resistors in rtd network resistor in series
float R1 = 0.2; // assume resistance r1 in circuit is 0.2 ohm
float R2 = 0; // assume r2 having a value of 0 ohm
float R_total = (R1 + R2); // Calculate total resistance of the network
float rtdResistance = (voltage * R_total) / (3.3 - voltage); // Calculate resistance of RTD sensor
Serial.print("Resistance of RTD: ");
Serial.print(rtdResistance);
// Simulated temperature conversion based on resistance
// Replace with your own temperature-resistance conversion formula
float simulatedTemperature = convertToTemperature(rtdResistance);
// Print temperature
Serial.print("Temperature: ");
Serial.print(simulatedTemperature);
Serial.println(" °C");
delay(1000);
}
// Function to calculate using liner approximation formula for this simulation only
float convertToTemperature(float resistance) {
// based on the characteristics of your simulated RTD sensor.
// For simplicity, we'll return a linear approximation here.
float temperature = resistance * 100; // Linear approximation for demonstration only
return temperature;
}