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

如何使用 PHP 创建一个与 Arduino 通信的网站

组件和用品

Arduino UNO
× 1
Arduino Ethernet Shield 2
× 1
DHT11 温湿度传感器(4 针)
× 1
2 Way Relay
× 4
迷你面包板
× 1
火焰传感器
× 1
MQ4 气体传感器
× 1
LDR
× 1
湿度计传感器
× 3
ADSL 路由器电缆
× 1
插入(一种方式)
× 7
套接字(一种方式)
× 7
9V 电池
× 1
9V 电池桶电缆
× 1

必要的工具和机器

热胶枪(通用)

应用和在线服务

Apache HTTP 服务器
Notepad++
Arduino IDE

关于这个项目

更新

如何使用 TheAmplituhedron.com 改进物联网项目?是我为您处理服务器端编程的新项目。通过使用 TheAmplituhedron.com 作为主机,您可以轻松地通过 Internet 发送和获取数据包。

为了支持我的项目和文章,你可以在这里访问我的网站:)

说明

创建一个专业的网站来控制我家中的水族馆和灌溉系统

在我不在家时接收有关房屋的信息是该项目的主要方面。

为了实现这个目标,我创建了 Arduinautomotion 项目,其中包括 4 个不同的 HTML 页面(Arduinautomotion.php、Arduinautomotioncontrol.php、Arduinautomotionformvalue.php、Arduinautomotioncommunication.php 在我的 Apache 本地主机中。

此外,Arduino Ethernet Shield 托管另一个 HTML 网页 (ArduinoSide.php),可以使用所选的 IP 地址访问该网页,以与 Arduinautomotion 网站进行通信。

我想过这个项目,因为我不得不休假2周,因此我无法对我的水族馆进行调整。有时我需要关闭内部过滤器以避免水族箱中的氧气含量增加,或者我需要打开我的喂食器远程喂鱼。我添加了六个选项来控制我的水族馆的内容和一个选项来激活灌溉系统。

此外,您可以通过Arduino Ethernet Shield使用Arduinautomotion轻松获取有关家庭的数据(例如温度和湿度值来自DHT11 Sensor或家中的甲烷气体值来自MQ4 Sensor)。

因此,Arduinautomotion 网站有一个简单的界面,可以从 Arduino 获取和发送有关家庭的数据。

理解整个项目的内容需要 HTML、CSS、JavaScript、PHP 和 jQuery 语言的知识,因此这只是项目的展示,但如果您了解这些语言,则可以找到项目包含的所有网页,如PHP代码文件如下。

注意:我使用 Notepad++ 来编写网页。

如何在两个PHP网页之间发送和获取数据

我使用 HTML 表单、PHP 方法和 PHP $_SESSION [""] 在网页之间获取和发送数据。 Get Method 比 Post Method 更容易用于通信,但 Post Method 比 Get Method 更安全,因此我使用 Post Method 在除 ArduinoSide 网页之外的网页之间进行通信。但是,Get Method 是与 Arduino Ethernet Shield 通信的最简单方法,因为 HTTP GET 请求比 Post Request 容易得多,所以我在 ArduinoSide 网页上使用了 Get Method。另外,PHP $_SESSION[""] 是在两个以上网页之间永久保存数据的方式。

https://www.w3schools.com/php/php_forms.asp

https://www.w3schools.com/php/php_sessions.asp

如何在 Apache HTTP 服务器(本地主机)上设置网站

Apache HTTP Server 对于这种托管非常有效,但您可以选择 XAMPP 或其他托管服务器来代替它。就我而言,AppServ>> www>> Arduinautomotion.php 及其内容。我使用自己的 IP 地址(“192.168.1.20”指的是本地主机)来访问网页,但您必须使用您的 IP 地址(如 http://yourIPAddress/Arduinautomotion.php)。

http://editrocket.com/articles/php_apache_windows.html

Arduinautomotion.php 在下面的自定义部分添加的所有内容。

如何从 Android 设备连接到您的本地主机

对于这项工作,Windows 与 MAC 不同,但下面的链接可能对 Windows 有所帮助。

https://stackoverflow.com/questions/4779963/how-can-i-access-my-localhost-from-my-android-device

之后,在同一个 Wİ-Fİ 网络中,您可以使用自己的 IP 地址轻松访问 Arduinautomotion.php。

如何通过 Wi-Fi 访问您的本地主机

对于这项工作,Windows 与 MAC 不同,但下面的链接可能对 Windows 有所帮助。

它适用于您的外部 IP 地址,但您确定只有您知道外部 IP 地址,因为它可能是危险的托管方式。

https://stackoverflow.com/questions/5524116/accessing-localhost-xampp-from-another-computer-over-lan-network-how-to

此外,您必须使用端口转发来访问 ArduinoSide.php,它可以与您在下面的 ArduinoSide 代码中选择的 IP 地址配合使用。

https://en.wikipedia.org/index.php?q=aHR0cHM6Ly9lbi53aWtpcGVkaWEub3JnL3dpa2kvUG9ydF9mb3J3YXJkaW5n

Arduinautomotion.php

它是与 Arduino Ethernet Shield 通信的主页,您可以从该页面向 Arduino 发出命令,并轻松从 Arduino 获取有关家庭的数据。

更改菜单解释了变化的情况,并通过更改部件的颜色来显示哪个部件是物体,哪个部件是传感器。

通过不断变化的圆圈,它显示了传感器的值和对象的情况。

1) 房间部分

所有来自 Arduinautomotioncommunication.php 的房间数据都将显示在房间部分。

之前:

之后:

2 )水族馆

