Funpack3-5——基于Arduino Cloud与Arduino UNO R4 WIFI的智能互联
该项目使用了ArduinoUNO R4 WIFI开发板、Arduino Cloud以及DHT11,实现了基于Arduino Cloud与ArduinoUNO R4 WIFI物联网的设计,它的主要功能为:LED矩阵灯的云端控制以及DHT11温湿度数据的云端显示。
标签
Funpack活动
DHT11
Arduino Cloud
ArduinoUNO R4 WIFI
慢即是快
更新2025-01-15
11

一.项目介绍

本项目依托Funpack3-5,基于Arduino UNO R4 WIFI开发板、DTH11传感器与Arduino Cloud平台,实现了LED矩阵灯的远程控制以及DTH11温湿度数据云上传与显示

项目任务:

1. 点灯!通过网络连接到Arduino Cloud智能云端,远程端发送指令,于0到90%时LED矩阵灯亮起的范围逐渐变大;于91%到99%时,LED灯全部点亮;100%时,灯板显示出太阳的图标。

2.接入DHT11传感器,并通过网络连接到智能云端,可以从远程获取传感器的温湿度信息。

二. 硬件介绍

1. Arduino UNO R4 WIFI

Arduino® UNO R4 WiFi是⾸款配备32位微控制器和ESP32-S3 Wi-Fi® 模块 (ESP32-S3-MINI-1-N8) UNO板。该开发板具有14个数字I/O端⼝,6个模拟通道,专⽤于 I2CSPI UART 连接的引脚。它具有更⼤的内存:闪存(256kBSRAM32 kB。它的时钟速度为48MHz。此外,它还具有ESP32-S3模块,⽤于Wi-Fi®Bluetooth®连接,以及内置的 12x8 LED 矩阵,使其成为迄今为⽌最具视觉效果的 Arduino 开发板之⼀。LED 矩阵是完全可编程的,支持加载从静态帧到⾃定义动画的任何内容。

2.DHT11

DHT传感器由两部分组成,电容式湿度传感器和热敏电阻。内部还有一个非常基本的芯片,可以进行一些模数转换,并输出带有温度和湿度的数字信号。使用任何微控制器都很容易读取数字信号。DHT11特性如下:

  • 超级成本
  • 3至5V电源
  • 适用于20-80%的湿度读数,精度为5%
  • 适用于0-50°C温度读数±2°C精度
  • 采样率不超过1 Hz(每秒一次)

参考链接:

https://cdn-learn.adafruit.com/downloads/pdf/dht.pdf

三.功能介绍

1.登录Arduino Cloud,将窗口切换至Dashboard窗口,如下图所示。

2.使用9V电池给UNO WIFI开发板供电,将DHT11连接至开发板(VCC->5V GND->GND DAT->D2),拔掉开发板OFF GND跳线帽完成开发板上电,等待开发板与Cloud平台网络连接,如下图所示。

3.网络连接成功后,调整Matrix LED部件值为8时,LED矩阵灯第一列亮起,如下图所示。

调整Matrix LED部件值为56时,LED矩阵灯六列亮起,如下图所示。

调整Matrix LED部件值为92时,LED矩阵灯全部亮起,如下图所示。

调整Matrix LED部件值为100时,LED矩阵灯显示太阳图案,如下图所示。

将DHT11传感器放置在热水杯附近,温湿度数据如下图所示。

四.主要代码

DHT11代码:DHT11.h

#ifndef _DHT11_H_
#define _DHT11_H_

#include <DHT.h>

#define DHTPIN 2 // Define the pin used to connect the sensor
#define DHTTYPE DHT11 // Define the sensor type

DHT dht(DHTPIN, DHTTYPE); // Create a DHT object


void DHT11Init();
void GetDataFromBMP280();

//DHT11初始化​
void DHT11Init()
{
dht.begin();
}

//获取温湿度数据​
void GetDataFromDHT11()
{
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).

if (isnan(humidity) || isnan(temperature)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Temperature = "));
Serial.print(temperature);
Serial.println(" °C");
}
#endif

LED矩阵灯控制代码:MatrixLEDControl.h

#ifndef _MATRIXLEDCONTROL_

#define _MATRIXLEDCONTROL_
#include <Arduino_LED_Matrix.h>

ArduinoLEDMatrix matrix; // Create a ArduinoLEDMatrix object
//8x12LED初始值
byte frame[8][12] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
//根据数值显示LED矩阵​列
void DisplayMartrxLED();
//显示太阳图案​
void DisplaySun();
//turn off all LEDs​
void ClearMarixLED();
//​turn on all LEDs​
void MatrixLEDOn();
//初始化LED矩阵,turn off all LEDS
void MatrixInit();

void DisplayMartrxLED()
{
// Serial.println(lED_MATRIX);
if(lED_MATRIX == 0)
{
Serial.println("lED_MATRIX == 0");
ClearMarixLED();
}
else if(lED_MATRIX > 0 && lED_MATRIX <= 90)
{
// Serial.println("lED_MATRIX > 0 && lED_MATRIX <= 90");
for(int i = 0; i < 8; i++)
for(int j = 0; j < 12; j++)
{
if(j <= lED_MATRIX / 10)
{
frame[i][j] = 1;
}
else
{
frame[i][j] = 0;
}
}
}
else if (lED_MATRIX > 90 && lED_MATRIX < 100)
{
MatrixLEDOn();
}
else
{
// Serial.println("lED_MATRIX == 100");
DisplaySun();
}
matrix.renderBitmap(frame, 8, 12);
}

void DisplaySun()
{
ClearMarixLED();
frame[0][4] = 1;
frame[0][5] = 1;
frame[0][6] = 1;
frame[1][3] = 1;
frame[1][7] = 1;
frame[2][2] = 1;
frame[2][8] = 1;
frame[3][2] = 1;
frame[3][8] = 1;
frame[4][2] = 1;
frame[4][8] = 1;
frame[5][3] = 1;
frame[5][7] = 1;
frame[6][4] = 1;
frame[6][5] = 1;
frame[6][6] = 1;
frame[0][0] = 1;
frame[0][10] = 1;
frame[1][1] = 1;
frame[1][9] = 1;
frame[6][1] = 1;
frame[6][9] = 1;
frame[7][0] = 1;
frame[7][10] = 1;
}

void ClearMarixLED()
{
for(int i = 0; i < 8; i++)
for(int j = 0; j < 12; j++)
{
frame[i][j] = 0;
}
}

void MatrixLEDOn()
{
for(int i = 0; i < 8; i++)
for(int j = 0; j < 12; j++)
{
frame[i][j] = 1;
}
}

void MatrixInit()
{
matrix.begin();
matrix.renderBitmap(frame, 8, 12);
}
#endif

主程序代码:LEDMatrix.info

/* 
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/5516dc2a-3a91-49d0-820c-336d717aa5e1
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing

float humidity;
float temperature;
int lED_MATRIX;

Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "MatrixLEDControl.h"
#include "DHT11.h"

void setup() {
// Turn off matrix led
MatrixInit();
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Initialize the DHT sensor
DHT11Init();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
// Your code here
GetDataFromDHT11();
}
/*
Since LEDMATRIX is READ_WRITE variable, onLEDMATRIXChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLEDMATRIXChange() {
// Add your code here to act upon LEDMATRIX change
DisplayMartrxLED();
}

遇到问题及总结

网络连接超时:查看所连接网络频段,UNO WIFI只支持2.4GHz,若连接的网络是5GHz,则网络将连接失败。

五.活动总结与未来计划

通过对本项目的实践,我对UNO WIFI、Arduino Cloud、物联网有了深入的认识,期待能够再次参加活动,了解并学习更多的关于嵌入式、物联网等方面的知识,掌握更多的技能,提高自己的动手实践的能力

附件下载
Matrix_LED_Display_nov26a.zip
团队介绍
电子设计爱好者
评论
0 / 100
查看更多
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2024 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号