IOT Experiment 7
Name : Raj Shah Sap Id:60019210056
Batch: A2
________________________________________________________________
Aim: Interfacing of LM35 using ESP32.
Code:
#define ADC_VREF_mV 3300.0 // in millivolt
#define ADC_RESOLUTION 4096.0
#define PIN_LM35 13 // ESP32 pin D13 connected to LM35
void setup() {
Serial.begin(9600);
}
void loop() {
// read the ADC value from the temperature sensor
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in °C
float tempC = milliVolt / 10;
// convert the °C to °F
float tempF = tempC * 9 / 5 + 32;
// print the temperature in the Serial Monitor:
Serial.print("Temperature: ");
Serial.print(tempC); // print the temperature in °C
Serial.print("°C");
Serial.print(" ~ "); // separator between °C and °F
Serial.print(tempF); // print the temperature in °F
Serial.println("°F");
delay(500);
}
IOT Experiment 7
Conclusion: