亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Manufacturing Technology >> 制造工艺

MyRiver

组件和用品

Arduino MKR1000
× 1
水位传感器
× 1
Ph 传感器
× 1
LED(通用)
如果可能,白色
× 1
电阻 221 ohm
× 2
光敏电阻
× 1
跳线(通用)
× 1

必要的工具和机器

烙铁(通用)
钢锯

应用和在线服务

Arduino 网页编辑器
Sigfox
Wia

关于这个项目

概览

河流或湖泊可以成为乐趣和放松的重要来源。但如果河流变得肮脏和污染,所有的乐趣都消失了。许多人依靠河水养活牲畜,无法给牲畜提供脏水。

想象一下,住在河边(如果不是的话),你不会想半夜醒来,房子被河水淹了。或者,如果您的邻居决定向河中倾倒一些汽油,您不会希望您的动物生病。

MyRiver 解决了所有这些问题,由于 Sigfox,它可以在孤立的区域运行,这样每个人都可以访问该设备。该设备将使用创新方法读取水的 pH 值、污染程度和水位。借助 Wia,您可以随时随地在手机或计算机上实时监控河流。通过这种方式,您可以知道流是否存在问题,并允许您在为时已晚之前采取行动。如果河流有问题,它会立即通知您。

视频

图片

功能

该设备基于Arduino MKR FOX,专为远程使用而设计,用户可以将设备放置在河流或湖泊中,随时随地进行监控。由于 SAM D 的低功耗模式,该设备可以使用 2AA 电池长时间工作。

设备每 30 分钟读取一次读数,之后进入睡眠状态,睡眠时间可以重置,但最短睡眠时间必须为 20 分钟。

MKR FOX 使用 pH 传感器读取河流的 pH 值,它还使用水位传感器获取水位,并通过在光敏电阻上照射 LED 来检测它是否被不溶性物质污染,如果光敏电阻读数为低,这意味着河流中存在固体物质(油、汽油、汞等)。然后该设备将所有数据发送到 Sigfox,在那里它被中继到 Wia,进行处理和可视化。用户会收到有关河流状况的通知。下面是功能概述的图像。

缓冲区将被发送到 Sigfox 编码为 HEX,Sigfox 将数据中继到 Wia,然后数据将通过一个流,数据将转换回字符串,然后转换为传感器值。然后将处理它们,如果值超出范围,将通知用户。

下面是另一个说明项目代码概述的图像,如下所述。

  • 读取传感器 将读取 pH 值、水位和光敏电阻传感器值并将它们存储在变量中。
  • 格式化缓冲区 将所有值合并到可以发送到 Sigfox 的 12 字节缓冲区中。
  • 解析数据 将缓冲区解析为 Sigfox。

MKR FOX 只能通过 Sigfox 发送 12 个字节,这意味着所有传感器值必须合并到 12 个字节中,每个传感器的最大原始值是 1024(因为它们都是模拟的),所以每个传感器代表三分之一缓冲区(4 个字节)。 Arduino 必须合并这些值并在每个值的开头添加零,直到该值有 4 个字节。下图说明了这个过程。

Arduino 以整数形式接收传感器值,然后将整数转换为字符串,并在每个值的开头添加零,直到它有 4 个字节,例如,如果光敏电阻值为 620,则会添加一个零, 0 620.但如果水位传感器等于24,则加两个零,00 24. 然后设备将这些值合并到一个 12 字节的缓冲区中,并将数据发送到 SigFox。

运行中的设备

下面是一些展示项目功能的照片,为了更好地查看它们,请参阅上面的视频。

好处

用户 运营 这个 项目 好处 在:

  • 随时随地轻松监测河流的水位、酸碱度和污染水平
  • 在河流被可溶性或不溶性物质污染或洪水泛滥时收到通知
  • 易于使用和安装
  • 在任何 Sigfox 覆盖的国家/地区工作

建设项目

第 1 步:所需设备

这个项目需要将所有组件焊接在一起,除了传感器没有太多东西。材料清单如下。

  • 1、Arduino MKR FOX 1200
  • 1、pH 传感器
  • 1、水位传感器
  • 1、光敏电阻
  • 1、白光 LED
  • 2、电阻(220Ω)
  • 跳线

第 2 步:连接电路

该项目的电路图可能会有点混乱,因为组件没有放置在面包板上,如果您有任何困难,请尝试下载下面的 Fritzing 文件并在您的计算机上移动电线。

  • 电路概览

下图将说明电路完成后的外观。

  • 准备 MKR 福克斯

下图将指导您将电池盒和天线连接到 MKR FOX,注意必须在连接传感器后连接电池盒。其他接线和设置位于constructing the project / Final。

第 3 步:确认代码

代码有3个主要部分:

  • 读取传感器
  • 格式化缓冲区
  • 解析数据

这些部分解释如下。

  • 读取传感器
