home auto — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by danielolasunkami9.

Components

Sketch code

/*
  Gesture Command Lab -> Blynk -> Velxio ESP32 simulation
  --------------------------------------------------------
  - V0 -> LED 1 (GPIO25)
  - V1 -> LED 2 (GPIO26)
  - V2 -> LED 3 (GPIO32)
  - V3 -> Fan speed 0-100 (GPIO18, mosfet gate, PWM)
            ALSO drives LED4 (GPIO19) as a brightness stand-in, since
            Velxio's fan/motor component currently won't spin at all
            (confirmed independent of this code - a direct battery-to-motor
            test with no ESP32 involved also failed). LED4 dims up/down
            with the same value so you can verify V3 is arriving and being
            applied correctly while that's sorted out or reported to Velxio.

  NOTE: GPIO34/35 were the original pins but are INPUT ONLY on the ESP32
  (confirmed by the "GPIO can only be used as input mode" error) - moved
  LED1/LED2 to GPIO25/26 instead.

  This version connects to Wi-Fi manually (instead of letting Blynk.begin
  do it silently) so the serial monitor shows exactly where things stand.
  It uses the DHCP-assigned DNS server from Velxio's own "Open IoT
  Gateway" rather than forcing an external one - that gateway is the
  resolver that's actually reachable from inside the simulator.
*/

#define BLYNK_TEMPLATE_ID   "TMPL2Fb9AYIMW"
#define BLYNK_TEMPLATE_NAME "Home auto"
#define BLYNK_AUTH_TOKEN    "lDNPNQxgL3ekCWWM7_ZpqG6i41-mDGNI"

// Blynk's defaults (10s heartbeat, 2s socket timeout) assume a normal WiFi
// connection. Velxio's emulated network has occasional small lag spikes
// (we saw this earlier with DNS), which is enough to trip those tight
// defaults and cause the "network-level drop, no crash" pattern. Loosening
// both gives it more room to recover from a brief hiccup instead of
// dropping the connection outright.
#define BLYNK_HEARTBEAT 30
#define BLYNK_TIMEOUT_MS 8000

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "Espressif";
char pass[] = "";

const int LED1_PIN = 25;
const int LED2_PIN = 26;
const int LED3_PIN = 32;
const int FAN_PIN  = 18;
const int LED4_PIN = 19; // speed stand-in - dims with the same value as the fan

const int PWM_FREQ = 5000;
const int PWM_RES = 8; // 0-255

BLYNK_WRITE(V0) {
  int v = param.asInt();
  digitalWrite(LED1_PIN, v);
  Serial.printf("Turn LED 1 %s\n", v ? "ON" : "OFF");
}
BLYNK_WRITE(V1) {
  int v = param.asInt();
  digitalWrite(LED2_PIN, v);
  Serial.printf("Turn LED 2 %s\n", v ? "ON" : "OFF");
}
BLYNK_WRITE(V2) {
  int v = param.asInt();
  digitalWrite(LED3_PIN, v);
  Serial.printf("Turn LED 3 %s\n", v ? "ON" : "OFF");
}

BLYNK_WRITE(V3) {
  int percent = param.asInt();               // 0-100 from the gesture app
  int duty = map(percent, 0, 100, 0, 255);    // convert to PWM duty cycle
  ledcWrite(FAN_PIN, duty);   // fan/mosfet - currently not spinning, Velxio-side bug
  ledcWrite(LED4_PIN, duty);  // LED4 stand-in - dims proportionally, use this to confirm V3 is working
  Serial.printf("Set fan speed to %d%% (LED4 brightness set to match)\n", percent);
}

// I

More projects by danielolasunkami9