資料介紹
描述
溫度預測
溫度預測
所需硬件
連接
將 LM35 傳感器連接到螺栓
第 1 步:握住傳感器,以便您可以讀取上面寫的 LM35。
第 2 步:在此位置,將傳感器的引腳從左到右識別為 VCC、輸出和接地。
在上圖中,VCC 連接到紅色線,輸出連接到橙色線,Gnd 連接到棕色線。步驟 3:使用公對母線將 LM35 的 3 個引腳連接到 Bolt Wifi 模塊,如下所示如下:
- LM35 的 VCC 引腳連接到 Bolt Wifi 模塊的 5v。
- LM35 的輸出引腳連接到 Bolt Wifi 模塊的 A0(模擬輸入引腳)。
- LM35 的 Gnd 引腳連接到 Gnd。
最終電路應如下圖所示:
既然您知道多項式回歸是什么,我們將使用它與 Bolt Cloud 來預測您房間的溫度。
第 1 步:在“云、API 和警報”模塊的“通過 VPS 連接傳感器”主題中進行與“溫度監(jiān)視器的硬件連接”屏幕相同的連接。
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模塊啟用的蜂鳴器系統(tǒng)
- 使用LM35和BoltIoT WiFi模塊持續(xù)監(jiān)測溫度
- 基于分布式光纖測溫的結冰風洞噴霧耙溫度場 19次下載
- 如何進行醫(yī)用紅外測溫儀及溫度補償技術的研究 22次下載
- 如何使用紅外溫度傳感器設計一個紅外測溫手環(huán) 41次下載
- 多點溫度檢測便攜式測溫儀的設計資料詳細說明 4次下載
- 數(shù)字溫度傳感器DS1820在高精度測溫儀中有怎么樣的應用 8次下載
- 電纜導體無線測溫與電纜運行狀態(tài)監(jiān)測系統(tǒng)的應用 12次下載
- DS18B20溫度傳感器測溫如何顯示在數(shù)碼管上的程序免費下載
- 基于TN9紅外溫度傳感器的紅外測溫儀設計方案資料下載 71次下載
- 諧振式水晶溫度傳感器的現(xiàn)狀和發(fā)展預測
- 測溫智能儀表中溫度傳感器的選擇與使用
- 基于比色測溫的溫度場測量技術研究
- 選擇適合的紅外測溫儀,需要考慮哪些因素? 394次閱讀
- 熱電偶測溫,如何“一鍵”實現(xiàn)? 557次閱讀
- 【鉑電阻測溫】如何快速實現(xiàn)多通道熱電阻溫度采集 613次閱讀
- 芯片溫度測量方法和應用案例 1610次閱讀
- 元器件溫度預測的十大技巧 1212次閱讀
- 預測元器件溫度的10項提示—高級操作指南 1158次閱讀
- NTC熱敏電阻測溫的工作原理及程序設計 2.7w次閱讀
- 使用溫度測溫儀測量電烙鐵頭溫度的步驟分析 1.9w次閱讀
- 紅外溫度計原理_紅外溫度計使用方法 1.8w次閱讀
- 電力無線測溫之TN-TS4H有源無線溫度傳感器 2664次閱讀
- 基于PIC單片機控制溫度傳感器測溫的設計 3382次閱讀
- 電阻測溫原理是什么?單片機溫度計電路設計 1.2w次閱讀
- 一種高精度低成本測溫方案詳解 3874次閱讀
- 集成溫度傳感器測溫電路 3385次閱讀
- 硅溫度傳感器測溫電路 3585次閱讀
下載排行
本周
- 1山景DSP芯片AP8248A2數(shù)據(jù)手冊
- 1.06 MB | 532次下載 | 免費
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費
- 3TC358743XBG評估板參考手冊
- 1.36 MB | 330次下載 | 免費
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費
- 5元宇宙深度解析—未來的未來-風口還是泡沫
- 6.40 MB | 227次下載 | 免費
- 6迪文DGUS開發(fā)指南
- 31.67 MB | 194次下載 | 免費
- 7元宇宙底層硬件系列報告
- 13.42 MB | 182次下載 | 免費
- 8FP5207XR-G1中文應用手冊
- 1.09 MB | 178次下載 | 免費
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費
- 2555集成電路應用800例(新編版)
- 0.00 MB | 33566次下載 | 免費
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費
- 4開關電源設計實例指南
- 未知 | 21549次下載 | 免費
- 5電氣工程師手冊免費下載(新編第二版pdf電子書)
- 0.00 MB | 15349次下載 | 免費
- 6數(shù)字電路基礎pdf(下載)
- 未知 | 13750次下載 | 免費
- 7電子制作實例集錦 下載
- 未知 | 8113次下載 | 免費
- 8《LED驅動電路設計》 溫德爾著
- 0.00 MB | 6656次下載 | 免費
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費
- 2protel99se軟件下載(可英文版轉中文版)
- 78.1 MB | 537798次下載 | 免費
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費
- 6電路仿真軟件multisim 10.0免費下載
- 340992 | 191187次下載 | 免費
- 7十天學會AVR單片機與C語言視頻教程 下載
- 158M | 183279次下載 | 免費
- 8proe5.0野火版下載(中文版免費下載)
- 未知 | 138040次下載 | 免費
評論
查看更多