该项目主要具有三个功能,即收集人的温度,计算人是否发烧,通知用户该人的健康状况,并通知站在门口的人是否允许他进入房屋或不是。
在本节中,我们研究项目的发烧检测和警报功能。
下面给出LM35温度传感器、LED、蜂鸣器和螺栓模块的电路连接。
LM35 温度传感器的输入来自模拟引脚 A0,LED 和蜂鸣器的输出写入数字引脚 1 和 2。LM35 温度传感器的电源由螺栓模块的 5V 引脚提供。
最初蜂鸣器和灯闪烁,通知用户将温度传感器放在手臂下15秒,15秒后蜂鸣器会蜂鸣一次,计算传感器接收到的值并与阈值比较(390 = 38摄氏度和换算公式 = 传感器值 *100 / 1024)
如果该值低于 390,则此人可以安全进入房屋,并在电报消息服务的帮助下通知房主,并在门口通过闪烁蓝灯和蜂鸣器五次来通知此人。
否则,如果该值等于或大于 390,则此人不安全进入房屋(他可能患有 COVID19),并且使用电报消息服务通知房主,并且门上的红灯亮起并且蜂鸣器嗡嗡作响持续 5 秒。
这个项目的 python 编码已经在 Spyder (windows) 中完成。在我们开始用 python 编写自动发烧检测和警报之前,我们需要制作一个配置文件,该文件将包含每个用户/设备的特定密钥。我们将在我们的主代码中导入这个文件并使用各种属性。这样做的好处是每个用户只需更改配置文件的内容即可使用该产品。
以下是配置文件(命名为 conf.py):
API_KEY = "XXXX" //Bolt Cloud API Key
DEVICE_ID = "BOLTXXXX" //Device ID of the Bolt Module
TELEGRAM_CHAT_ID = "-XXXX" //Chat ID of the created Telegram Channel
TELEGRAM_BOT_ID = "botXXXX" //Bot ID of the created Telegram Bot
Threshold = "XXX" //Threshold value for fever
Bolt 模块的 API 密钥和设备 ID 可以如下确定:
按照以下说明将您的 Bolt 设备连接到 Bolt Cloudhttps://cloud.boltiot.com/ 。之后将出现以下屏幕。螺栓设备 ID 以黑色交叉。
转到 API 部分以了解 API 密钥
安装 Telegram App 并使用您的手机号码登录。然后创建一个频道和一个机器人。
#Import the Required Libraries
from boltiot import Bolt import requests import json import time import conf
#To identify your bolt device
mybolt = Bolt(conf.api_key, conf.device_id)
#To get data from sensor
def get_sensor_value_from_pin(pin):
"""Returns the sensor value. Returns -999 if request fails"""
try:
response = mybolt.analogRead(pin)
data = json.loads(response)
if data["success"] != 1:
print("Request not successfull")
print("This is the response->", data)
return -999
sensor_value = int(data["value"])
return sensor_value
except Exception as e:
print("Something went wrong when returning the sensor value")
print(e)
return -999
#To send notifying messages to the owner
def send_telegram_message(message):
"""Sends message via Telegram"""
url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
data = {
"chat_id": conf.telegram_chat_id,
"text": message
}
try:
response = requests.request(
"POST",
url,
params=data
)
telegram_data = json.loads(response.text)
return telegram_data["ok"]
except Exception as e:
print("An error occurred in sending the alert message via Telegram")
print(e)
return False
#Main Loop is started
while True:
print("*******************************")
print("Loop Starting")
#initial Notification to person about the starting process
mybolt.digitalWrite("2","HIGH")
mybolt.digitalWrite("1","HIGH")
time.sleep(0.5)
mybolt.digitalWrite("1","LOW")
mybolt.digitalWrite("2","LOW")
print("Reading time 15 secs")
#time required to stabilize the environment and accurate reading
time.sleep(15)
sensor_value = get_sensor_value_from_pin("A0")
print(sensor_value)
#if the person has fever
if(sensor_value >conf. threshold):
message = "Alert! Person at the door has fever, Dont LET HIM IN!!!. \nThe current value of his fever is " + str(sensor_value*100/1024)
telegram_status = send_telegram_message(message)
print("person at the door is not safe do not let him enter")
mybolt.digitalWrite("2","HIGH")
time.sleep(4)
mybolt.digitalWrite("2","LOW")
#if person doesn’t have fever
else:
message = "Alert! Person at the door is healthy, LET HIM IN!" + str(sensor_value*100/1024)
telegram_status = send_telegram_message(message)
print("Person at the door is safe, we can let him enter")
mybolt.digitalWrite("1","HIGH")
time.sleep(0.1)
mybolt.digitalWrite("1","LOW")
for _ in range(5):
mybolt.digitalWrite("2","HIGH")
time.sleep(0.5)
mybolt.digitalWrite("2","LOW")
print("next cycle will start in 5 secs")
print("*******************************")
#wait for 5 seconds before next cycle
time.sleep(5)
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
全部0条评论
快来发表一下你的评论吧 !