|
在极客工坊淘宝店买了arduino套装,最近又在arduino city拿到了W5100网络模块,周日研究了一上午,arduino+W5100也没有搞通,下午在乐联网老刘,和乐联网技术支持群里的Jak和疯子的指导下,终于搞清楚了W5100上传乐联网传感器数据,并成功建立了家庭监测系统,虽然还只是传上去一个LM35温度,但已经感受到了群里面众兄弟的热情支持和帮助。先发个题目,实验内容及图片随后附上。大家可以先看一下我的监测系统的门户首页。http://www.lewei50.com/home/gatewaystatus/855
经过几天的琢磨以及各位高人指点下,成功实现了DHT11湿度、温度、DSM501A颗粒物传感器连接与数据上传。在此要特别感谢物联网老刘无偿提供的DMS501A颗粒物传感器和不厌其烦的指点。
所需的库文件附上:
代码如下: - #include <SPI.h>
- #include <Ethernet.h>
- // #include <Arduino.h>
- #include <dsm501.h>
- #include <LeweiClient.h>
- #define LW_USERKEY "6f7ce35ca209470c95fc8d9d2f513ce4"
- #define LW_GATEWAY "01"
- dsm501 pm25Sensor;
- #include <dht11.h>
- dht11 DHT11;
- #define DHT11PIN 2
-
-
- //#define MY_NAME "UNO1"
- //#define MY_DESC "virtual gate"
- //char my_addr[50]="http://192.168.1.233/api";
- //int port =80;
- LeWeiClient *lwc;
- // unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
- //boolean lastConnected = false; // state of the connection last time through the main loop
- //const unsigned long postingInterval = 30*1000; //delay between updates to cosm.com
- // unsigned long duration;
- unsigned long starttime;
- //LM35
- //int potPin = 0; //设置模拟口0为LM35的信号输入端口
- //float temperature = 0; //设置temperature为浮点变量 //设置val为长整数变量
- //long val=0; //定义变量来存储读取的数值
- void setup() {
- pm25Sensor.setDatapin(8); //设置DSM501数据引脚
- // start serial port:
- // Serial.begin(9600);
- lwc = new LeWeiClient(LW_USERKEY, LW_GATEWAY);
- starttime = millis();
- }
- void loop() {
- //LM35
- // val=analogRead(potPin); //温度传感器LM35接到模拟PIN0上;val变量为从LM35信号口读取到的数值
- // temperature = (val*5.0/1023.0*100);//把读取到的val转换为温度数值,系数一:0.00488125=5/1024,0~5V对应模拟口读数1~1024,
- //系数二:100=1000/10,1000是毫伏与伏的转换;10是每10毫伏对应一度温升。
-
- //DSM501A
- //Serial.print("particle concentration: ");
- //如果数据需要滤波
- //pm25Sensor.enableFilter();
- int p=0;
- p=pm25Sensor.getParticles();
- //Serial.println(p); //取得颗粒物浓度
- //DHT11
- int chk = DHT11.read(DHT11PIN);
- float h = DHT11.humidity;
- float t = DHT11.temperature;
- // Serial.print("Humidity (%): ");
- //Serial.println((float)DHT11.humidity, 2);
- //Serial.print("Temperature (oC): ");
- //Serial.println((float)DHT11.temperature, 2);
- // Serial.print("Tep= ");
- // Serial.print(temperature);
- // Serial.println(" C");
-
- lwc->append("TEMP", t);
- lwc->append("HM", h);
- lwc->append("PM1", p);
- lwc->send();
- delay(10000);//延时10秒,这里也就是刷新速度。
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|