from machine import Pin, ADC
from time import sleep
import math
mic = ADC(Pin(2))
mic.atten(ADC.ATTN_11DB)
calibration_constant = 2.0
noise_threshold = 60
while True:
mic_level = mic.read()
mic_level_db = 20 * math.log10(mic_level / calibration_constant)
if mic_level_db > noise_threshold:
print("Warning: Noise pollution exceeds threshold!")
print("dB: {:.2f}".format(mic_level_db))
sleep(0.3)