fix daur — ESP32-S3 simulation

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

Components

Sketch code

// #include <Adafruit_NeoPixel.h>

// #define LED_PIN 2
// #define BUTTON_PIN 4
// #define NUMPIXELS 60

// Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

// bool lampuNyala = false;
// bool tombolSebelumnya = HIGH;

// #include "DHT.h"

// #define DHTPIN 5
// #define DHTTYPE DHT22
// DHT dht(DHTPIN, DHTTYPE);

// const int pinGas = 3;        // A0
// const float RL = 10.0;       // load resistance on the brick, kOhm
// float R0 = 10.0;             // sensing resistance in clean air, kOhm (calibrate!)
// const float DIVIDER_FACTOR = 1.5f; 

// #include <WiFi.h>
// #include <WiFiClient.h>
// #include "MqttHub.h"

// // Deklarasi klien jaringan
// WiFiClient wifiClient;

// // ==========================================
// // CALLBACK: PENERIMA PESAN MQTT
// // ==========================================
// void onMqttMessageReceived(String topic, String payload) {
//   Serial.println("MQTT Masuk: [" + topic + "] -> " + payload);
  
//   // Tambahkan logika respon topik Anda di sini
//   // Contoh:
//   // if (topic == "smarthome_acd81x/dapurku_65f21x0z/perintah") {
//   //   if (payload == "NYALA") { /* ... */ }
//   // }
// }

// float readRs() {
//   long sum = 0;
//   for (int i = 0; i < 16; i++) sum += analogRead(pinGas);
//   float v_pin = (sum / 16.0f) * 3.3f / 4095.0f;
//   float v_sensor_actual = v_pin * DIVIDER_FACTOR;
//   if (v_sensor_actual < 0.01f) v_sensor_actual = 0.01f;
//   return RL * (5.0f - v_sensor_actual) / v_sensor_actual; 
// }

// void setup() {
//   Serial.begin(115200);

//   R0 = readRs(); 

//   // 1. Hubungkan ke WiFi
//   // (Ubah "Wokwi-GUEST" menjadi SSID rumah Anda saat pindah ke alat fisik)
//   WiFi.begin("Velxio-GUEST", ""); 
//   Serial.print("Menghubungkan WiFi");
//   while (WiFi.status() != WL_CONNECTED) {
//     delay(500);
//     Serial.print(".");
//   }
//   Serial.println("\nWiFi Terhubung!");

//   // 2. Setup MQTT dengan ID Unik
//   // (Pastikan Client ID di param ke-4 selalu BEDA untuk setiap board)
//   setupMqtt(wifiClient, "broker.hivemq.com", 1883, "KucingMiawSigma67_Dapur");
  
//   // 3. Daftarkan fungsi penerima pesan
//   setMqttCallback(onMqttMessageReceived);
  
//   // Inisialisasi pin/sensor lain di bawah ini:
//   pixels.begin();
//   pixels.setBrightness(40);
//   pixels.clear();
//   pixels.show();

//   pinMode(BUTTON_PIN, INPUT_PULLUP);

//   dht.begin();
// }

// void readSensor(){
//   float humidity = dht.readHumidity();
//   float temperature = dht.readTemperature();

//   if (isnan(humidity) || isnan(temperature)) {
//     Serial.println("Failed to read from DHT");
//   } else {
//     Serial.print("Humidity: ");
//     Serial.print(humidity, 1);
//     Serial.print(" %\t");
//     Serial.print("Temperature: ");
//     Serial.print(temperature, 1);
//     Serial.println(" *C");
//   }

//   float rs = readRs();
//   Serial.print("Rs = ");
//   Serial.print(rs, 2);
//   Serial.print(" kOhm   Rs/R0 = ");
//   Serial.print(rs / R0, 3);
//   Serial.println("   

More projects by itsmebenn