#define ADC_VREF_mV 3300.0 // 3.3v en millivoltios
#define ADC_RESOLUTION 4096.0
#define PIN_LM35 36 // ESP32 pin GIOP36 (ADC0) conectado al LM35
#define factor 0.0805860805860
int PinLedR = 5,PinLedG = 4,PinLedB = 0;
int estadoR = LOW; //Definimos la variable que va a recoger el estado del LED
int estadoG = LOW;
int estadoB = LOW;
int datoVal;
float milliVolt,tempC,tempF;
void setup() {
Serial.begin(115200);
Serial.println("Ejemplo Sensor de Temperatura LM35");
pinMode(PinLedR, OUTPUT); pinMode(PinLedG, OUTPUT); pinMode(PinLedB, OUTPUT);
digitalWrite(PinLedR, LOW); digitalWrite(PinLedG, LOW); digitalWrite(PinLedB, LOW);
}
void loop(){
// Lectura de los datos del sensor
datoVal = analogRead(PIN_LM35);
// Convirtiendo los datos del ADC a milivoltios
milliVolt = datoVal * (ADC_VREF_mV / ADC_RESOLUTION);
// Convirtiendo el voltaje al temperatura en °C
tempC = datoVal * factor ;
// convirtiendo °C a °F
tempF = tempC * 9 / 5 + 32;
// Imprimiendo valores en el monitor serial:
Serial.print("Lectura del ADC: ");
Serial.print(datoVal); // Valor leido por el ADC
Serial.print(" Temperatura: ");
Serial.print(tempC); // Imprimiendo la temperatura en °C
Serial.print("°C");
Serial.print(" ~ "); //
Serial.print(tempF); // Imprimiendo la temperatura en °F
Serial.println("°F");
delay(500);
}