2019-12-30 10:07:50 [显示全部楼层]
1921浏览
查看: 1921|回复: 1

[项目] 远程查看家里门上的震动传感值

[复制链接]
快过年了。如果出去走亲戚,难免要离家几天。怎么知道家里如没有人进去过呢。这里提供一个低成本的IOT方案。

项目用到硬件如下:
远程查看家里门上的震动传感值图1
NodeMCU
远程查看家里门上的震动传感值图2
震动传感SW-420
远程查看家里门上的震动传感值图3
NodeMCU脚位图
远程查看家里门上的震动传感值图4
项目连线图
震动传感的D0连NodeMCU的A0

下面进行云平台的设置
首先进入thingspeak.com,选择它是因为它免费
远程查看家里门上的震动传感值图5
注册后,建立通道
远程查看家里门上的震动传感值图6
这里建立的是knock level通道
远程查看家里门上的震动传感值图7
通过敲击震动传感,传感值会实时上传到云平台,并以图表方式展示
远程查看家里门上的震动传感值图8
写api码是写入代码里的
读api码是在第三方手机app里调用的。
远程查看家里门上的震动传感值图9

然后是撸代码
远程查看家里门上的震动传感值图10
程序运行后的COM口数值

代码当中的
String apiKey = "";
const char *ssid = "";
const char *pass = "";

必须填你的真实数据,分别是api码,wifi名,wifi密码
[mw_shl_code=applescript,true]//---------gada888撸码-------2019-12----
#include <ESP8266WiFi.h>
String apiKey = "";
const char *ssid = "";
const char *pass = "";
const char* server = "api.thingspeak.com";
WiFiClient client;

//--------------------SETUP---------------
void setup(){
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

}
//--------------LOOP-----------------
void loop(){

float h = analogRead(A0);
if (client.connect(server, 80))
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(h/1023*100);
postStr += "r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Noise Level: ");
Serial.println(h/1023*100);
Serial.println("Data Send to Thingspeak");
}
client.stop();
Serial.println("Waiting...");

// thingspeak needs minimum 15 sec delay between updates.
delay(1500);

  }
[/mw_shl_code]

远程查看家里门上的震动传感值图11
查看IOT数值的话,可以从PC端登录thingspeak.com来查,也可以用app来查。时间关系,这次app还在调试中。


kylinpoet  初级技神

发表于 2020-2-18 16:35:56

楼主强大,多谢分享。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail