/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL5mMIlGvkq"
#define BLYNK_TEMPLATE_NAME "Led y potenciómetro"
#define BLYNK_AUTH_TOKEN "V8jA7uvbun6uXpTJHbXYBH17jmtwejse"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define ledPin 5
#define servoPin 13 // GPIO pin used to connect the servo control (digital out)
// Possible ADC pins on the ESP32: 0,2,4,12-15,32-39; 34-39 are recommended for analog input
#define potPin 34 // GPIO pin used to connect the potentiometer (analog in)
#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
BlynkTimer timer; // This function creates the timer object
int potVal;
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
myservo.setPeriodHertz(50);// Standard 50hz servo
//myservo.attach(servoPin, 500, 2400); // attaches the servo
myservo.attach(servoPin);
timer.setInterval(1000L, myTimer); //el intervalo de lectura de la entrada analogica
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
timer.run(); // runs BlynkTimer
}
// mío
BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
if (param.asInt() == 1)
{
digitalWrite(ledPin, HIGH); //
Serial.println("Enciendo el LED");
}
else
{
digitalWrite(ledPin, LOW); //
Serial.println("Apago el LED");
}
}
BLYNK_WRITE(V1) // Executes when the value of virtual pin 1 changes
{
myservo.write(param.asInt());
}
void myTimer()
{
potVal = analogReadMilliVolts(potPin); // Reading sensor from hardware analog pin A0
float potVal_V = potVal / 1000.0;
Serial.println("V = " + String(potVal_V, 2));
Blynk.virtualWrite(V2, potVal_V);
//Notificación por mail y SMS
if (potVal_V > 3)
{
//Blynk.logEvent("high_temp");
// para cambiar la descripción del evento de modo que incluya el valor de la variable
Blynk.logEvent("high_temp", String("El voltaje es alto! V: ") + potVal_V);
}
}
BLYNK_CONNECTED()
{ Blynk.syncVirtual(V0); // sincroniza el estado del widget
Blynk.syncVirtual(V1); // sincroniza el estado del widget
}