#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL5gudIlu_d"
#define BLYNK_TEMPLATE_NAME "esp32 LM35 oled version 2"
#define BLYNK_AUTH_TOKEN "YQ_FFMlV3-4eEdzrXQAoLjXvUHI9Gh5p"
//#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define PIN_LM35 34
#define ADC_VREF_mV 5000.0 // in millivolt, el sensor era para Arduino
#define ADC_RESOLUTION 4096.0
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3C ///(0x3D) See datasheet for Address;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
BlynkTimer tiempo;
void Lectura()
{ // This function describes what will happen with each timer tick
int adcVal = analogRead(PIN_LM35);
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
float temperatura=milliVolt/10;
Blynk.virtualWrite(V2, temperatura);
display.clearDisplay();
display.setCursor(15, 0);
display.print(" -- HOLA ANA-- ");
display.print("El valor de la temperatura es:");
display.print(temperatura);
display.display();
}
void setup() {
Serial.begin(9600);
Serial.println("Programa de control de temperatura");
// en Wokwi
Serial.println("Pulsa sobre el sensor LM35 para cambiar el valor de Tª");
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); // initialize the OLED
display.setTextColor(SSD1306_WHITE); // set text color to white
display.setTextSize(1);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
tiempo.setInterval(1000L, Lectura); // Setting interval to send data to Blynk Cloud
}
void loop() {
Blynk.run(); // Runs all Blynk stuff
tiempo.run(); // runs BlynkTimer
}