您选择的有关水族箱部件与 HTML 表单的任何组合都将发送到 Arduinautomotionformvalue.php,之后它将作为输出从 Arduinautomotioncontrol.php 返回到 Arduinautomotion.php。

之前:

之后:

3) 植物部分

可以观察湿度计传感器的值,并可以通过这些值考虑启动灌溉系统。作为水族馆部分,数据将作为输出从 Arduinautomotioncontrol.php 返回到 Arduinautomotion.php。

之前:

之后:

4) 指南部分

它包含 Arduinautomotionformvalue.php 网页以再次观察表单的选择。此外,它还包括一些项目说明和一张说明沟通过程的图片。

5 )警报框

无论哪个值在危险范围内,当重新加载 Arduinautomotion.php 网页时,都会出现一个包含蜘蛛侠视频文件和音频文件(“蜘蛛侠感觉刺痛”)的警报框。

6) Arduinautomotion.php 的部分

重新调整大小的网站作为指南:

整个变化的圈子:

页脚:

Arduinautomotioncontrol.php

它嵌入在 Arduinautomotion.php 网页中,以从 Arduinautomotionformvalue.php 和 Arduinautomotioncommunication.php 获取所有数据为 $_SESSION [" "]。

它通过 PHP 页面永久保存数据。

Arduinautomotionformvalue.php

它从 Arduinautomotion.php 获取表单的选择,并将它们发送到 ArduinoSide 和 Arduinautomotioncontrol.php。它嵌入在 Arduinautomotion.php 网页的指南部分,但也可以通过新选项卡访问。

Arduinautomotioncommunication.php

来自ArduinoSide的数据由Arduinautomotioncommunication.php保存后自动发送到Arduinautomotioncontrol.php。

ArduinoSide

它由 Arduino Ethernet Shield 通过 DNS 托管,您可以使用您在下面的 ArduinoSide 代码中选择的 IP 地址(如 https://yourChosenIPAddress )访问它。

连接

只需按照 ArduinoSide 代码和下面的 Fritzing 图片中的说明进行连接。将单向插头和插座连接到 2 向继电器,并将所有组件粘贴到一块平面上,例如软木板。

阿杜诺

DHT11模块

引脚 2 -------------------------

2路继电器(1)

引脚 3 -------------------------

引脚 4 -------------------------

2路继电器(2)

引脚 5 -------------------------

引脚 6 -------------------------

二路继电器 (3)

引脚 7 -------------------------

引脚 8 -------------------------

二路继电器 (4)

引脚 9 -------------------------

阿杜诺以太网盾

引脚 10 --------------------------

引脚 11 --------------------------

引脚 12 --------------------------

引脚 13 --------------------------

LDR

奥 --------------------------

火焰传感器

A1 --------------------------

MQ4传感器

A2 --------------------------

湿度计模块(一)

A3 --------------------------

湿度计模块 (2)

A4 --------------------------

湿度计模块 (3)

A5 --------------------------

Arduino 代码基本上类似于以太网库示例文件夹中的 WebServer 代码。

我只添加了一些代码来控制传感器和运行来自 Arduinautomotion 网站的命令。

并将 ADSL 电缆从 Arduino 以太网扩展板连接到路由器。

运行 Arduino 代码后,Arduinautomotion 网站通过 LAN 通过 Wİ-Fİ 从 Arduino 发送和获取数据。

测试视频

我测试了这个项目,然后将它与我的水族馆和灌溉系统(它基本上是一个水马达)连接起来,该项目效果很好。 :) 这是 Arduinautoumotion 项目的测试视频。我用Filmora的试用版编辑了它,出于尊重他们的工作,我没有去除水印。

计算机:

安卓:

代码

  • Arduinautomotion.php
  • Arduinautomotioncontrol.php
  • Arduinautomotionformvalue.php
  • Arduinautomotioncommunication.php
  • ArduinoSide_Code.ino
Arduinautomotion.phpPHP

Guidelines for managing to adjustments of the objects.

Please click the buttons and th e color bars to learn the info about colors.

ROOM

AQUARUM

PLANT

GUDE
Open FormValue In New Tab
  • When a form is sent to the FormValue page, form values are revealed in the iframe which named newsite in Guide.

  • Form values are the saved data which give Arduino an ability to determine the adjustments of the aquarium and the plants.

  • And all of the data go through the ArduinoSide page that is hosted by Arduino Ethernet Shield with the IP address you choose.

  • After that, the Communication button in the ArduinoSide page has to be pushed to open the Communication page and to change the $_Session values.

  • Lastly, the Arduinautomotion page has to refresh or the Reload button has to pushed to get the new data from Arduino.

  • If the information about the room is in the dangerous range, the homepage notifies you with a voice alert box which includes a Spider-man video and audio file that are in the www folder in Apache localhost furthermore the related information circle changes its colour to red.

PLANT
AQUARUM
...This file has been truncated, please download it to see its full contents.
Arduinautomotioncontrol.phpPHP
Arduinautomotion
Arduinautomotionformvalue.phpPHP
FormValue

Server has received the data from Arduinautomotion.

Airpump=


Lamp=


Feeding=


Heater=


Filterex=


Filterin=


Irrigation=


Arduinautomotioncommunication.phpPHP
Communication