火災報知器を炎センサーモジュールとRaspberry Piで作る
概要
アリエクで炎センサーを買いました

フォトダイオードで760~1100nmの赤外線を検出する仕組みらしいです

感度は可変抵抗で調節でき、炎を検知するとDOがLOWになります。
赤外線を検出して反応する仕組み上当たり前ですが、日光が当たる場所ではまともに使えません。
また、指向性がかなり高く直線上に炎がないと全く検出できませんでした。 detection angle 60 deg とか書いてますがそんなに広くないと思います。なので、炎が出そうな場所に狙って配置する必要があります…
プログラム
炎を検出したらブザーを鳴らしてメールが飛ぶようなプログラムにしました。また、メールの本文に温度センサーAHT10で読み取った室温も記録して送信します。
AHT10について
炎センサーはGPIO27、ブザーはGPIO17に繋いでいます。
fire.pyはメインプログラム、temp.pyは室温を返すプログラム、command.shはメールを送るスクリプト、mailtext.txtはメール本文で、すべて /home/pi/fire/ に入っているとします。なお、sendmailでgmailを踏み台にしてメールを送信してます。
fire.py
import RPi.GPIO as GPIO
import time
import requests
import subprocess
import pigpio
GPIO_INPUT = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_INPUT, GPIO.IN)
buzzer_gpio = 17
gpio = pigpio.pi()
gpio.set_mode(buzzer_gpio, pigpio.OUTPUT)
try:
while True:
state = GPIO.input(GPIO_INPUT)
if state == GPIO.LOW:
res = subprocess.run("sh /home/pi/fire/command.sh", shell=True)
while state == GPIO.LOW:
gpio.write(buzzer_gpio, 1)
time.sleep(10)
gpio.write(buzzer_gpio, 0)
state = GPIO.input(GPIO_INPUT)
else:
time.sleep(3)
except KeyboardInterrupt:
print("stopped")
GPIO.cleanup()
temp.py
# -*- coding: utf-8 -*-
#!/usr/bin/python3
# https://github.com/Thinary/AHT10/blob/master/src/Thinary_AHT10.cpp
# https://myhydropi.com/raspberry-pi-i2c-temperature-sensor
# cleaned up and documented smbus 1 and some errors
# GJ 03-2020
# i2cdetect -y 0
import smbus
import time
# Get I2C bus
#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
bus = smbus.SMBus(1) # Rev 2 Pi uses 1
# when you have a 121 IO Error, uncomment the next pause
# time.sleep(1) #wait here to avoid 121 IO Error
config = [0x08, 0x00]
bus.write_i2c_block_data(0x38, 0xE1, config)
time.sleep(0.5)
byt = bus.read_byte(0x38)
#print(byt&0x68)
MeasureCmd = [0x33, 0x00]
bus.write_i2c_block_data(0x38, 0xAC, MeasureCmd)
time.sleep(0.5)
data = bus.read_i2c_block_data(0x38,0x00)
#print(data)
temp = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5]
ctemp = ((temp*200) / 1048576) - 50
print(u'{0:.1f}'.format(ctemp))
command.sh
#!/bin/bash<br><br>sed -i -e "5d" /home/pi/fire/mailtext.txt<br>python3 /home/pi/fire/temp.py >> /home/pi/fire/mailtext.txt<br>cat /home/pi/fire/mailtext.txt | sendmail -i -t
mailtext.txt
From: [email protected]
To: [email protected]
Subject: FIRE alart!!!
XX.X
systemctlに登録して自動起動します
$ sudo nano firealarm.service
[Unit]
Description = fire alarm daemon
[Service]
ExecStart = python3 /home/pi/fire/fire.py
Restart = always
Type = simple
[Install]
WantedBy = multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable firealarm
$ sudo systemctl start firealarm
ケース
ケースを3Dプリンターで作りました。このモデルを使わせていただきます。
https://www.thingiverse.com/thing:2560768
M3の皿ネジは持ってなかったので、STLを編集して普通のM3ネジが使えるようにザグリを削除しました。ここにアップしておきます。なお大きさの指定を間違えて10倍になってる😅ので、スライサーソフトで1/10倍にしてください。
https://drive.google.com/file/d/1kRcqGKSGf42J3THlbhNTNXuBhVPFdAZX/view?usp=sharing

火の出そうな場所に設置します

最近のコメント