與火災相關的警報零組件

這次一次介紹三種與溫度、火光相關的零組件,熱敏電阻與火燄偵測,熱敏電阻是透過熱的感應,而火燄偵測是感應火光產生的紅外線,各有其用處。另外從這次的介紹可以發現,相同的程式碼可以應用在許多相類似的地方,能深入了解與分辨類比、數位的輸入與輸出,就可以發展出許許多多的用法。

from gpiozero import MCP3008, LED, Buzzer, Button
from time import sleep


# 使用generator的用法
def convert_temp(gen):
    for value in gen:
        sleep(0.1)
        yield value


adc_sound = MCP3008(0)
led = LED(17)
buzzer = Buzzer(27)
button = Button(21)
# led.on()
# buzzer.on()
# 使用generator的用法
for temp in convert_temp(adc_sound.values):
    # data = temp * 1023
    # print('data: {:.1f}'.format(data))
    # 利用觸發設定值 threshold 觸發警報
    # if data < 510:
    #     led.on()
    #     buzzer.on()
    # else:
    #     led.off()
    #     buzzer.off()
    # 利用數位輸入Digital Out來判斷警報
    if not button.is_active:
        led.on()
        buzzer.on()
    else:
        led.off()
        buzzer.off()

Last updated