struct GetValue // 创建结构以缓和循环{ int riverLevel() // 获取河流的水位 { const int val =analogRead(A2);如果(proDebug){ Serial.print(“河流级别”); Serial.println(val); } 返回值; } int riverPh() // 获取河流的 ph { const int val =(analogRead(A1) / 5 * 3.3); if(proDebug) { Serial.print(" River Ph "); Serial.println(val); } 返回值; } int riverPol() // 获取河流的污染程度 { const int val =analogRead(A3); if(proDebug) { Serial.print("河流污染"); Serial.println(val); } 返回值; }}; 

上面的结构包含读取每个传感器值的循环,每个值都有一个单独的循环。

  • 格式化缓冲区
String data(int level, int ph, int pol) // 将传感器值合并到缓冲区 { int values[3] ={level, ph, pol};字符串新值; for(int i =0; i <3; i++) // 将遍历所有值,在开始处添加 0 { if(values[i] <10) { newValues +="000"; Serial.println("选项1"); } else if(values[i] <100) { newValues +="00"; Serial.println("选项2"); } else if(values[i] <1000) { newValues +="0"; Serial.println("选项3"); } 别的 {}; newValues +=values[i]; Serial.print("运行"); Serial.print(i); Serial.print("/3"); Serial.println(newValues);返回新值; }  

上面的循环接收 3 个传感器值,然后将它们放入一个数组中。然后循环遍历每个值,在每个值的开头添加零,直到值的大小为 4 个字节,然后将每个值添加到一个字符串中,然后返回。

  • 解析数据
void parseData(String data) // 发送缓冲区到 SigFox { SigFox.beginPacket(); SigFox.print(数据); int ret =SigFox.endPacket(); } 

此部分接收要解析的字符串,然后将值发送给 Sigfox。

第 4 步:设置 Wia Sigfox 集成

这一步将说明如何设置 Wia 以接收来自 Sigfox 的消息,Wia 是一个专业的物联网平台,允许用户使用 web 或移动应用程序上的小部件来可视化数据,它还允许用户创建一个名为的块代码一个流,它允许用户处理数据。数据由一个事件表示。

首先,请确保您拥有 Sigfox 帐户和 Wia 帐户。还可以在 iOS 或 Android 上下载 Wia 应用程序,以便您接收通知。下面的图片将说明连接 Sigfox 和 Wia。

  • 设置类型 数据上行
  • 设置频道URL
  • 无需填写Custom Payload Configuration
  • 设置网址 模式为“https://api.wia.io/v1/events”
  • 设置HTTPMethod POST
  • 创建一个名为 Authorisation 的标头 值 Bearer (此值稍后将被编辑)
  • 设置ContentTypeapplication/json
  • 将此链接中的代码复制到网络钩子的正文中。
  • 最后,单击“确定”即可完成。

第 5 步:设置 Wia 流程

这部分需要更长的时间来完成,流程将从 HEX 接收到的数据转换为字符串,然后将字符串解析为 3 个传感器值,然后将它们转换为整数,然后将转换为河流污染值和将河流水位转换为 High 或 Ok 描述符,将原始 ph 值转换为实际 ph 值,然后如果该值超出范围,它将通知用户。

下面的指南将逐步说明此过程。您将被指示在 Wia Functions 中插入某些代码段,这些代码段插入在下面,只需将代码复制并粘贴到函数中即可。要包含在电子邮件中的数据也插入下面,像使用函数一样使用它们。

Wia 函数

  • processPayload
if(input.body){ output.body.name ="value"; output.body.data =toByteArrayStr(input.body.data.sigfoxData);}function toByteArrayStr(sigfoxData){ let result =Buffer(sigfoxData, 'hex'); return result.toString('utf8');} 
  • 过程污染
if(input.body.data){ let data =input.body.data; if(data =="POLLUTED") { output.body.name ="waterLevel"; output.body.data =数据; } else { while(1); }} 
  • processPh
