from picozero import Speaker
from machine import ADC, Pin
from utime import sleep
import math
led = Pin(14, Pin.OUT)
buzzer = Speaker(15)
gas = ADC(26)
RL = 5000
R0 = 10000
m = -0.42
b = 1.92
while True:
leitura = gas.read_u16()
print("Nível de gás/fumaça:", leitura)
sleep(1)
leitura = gas.read_u16()
tensao = (leitura / 65535) * 3.3
rs = (3.3 - tensao) * RL / tensao
razao = rs / R0
ppm = 10 ** ((math.log10(razao) - b) / m)
print("Leitura ADC:", leitura,
"| Tensão: {:.2f} V".format(tensao),
"| Rs: {:.0f} Ω".format(rs),
"| Fumaça estimada: {:.0f} ppm".format(ppm))
sleep(1)
if leitura > 5000:
buzzer.on()
led.on()
else:
buzzer.off()
led.off()