nagata が 2024年10月25日18時29分43秒 に編集
コメント無し
タイトルの変更
イライラいらすとや不快指数警告器
イライラいらすとや警告器
本文の変更
**目次** ・概要 ・概要図 ・詳細 ・プログラム ・プログラムの実行結果 ・必要な物品 ・参考文献 **概要** ラズパイ4を使用し、センサーが検知した湿度と温度の値を使って不快指数を計算する。不快指数が警告する値であったとき、LINE Notifyでスマートフォンに警告を送るシステム。 **概要図**  **詳細** BME280を使い、湿度と温度を検知する。検知した湿度と温度の値を使って不快指数を計算((0.81×気温+0.01×相対湿度(0.99×気温-14.3)+46.3)した後、判定する。判定した結果、不快指数が70~75、80~85、85以上であったとき、LINE Notifyを使い、スマートフォンに警告のメッセージと画像を送る。 **プログラム** ``` import RPi.GPIO as GPIO import smbus2 import bme280 import sys import requests import time import os i2c_bus = smbus2.SMBus(1) address = 0x76 calibration_parms = bme280.load_calibration_params(i2c_bus, address) i=0 x=0 y=0 def send_1():
token = ''
token = 'iUlH6gX5mQGQWW8UcCPBfZZWJIG74dddQN8oGvrZKB8'
api = 'https://notify-api.line.me/api/notify' headers = {'Authorization': f'Bearer {token}'} data = {"message" : message } files = {'imageFile':open('face_angry_man3.png','rb')} result = requests.post(api,headers=headers,data=data,files=files) def send_2(): token = '' api = 'https://notify-api.line.me/api/notify' headers = {'Authorization': f'Bearer {token}'} data = {"message" : message } files = {'imageFile':open('face_angry_man4.png','rb')} result = requests.post(api,headers=headers,data=data,files=files) def send_3(): token = '' api = 'https://notify-api.line.me/api/notify' headers = {'Authorization': f'Bearer {token}'} data = {"message" : message } files = {'imageFile':open('face_angry_man5.png','rb')} result = requests.post(api,headers=headers,data=data,files=files) while True: if i >= 1 : time.sleep(10) i = 0 print("stop") bme_data = bme280.sample(i2c_bus,address,calibration_parms) temperature = bme_data.temperature humidity = bme_data.humidity print("%d" % temperature) print("%d" % humidity) hot = 0.81*temperature+0.01*humidity*(0.99*temperature-14.3)+46.3
if hot >= 75 and hot <= 80:
if hot >= 75 and hot < 80:
x = temperature y = humidity
message = "不快指数70以上75以下やや暑いです"
message = "不快指数75以上80未満やや暑いです"
time.sleep(2) send_1() i += 1
if hot >= 80 and hot <= 85:
if hot >= 80 and hot < 85:
x = temperature y = humidity
message = "不快指数80以上85以下熱くて汗が出ます"
message = "不快指数80以上85未満熱くて汗が出ます"
time.sleep(2) send_2() i += 1 if hot >= 85 : x = temperature y = humidity message = "不快指数85以上熱くてたまらないです" time.sleep(2) send_3() i += 1 print( x, y, hot) ``` **プログラムの実行結果**
  

**実物の写真**  **必要な物品** • Raspberry Pi 4 • BME280 **参考文献** ・【仕事の自動化】PythonでLINEを操作。メッセージや画像を自分へ送信しよう!【初心者の方もわかりやすいように解説】 https://kino-code.com/pythonline/ ・湿度・気圧センサーBME280 の使い方 https://s-design-tokyo.com/use-bme280/ ・不快指数の計算式とは?早見表もご紹介 https://kenchiku-setsubi.biz/fukaishisu/ ・怒る男性のイラスト https://www.irasutoya.com/2017/02/5.html ・スマートフォン・スマホのイラスト https://www.irasutoya.com/2014/11/blog-post_362.html ・シングルボードコンピュータのイラスト https://www.irasutoya.com/2016/05/blog-post_414.html