let minVal =6.5;let maxVal =8.5;if(input.body.data){ let data =input.body.data; if(data> maxVal || data  
  • 流程级别
if(input.body.data){ let data =input.body.data; if(data =="HIGH") { output.body.name ="waterLevel"; output.body.data =数据; } else { while(1); }} 
  • 河流污染
let minVal =200;let maxVal =0;if(input.body.data.sigfoxData){ let data =input.body.data.sigfoxData;让处理数据 =toByteArrayStr(data);让 newData =cutString(processedData); output.body.name ="水污染"; output.body.data =processData(newData);}function toByteArrayStr(sigfoxData){ let result =Buffer(sigfoxData, 'hex'); return result.toString('utf8');}function cutString(data){ let newVal =data[8]; newVal +=数据[9]; newVal +=数据[10]; newVal +=数据[11];让 finalVal =parseInt(newVal); return finalVal;}function processData(data){ if(data  
  • riverPh
let minVal =300;let maxVal =600;if(input.body.data.sigfoxData){ let data =input.body.data.sigfoxData;让处理数据 =toByteArrayStr(data);让 newData =cutString(processedData);让 finalVal =(newData / 73.1428571);让 valueToSend =finalVal.toFixed(2); output.body.name ="waterPh"; output.body.data =valueToSend;}function toByteArrayStr(sigfoxData){ let result =Buffer(sigfoxData, 'hex'); return result.toString('utf8');}function cutString(data){ let newVal =data[4]; newVal +=数据[5]; newVal +=数据[6]; newVal +=数据[7];让 finalVal =parseInt(newVal); return newVal;} 
  • riverLevel
let minVal =0;let maxVal =200;if(input.body.data.sigfoxData){ let data =input.body.data.sigfoxData;让处理数据 =toByteArrayStr(data);让 newData =cutString(processedData); output.body.name ="水位"; output.body.data =processData(newData);}function cutString(data){ let newVal =data[0]; newVal +=数据[1]; newVal +=数据[2]; newVal +=数据[3];让 finalVal =parseInt(newVal); return finalVal;}function toByteArrayStr(sigfoxData){ let result =Buffer(sigfoxData, 'hex'); return result.toString('utf8');}function processData(data){ if(data> maxVal) { return "HIGH"; } else { 返回“确定”; }} 

Wia 电子邮件

  • riverPollutionEmail
Automatic Messaging SystemDataWarning - myWater 设备 ${trigger.source.device.id} 在流中检测到问题。警告 - 水被不溶性物质污染.InformationDevice ${trigger.source.device.id}Raw数据 ${input.body.data} 
  • riverPhEmail
Automatic Messaging SystemDataWarning - myWater 设备 ${trigger.source.device.id} 在流中检测到问题。警告 - Water Ph 不合适。水被污染了。InformationDevice ${trigger.source.device.id}Raw Data ${input.body.data} 
  • riverLevelEmail
Automatic Messaging SystemDataWarning - myWater 设备 ${trigger.source.device.id} 在流中检测到问题。警告 - 水位太高,河流可能泛滥。InformationDevice ${trigger.source.device .id}原始数据 ${input.body.data} 

设置变量

Wia 接收到数据后,必须对其进行处理,如果数据在最小值和最大值之间,则该值是安全的,pH 和水位传感器的限值已设置,但用户必须手动设置光敏电阻的限制,必须进行测试以确定此值,以下步骤将指导您如何执行此操作。

void setup(){ pinMode(1, OUTPUT); Serial.begin(9600); while(!Serial) {}; digitalWrite(1, HIGH);} void loop(){ const int val =analogRead(A3); Serial.println(val);延迟(5000);} 

用户必须设置另一个变量,proDebug , 如果启用,Arduino 需要通过 USB 连接到计算机,并且必须打开 Serial Monitor,该模式下 Arduino 打印到 Serial Monitor,非常适合故障排除。 proDebug 默认为 false 用于现场操作。

图书馆

  • Sigfox - 版权所有 (c) 2016 Arduino LLC GNU 宽松通用公共许可证,该库属于公共领域
  • ArduinoLowPower (c) 2016 Arduino LLC GNU 宽松通用公共许可证,此库在公共领域

决赛

最后一步是将您的Arduino连接到PC/Mac并上传草图,确保电池盒连接到Arduino并且电路正常。接下来的步骤将指导您为项目制作围栏。

我决定用一瓶水制作我的围栏,我认为这是一种很好的生态方式来拥抱这个项目。设备如下图所示。

如果您喜欢围栏的想法,您可以滚动浏览下面的图片,说明围栏是如何制作的,您可以自己制作。

The last thing to do is place the device in the river. To do this, go to the river you wish to implement MyRiver on during High Tide , this is essential to ensure that the device is not alerting that the river is flooding when it is actually just the tide.

Place some tape on the top of the water bottle to prevent water from seeping into the bottle and destroying everything.

We went to a local, dirty river to test the project out, all the alarms went off correctly.

When placing the probe in the water, ensure that the water is at the bottom of the water level sensor but is covering the photoresistor entirely. Secure the project to the shore using tape or a hammer and screws, and it should look like this (or better).

Background

Relaxing in your house, looking out the window at the once beautiful and delightful river rushing in front of you. But instead of the beautiful fresh river, you see a green slimy one, you might want to move house in that case.

And if the river decides to flood into your house in the middle of the night while you are sleeping, you will certainly decide to move.

I thought of these problems and how to solve them all in one device, and I came up with MyRiver.

If you are in the city and living beside a river, it will warn you in time if the river decides to ruin your day in any way or if your neighbour is dumping oil in the river. Or if you are on a farm, MyRiver will warn you that the river is dirty before you give the water to your animals, and will give you time to bring the animals in before the river floods.

But just reading the pH of the river was not enough, as insoluble substances like mercury or other metals do not effect the Ph of the water. So we came up with a new method to detect those substances, unique to this project, a photoresistor reading the amount of light from an LED penetrating the water. This way any water impurity can be detected.

代码

MyRiver
The Full Code

示意图

schematics_lXO5SiusZO.fzz

制造工艺

  1. 什么是 O2 传感器?
  2. Raspberry Pi 温度传感器
  3. 情绪传感器/脑电图
  4. 带模拟传感器的压力气流测量设备
  5. 带 LED 和压电扬声器的 DHT11 传感器
  6. UnifiedWater v1
  7. 3D RGB Arduclock
  8. 带有 Arduino 的简单障碍物传感器
  9. 摇杆游戏
  10. 找到我
  11. 小流浪者
  12. Arduino Joystick