U2 — Aitewinrobot Esp32C3 Supermini simulation

An interactive Aitewinrobot Esp32C3 Supermini circuit simulation you can run free in your browser on Velxio, by edelarosagon.

Components

Sketch code

from machine import Pin, I2C, ADC
import dht
import ssd1306
import time

# --- Constantes ---
UMBRAL_TEMP = 30   # grados C
INTERVALO = 2      # segundos entre lecturas

# --- Hardware ---
i2c = I2C(0, scl=Pin(6), sda=Pin(5), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
sensor = dht.DHT22(Pin(4))
ldr = ADC(Pin(3))
ldr.atten(ADC.ATTN_11DB)   # rango completo 0-3.3 V
led = Pin(2, Pin.OUT)

print("Direccion I2C:", [hex(d) for d in i2c.scan()])


def leer_dht():
    """Devuelve (temperatura, humedad) o (None, None) si falla."""
    try:
        sensor.measure()
        return sensor.temperature(), sensor.humidity()
    except OSError:
        return None, None


def leer_luz():
    """Devuelve la luz en porcentaje (0-100)."""
    return ldr.read() * 100 // 4095


def fmt(valor):
    """Da formato a un valor o muestra -- si no hay dato."""
    return "--" if valor is None else "{:.1f}".format(valor)


while True:
    temp, hum = leer_dht()
    luz = leer_luz()

    # Logica de estados
    if temp is None:
        estado = "ERROR SENSOR"
        led.value(0)
    elif temp > UMBRAL_TEMP:
        estado = "ALERTA"
        l

More projects by edelarosagon