Mit KI Ähnliches finden
Druckprofil(0)
Modelldatei(0)
Veröffentlicht:2026-05-19 10:30:12
0
0
I created this little sensor for monitoring the level of tanks or anything else. comunication data works by Wifi and for the dashboard I used Blynk, the input si setted every 24 hours
electronic parts:
ESP32 WROOM
Vl53L0X IR Sensor
MicroPython code
import network import time import urequests from machine import Pin, I2C import vl53l0x # --- CREDENZIALI --- SSID = "wifi" PASSWORD = "password" BLYNK_TOKEN = "token" FONDO_TANICA = 164 LIVELLO_PIENO = 33 CAPACITA_LITRI = 0.15 # --- CONNESSIONE WIFI --- def connetti_wifi(): wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print("Connessione al WiFi in corso...") wlan.connect(SSID, PASSWORD) while not wlan.isconnected(): pass print("Connesso al WiFi! IP:", wlan.ifconfig()[0]) connetti_wifi() # --- INIZIALIZZAZIONE SENSORE --- print("Inizializzazione sensore...") i2c = I2C(0, sda=Pin(21), scl=Pin(22)) sensore_laser = vl53l0x.VL53L0X(i2c) # --- CICLO INFINITO --- while True: try: distanza_mm = sensore_laser.read() print("Distanza rilevata:", distanza_mm, "mm") if distanza_mm >= FONDO_TANICA: percentuale = 0 elif distanza_mm <= LIVELLO_PIENO: percentuale = 100 else: range_totale = FONDO_TANICA - LIVELLO_PIENO distanza_relativa = FONDO_TANICA - distanza_mm percentuale = int((distanza_relativa / range_totale) * 100) print("Livello %:", percentuale) litri = (percentuale/100)*CAPACITA_LITRI print ("Litri Stimati:", litri, "l") url_blynk = f"http://blynk.cloud/external/api/update?token={BLYNK_TOKEN}&v0={percentuale}" risposta = urequests.get(url_blynk) risposta.close() # 2. Invia i Litri sul Pin V1 url_litri = f"http://blynk.cloud/external/api/update?token={BLYNK_TOKEN}&v1={litri}" risp_litri = urequests.get(url_litri) risp_litri.close() print("Dato inviato a Blynk!") except Exception as e: print("Errore:", e) time.sleep(86400)for printing parts I used Prusament PETG V0
