资料介绍
描述
温度预测
温度预测
所需硬件
连接
将 LM35 传感器连接到螺栓
第 1 步:握住传感器,以便您可以读取上面写的 LM35。
第 2 步:在此位置,将传感器的引脚从左到右识别为 VCC、输出和接地。
在上图中,VCC 连接到红色线,输出连接到橙色线,Gnd 连接到棕色线。步骤 3:使用公对母线将 LM35 的 3 个引脚连接到 Bolt Wifi 模块,如下所示如下:
- LM35 的 VCC 引脚连接到 Bolt Wifi 模块的 5v。
- LM35 的输出引脚连接到 Bolt Wifi 模块的 A0(interwetten与威廉的赔率体系 输入引脚)。
- LM35 的 Gnd 引脚连接到 Gnd。
最终电路应如下图所示:
既然您知道多项式回归是什么,我们将使用它与 Bolt Cloud 来预测您房间的温度。
第 1 步:在“云、API 和警报”模块的“通过 VPS 连接传感器”主题中进行与“温度监视器的硬件连接”屏幕相同的连接。
Step 2: Power up the circuit and let it connect to the Bolt Cloud. (The Green LED of the Bolt should be on)
Step 3: Go to cloud.boltiot.com and create a new product. While creating the product, choose product type as Input Device and interface type as GPIO. After creating the product, select the recently created product and then click on configure icon.
Step 4: In the hardware tab, select the radio button next to the A0 pin. Give the pin the name 'temp' and save the configuration using the 'Save' icon.
Step 5: Move to the code tab, give the product code the name 'predict', and select the code type as js.
Step 6: Write the following code to plot the temperature data and run the polynomial regression algorithm on the data, and save the product configurations.
setChartLibrary('google-chart');
setChartTitle('Polynomial Regression');
setChartType('predictionGraph');
setAxisName('time_stamp', 'temp');
mul(0.0977);
plotChart('time_stamp', 'temp');
Step 7: In the products tab, select the product created and then click on the link icon. Select your Bolt device in the popup and then click the 'Done' button.
Step 8: Click on 'deploy configuration' button and then the 'view this device' icon to view the page that you have designed. Below is the screenshot of the final output.
Step 1: Connect the temperature monitoring circuit as we have done in the previous lesson -Hardware connections for temperature monitor.
Step 2: Login into the putty by entering the IP address of your digital ocean droplet.
Step 3: After successful login, create a file named conf.py which will store all the credentials related to Twilio. To create a new file type sudo nano conf.py in the terminal. After that write below code to save all the credentials in a single file.
SID = 'You can find SID in your Twilio Dashboard'
AUTH_TOKEN = 'You can find on your Twilio Dashboard'
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'
Note: You have to replace all the above value with your credentials. You can find the first four value in Twilio dashboard and the last two in Bolt Cloud dashboard.
We store all the credentials in a separate file since it is sensitive data which should not be shared with anyone. Hence it is a good practice to avoid using credentials in code directly. After replacing all the values, save the file using CTRL+X.
Step 4: Now create one more file named temp_sms.py. To do so you have to type sudo nano temp_sms.py in the terminal. Now we will write main code to collect the data from the Bolt and send SMS if it crosses the threshold.
The algorithm for the code can be broken down into the following steps -
Fetch the latest sensor value from the Bolt device.
Check if the sensor value is in the range specified in our min and max values.
If it is not in range, send the SMS.
Wait for 10 seconds.
Repeat from step 1.
Now we will initialize two variables which will store minimum and maximum threshold value. You can initialize any minimum and maximum integer limits to them.
- This would send an alert if the temperature reading goes below the minimum limit or goes above the maximum limit similar to the alerts on a Pharmaceutical company's manufacturing line.
minimum_limit = 300
maximum_limit = 600
- Now to fetch the data from Bolt Cloud, we will create an object called 'mybolt' using which you can access the data on your Bolt.
- For the Bolt Cloud to identify your device, you will need to provide the API key and the Device ID when creating the mybolt object. Since the conf file holds the API key and Device ID variables, you can use them as follows,
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
- The above code will automatically fetch your API key and Device ID that you have initialized in conf.py file.
- Now to send an SMS, we will create an object of the same.
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
- The above code will automatically fetch your SID, AUTH_TOKEN, TO_NUMBER and FROM_NUMBER that you have initialized in conf.py file. Make sure you have given correct value in conf.py file.
- Since we want to continuously monitor the temperature reading, we will enclose our logic to fetch, compare and send the SMS inside an infinite loop using the `while True:` statement. An infinite loop is a special loop which executes its code continuously since its exit condition is never going to be valid. To exit the loop, we will need to forcibly exit the code by holding CTRL + C.
while True:
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
try:
sensor_value = int(data['value'])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
except Exception as e:
print ("Error occured: Below are the details")
print (e)
time.sleep(10)
- The code continuously fetches the temperature value using `analogRead` function. Since the sensor is connected to A0 pin of the Bolt, we will execute the analogRead() function on the pin A0.
- The response from the Bolt Cloud using the analogRead() function is in a JSON format, so we will need to load the JSON data sent by the cloud using Python's json library.
- The temperature value is inside a field labelled as "value" in the response. We can access the JSON values using the statement `sensor_value = int(data['value'])`. This line also converts the sensor reading to integer data type for comparing the temperature range.
- This is enclosed inside a try-except block to handle any error that may occur in the code. More explanation of try-except code block is given here.
- The next line of code checks if the temperature reading is above the maximum limit or below the minimum limit. If it exceeds, then the SMS will be sent.
- The SMS to be sent will contain the text "The Current temperature sensor value is" followed by the temperature value.
- The response from Twilio will be stored inside the `response` variable.
- Once the temperature reading has been sent, we will need to wait for 10 seconds to get the next reading. For this, we will put the program to sleep once every loop iteration.
- The statement `time.sleep(10)` puts the program execution on hold for 10 seconds. This means that the program would not execute for a period of 10 seconds.
In the above code, we are fetching the data every 10sec. You can change the value but ideally, it should be good if the time interval between 2 data points is more than 10sec.
Below is the complete code:
import conf
from boltiot import Sms, Bolt
import json, time
minimum_limit = 300
maximum_limit = 600
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
while True:
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
try:
sensor_value = int(data['value'])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
except Exception as e:
print ("Error occured: Below are the details")
print (e)
time.sleep(10)
Note: The above "sensor_value" is the raw temperature reading, obtained from the LM35 sensor. In case you want to convert this value to the temperature in degree Celsius, use the formula:
- Temperature=(100*sensor_value)/1024
Where sensor_value is the variable in which data obtained from the LM35 sensor is stored.
- Save the file. Time to run the code. To do so type `sudo python3 temp_sms.py` in terminal
- 使用BoltIot的语音控制LED灯
- 使用BOLTIOT进行LED控制
- 通过boltiot wifi模块启用的蜂鸣器系统
- 使用LM35和BoltIoT WiFi模块持续监测温度
- 基于分布式光纤测温的结冰风洞喷雾耙温度场 19次下载
- 如何进行医用红外测温仪及温度补偿威廉希尔官方网站 的研究 22次下载
- 如何使用红外温度传感器设计一个红外测温手环 41次下载
- 多点温度检测便携式测温仪的设计资料详细说明 4次下载
- 数字温度传感器DS1820在高精度测温仪中有怎么样的应用 8次下载
- 电缆导体无线测温与电缆运行状态监测系统的应用 12次下载
- DS18B20温度传感器测温如何显示在数码管上的程序免费下载
- 基于TN9红外温度传感器的红外测温仪设计方案资料下载 71次下载
- 谐振式水晶温度传感器的现状和发展预测
- 测温智能仪表中温度传感器的选择与使用
- 基于比色测温的温度场测量威廉希尔官方网站 研究
- 【铂电阻测温】如何快速实现多通道热电阻温度采集 248次阅读
- 芯片温度测量方法和应用案例 1154次阅读
- 元器件温度预测的十大技巧 986次阅读
- 预测元器件温度的10项提示—高级操作指南 943次阅读
- 热敏电阻如何测温度 1.2w次阅读
- NTC热敏电阻测温的工作原理及程序设计 2.5w次阅读
- 使用温度测温仪测量电烙铁头温度的步骤分析 1.8w次阅读
- 工业红外测温仪能测体温吗 3.2w次阅读
- 红外温度计原理_红外温度计使用方法 1.8w次阅读
- 电力无线测温之TN-TS4H有源无线温度传感器 2558次阅读
- 基于PIC单片机控制温度传感器测温的设计 3278次阅读
- 电阻测温原理是什么?单片机温度计电路设计 1.2w次阅读
- 一种高精度低成本测温方案详解 3794次阅读
- 集成温度传感器测温电路 3249次阅读
- 硅温度传感器测温电路 3384次阅读
下载排行
本周
- 1使用单片机实现七人表决器的程序和仿真资料免费下载
- 2.96 MB | 44次下载 | 免费
- 2联想E46L DAOLL6笔记本电脑图纸
- 1.10 MB | 2次下载 | 5 积分
- 3MATLAB绘图合集
- 27.12 MB | 2次下载 | 5 积分
- 4PR735,使用UCC28060的600W交错式PFC转换器
- 540.03KB | 1次下载 | 免费
- 5UCC38C42 30W同步降压转换器参考设计
- 428.07KB | 1次下载 | 免费
- 6DV2004S1/ES1/HS1快速充电开发系统
- 2.08MB | 1次下载 | 免费
- 7模态分解合集matlab代码
- 3.03 MB | 1次下载 | 2 积分
- 8美的电磁炉维修手册大全
- 1.56 MB | 1次下载 | 5 积分
本月
- 1使用单片机实现七人表决器的程序和仿真资料免费下载
- 2.96 MB | 44次下载 | 免费
- 2UC3842/3/4/5电源管理芯片中文手册
- 1.75 MB | 15次下载 | 免费
- 3DMT0660数字万用表产品说明书
- 0.70 MB | 13次下载 | 免费
- 4TPS54202H降压转换器评估模块用户指南
- 1.02MB | 8次下载 | 免费
- 5STM32F101x8/STM32F101xB手册
- 1.69 MB | 8次下载 | 1 积分
- 6HY12P65/HY12P66数字万用表芯片规格书
- 0.69 MB | 6次下载 | 免费
- 7华瑞昇CR216芯片数字万用表规格书附原理图及校正流程方法
- 0.74 MB | 6次下载 | 3 积分
- 8华瑞昇CR215芯片数字万用表原理图
- 0.21 MB | 5次下载 | 3 积分
总榜
- 1matlab软件下载入口
- 未知 | 935119次下载 | 10 积分
- 2开源硬件-PMP21529.1-4 开关降压/升压双向直流/直流转换器 PCB layout 设计
- 1.48MB | 420061次下载 | 10 积分
- 3Altium DXP2002下载入口
- 未知 | 233084次下载 | 10 积分
- 4电路仿真软件multisim 10.0免费下载
- 340992 | 191367次下载 | 10 积分
- 5十天学会AVR单片机与C语言视频教程 下载
- 158M | 183335次下载 | 10 积分
- 6labview8.5下载
- 未知 | 81581次下载 | 10 积分
- 7Keil工具MDK-Arm免费下载
- 0.02 MB | 73807次下载 | 10 积分
- 8LabVIEW 8.6下载
- 未知 | 65987次下载 | 10 积分
评论
查看更多