0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何将此ESP32 LORA模块用作发送方和接收方

454398 来源:网络整理 作者:网络整理 2019-11-14 17:14 次阅读

步骤1:操作(数据传输)

这是装配体工作原理图。

步骤2:使用的资源

2 ESP32 LORA OLED显示屏

1 Arduino Nano ATmega328

1 Arduino以太网模块ENC28J60

1气体传感器模块MQ2

1湿度和温度传感器DHT22( AM2302)

2330欧姆电阻

1 4k7欧姆电阻

1蜂鸣器5V

1个绿色LED

1红色LED

跳线

步骤3:功能-发送方

1 ESP32 LORA Display

1气体传感器模块MQ2

1湿度和温度传感器DHT22(AM2302)

1个4k7欧姆电阻器

跳线

第4步:使用的功能-接收器

1个ESP32 LORA OLED显示屏

1个Arduino Nano ATmega328

1个用于Arduino的以太网模块ENC28J60

2330 ohm r电阻器

1个蜂鸣器5V

1个绿色LED

1个红色LED

跳线

步骤5:MQ-2气体传感器灵敏度

传感器的电阻(Rs/Ro)根据现有的气体浓度(ppm)更高或更低。此浓度可以通过引脚A0的输出来显示。

MQ-2气体传感器对气体具有高灵敏度:

•LPG(液化石油气);

•丙烷(C3H8);

•氢气(H2);

•甲烷(CH4);

•燃料气体,例如丙烷, CO,酒精和丁烷(用于打火机)。

步骤6:发送器安装--- Pinout ESP32 LORA OLED

步骤7 :发送器电路

步骤8:发送器安装

步骤9:安装接收器---引脚排列Arduino Nano ATmega328

步骤10:接收器电路

步骤11:接收器安装

绿色LED指示Arduino已连接到以太网客户端。

红色LED指示已发送SMS。

发送SMS时,Arduino已断开连接,因此不再发送任何消息。

步骤12:DHT库安装

1。转到草图-》包含库-》库管理器。

2。搜索SimpleDHT,然后单击“安装”。

步骤13:发件人-代码的组织

设置 》

循环

-readDhtSensor:负责读取传感器和获取温度和湿度值。

-gasDetected:负责读取传感器并验证是否已检测到气体的功能。

-sendPacket:负责通过LORA发送包裹的功能

-showDisplay:负责显示在显示屏上获得的消息和值的功能。

步骤14:发件人代码[包含和定义]

首先,我们将包含定义引脚的库。

#include //serial peripheral interface (SPI) library

#include //wifi lora library

#include //communication i2c library

#include “SSD1306.h” //display communication library

#include //dht communication library

//Descomment the line below which dht sensor type are you using

//#define DHTTYPE DHT11 // DHT 11

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

我们将处理

// DHT Sensor

const int DHTPin = 23;

int analog_value; //variable used to receive the analog signal from sensor (from 100 to 10000)

int dig_value; //variable used to receive the digital signal from sensor

int gas_limit = 0; //used to indicates the minimum value to active the gas sensor (that value changes as the sensor screw is adjusted)

//h = humidity; c = Celsius temperature

float h, c;

String packSize; //variable used to receive the size of package converted in string

String packet = “OK”; //part of packet, that informs the status of sensor. That variable will be concatenate with the string “values”

String values = “|-|-”; //humidity and temperature values, separated by pipe

//parameters: address,SDA,SCL

SSD1306 display(0x3c, 4, 15); //display object

SimpleDHT22 dht22;

// Pins definition

#define SCK 5 // GPIO5 -- SX127x‘s SCK

#define MISO 19 // GPIO19 -- SX127x’s MISO

#define MOSI 27 // GPIO27 -- SX127x‘s MOSI

#define SS 18 // GPIO18 -- SX127x’s CS

#define RST 14 // GPIO14 -- SX127x‘s RESET

#define DI00 26 // GPIO26 -- SX127x’s IRQ(Interrupt Request)

#define MQ_analog 12 //analog gas sensor pin

#define MQ_dig 13 //digital gas sensor pin

#define BAND 433E6 //Radio frequency, we can still use: 433E6, 868E6, 915E6

步骤15:发送方除了定义气体传感器的最小触发值外,还带有用于接收模拟数字信号的变量的传感器。代码[设置]

在设置中,我们将首先配置引脚和显示。

void setup()

{

//set the humidity and temperature values with zero

h = c = 0;

//initialize the Serial with 9600b per second

Serial.begin(9600);

//configures analog pin as input

pinMode(MQ_analog, INPUT);

//configures digital pin as input

pinMode(MQ_dig, INPUT);

//configures oled pins as output

pinMode(16,OUTPUT);

//reset oled

digitalWrite(16, LOW);

//wait 50ms

delay(50);

//while the oled is on, GPIO16 must be HIGH

digitalWrite(16, HIGH);

//initializes the display

display.init();

//flip vertically the display

display.flipScreenVertically();

接下来,我们将在显示屏上定义打印特性,并开始与LORA进行串行通信。然后,我们将继续进行配置。

//set display font

display.setFont(ArialMT_Plain_10);

//wait 1500ms

delay(1500);

//clear the display

display.clear();

//initializes serial interface

SPI.begin(SCK,MISO,MOSI,SS);

//set Lora pins

LoRa.setPins(SS,RST,DI00);

//initializes the lora, seting the radio frequency

if (!LoRa.begin(BAND))

{

//draw in the position 0,0 the message in between quotation marks

display.drawString(0, 0, “Starting LoRa failed!”);

//turns on the LCD display

display.display();

//do nothing forever

while (true);

}

}

步骤16:发件人代码[循环]

在循环中,我们还使用显示器的特性,并指示读取传感器的步骤以及LORA的气体检测和警报发送的方法。

void loop()

{

//clear the display

display.clear();

//set the text alignment to left

display.setTextAlignment(TEXT_ALIGN_LEFT);

//sets the text font

display.setFont(ArialMT_Plain_16);

//draw in the position 0,0 the message in between quotation marks

display.drawString(0, 0, “Running.。.”);

//reads temperature sensor values

readDhtSensor();

//it concatenates on string the humidity and temperature values separated by pipe

values=“|”+String(h)+“|”+String(c);

//if the digital signal of sensor is lower, it means gas detected (inverse logic

if(gasDetected())

{

//sets the value of the packet string to “ALARM

packet = “ALARM”;

//it concatenates the packet with the values

packet+=values;

//sends package by LoRa

sendPacket();

//shows display, true = gas detected

showDisplay(true);

}

我们定义了将通过SMS发送的信息

else

{

//sets the value of the packet string to “OK”

packet = “OK”;

//it concatenates the packet with the values

packet+=values;

//sends package by LoRa

sendPacket();

//shows display, false = no gas detected

showDisplay(false);

}

//waits 250ms

delay(250);

}

步骤17:发件人代码[showDisplay]

同样,我们处理LORA显示屏上的数据显示。

void showDisplay(bool gasDetected)

{

//clear the display

display.clear();

//set the text alignment to left

display.setTextAlignment(TEXT_ALIGN_LEFT);

//sets the text font

display.setFont(ArialMT_Plain_16);

//draw in the position 0,0 the message in between quotation marks

display.drawString(0, 0, “Running.。.”);

//if flag = true

if(gasDetected)

{

//draw in the position 0,20 the message in between quotation marks

display.drawString(0, 20, “Status: ALARM”);

//draw in the position 0,40 the message in between quotation marks

display.drawString(0, 40, “Gas detected!”);

//turns on the LCD display

display.display();

}

else

{

//draw in the position 0,20 the message in between quotation marks

display.drawString(0, 20, “Status: OK”);

//draw in the position 0,40 the message in between quotation marks

display.drawString(0, 40, “H: ”+String(h)+“ T: ”+String(c)+“°”);

//turns on the LCD display

display.display();

}

}

步骤18:发件人代码[gasDetected]

在这里,如果传感器检测到某种类型的气体泄漏,我们具有触发消息的功能。

bool gasDetected()

{

//reads the analog value of the sensor

analog_value = analogRead(MQ_analog);

//reads the digital value of the sensor

dig_value = digitalRead(MQ_dig);

//obs: the serial views in this code do not influence the operation of the prototype

//shows value to the serial

Serial.print(analog_value);

//shows tab “||” to the serial

Serial.print(“ || ”);

//inverse logic

if(dig_value == 0)

{

//sets the minimum analog value

if(gas_limit == 0 || gas_limit 》 analog_value)

gas_limit = analog_value;

//shows ‘gas detected’ to the serial

Serial.println(“GAS DETECTED !!!”);

//shows the minimum gas limit to the serial

Serial.println(“Gas limit: ”+String(gas_limit));

//gas detected

return true;

}

else

{

//shows ‘no gas detected’ to the serial

Serial.println(“No gas detected.。.”);

//if first time, shows ‘X’ to the serial

if(gas_limit == 0)

Serial.println(“Gas limit: X”);

else //shows gas limit to the serial

Serial.println(“Gas limit: ”+String(gas_limit));

//no gas detected

return false;

}

}

第19步:发送方代码[readDhtSensor]

void readDhtSensor()

{

// declaration of variables that will receive the new temperature and humidity

float novoC, novoH;

//waits 250ms

delay(250);

//set dht22 sensor values tovariables &novoC and &novoH

int err = dht22.read2(DHTPin, &novoC, &novoH, NULL);

//checks for an error

if (err != SimpleDHTErrSuccess)

{

//shows error in the serial

Serial.print(“Read DHT22 failed, err=”);

Serial.println(err);

return;

}

//if no error

//sets the variable values

c = novoC;

h = novoH;

//shows values in the serial

Serial.print((float)c); Serial.println(“ *C ”);

Serial.print((float)h); Serial.println(“ H”);

//waits 250ms

delay(250);

}

第20步:发送方代码[sendPacket]

最后,我们打开了一个程序包,以添加用于SMS发送的数据。

void sendPacket()

{

//starts a connection to write UDP data

LoRa.beginPacket();

//send packet

LoRa.print(packet);

//returns an int: 1 if the packet was sent successfully, 0 if there was an error

LoRa.endPacket();

}
责任编辑:wv

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 传感器
    +关注

    关注

    2522

    文章

    47984

    浏览量

    739678
  • 蜂鸣器
    +关注

    关注

    12

    文章

    849

    浏览量

    45282
  • ESP32
    +关注

    关注

    13

    文章

    895

    浏览量

    15795
收藏 人收藏

    评论

    相关推荐

    esp32s3使用多串口

    esp32s3使用多串口 我按照别人博客中设置串口2,串口打印有问题,因为没有看到esp32s3 多串口,就总结了一下自己的经验 下图为esp32的引脚图 下图为esp32s3的引脚
    的头像 发表于 11-06 11:29 1338次阅读
    <b class='flag-5'>esp32</b>s3使用多串口

    启明云端将推出基于ESP32-C6的Wi-Fi/BLE+ LoRa®低成本单通道网关方案

    前不久发布的基于ESP32-C2的Wi-Fi/BLE+LoRa极低成本无线组网方案后,收到了不少客户的咨询,可见低成本Wi-Fi和LoRa的结合使用还是很受市场欢迎的。本月,启明云端继而推出
    的头像 发表于 10-31 08:03 537次阅读
    启明云端将推出基于<b class='flag-5'>ESP32</b>-C6的Wi-Fi/BLE+ <b class='flag-5'>LoRa</b>®低成本单通道网关方案

    如何在ESP32中使用PWM

    ESP32 SoC 满载了非常有用的外设,PWM 就是其中之一。是的。ESP32 的芯片中有一个专用的 PWM 硬件模块。脉宽调制或简称PWM是一种成熟且广泛使用的供电技术。
    的头像 发表于 07-13 11:14 1316次阅读
    如何在<b class='flag-5'>ESP32</b>中使用PWM

    LoRa ESP32无线电-轻松入门教程

    电子发烧友网站提供《LoRa ESP32无线电-轻松入门教程.zip》资料免费下载
    发表于 07-11 10:14 1次下载
    <b class='flag-5'>LoRa</b> <b class='flag-5'>ESP32</b>无线电-轻松入门教程

    如何将ESP8266 NodeMCU用作WiFi无线电

    电子发烧友网站提供《如何将ESP8266 NodeMCU用作WiFi无线电.zip》资料免费下载
    发表于 07-05 11:37 1次下载
    <b class='flag-5'>如何将</b><b class='flag-5'>ESP</b>8266 NodeMCU<b class='flag-5'>用作</b>WiFi无线电

    如何使用M5StickC ESP32模块通过按钮更改LED亮度

    电子发烧友网站提供《如何使用M5StickC ESP32模块通过按钮更改LED亮度.zip》资料免费下载
    发表于 06-29 11:27 0次下载
    如何使用M5StickC <b class='flag-5'>ESP32</b><b class='flag-5'>模块</b>通过按钮更改LED亮度

    ESP32ESP32通过Internet进行通信

    电子发烧友网站提供《ESP32ESP32通过Internet进行通信.zip》资料免费下载
    发表于 06-15 09:58 2次下载
    <b class='flag-5'>ESP32</b>到<b class='flag-5'>ESP32</b>通过Internet进行通信

    [esp32教程] 5、UART使用

    基于Ubuntu下,利用esp-idf进行esp32开发的教程
    的头像 发表于 06-13 09:04 4263次阅读
    [<b class='flag-5'>esp32</b>教程] 5、UART使用

    [esp32教程] 4、LEDC使用

    基于Ubuntu下,利用esp-idf进行esp32开发的教程
    的头像 发表于 06-03 09:39 3078次阅读
    [<b class='flag-5'>esp32</b>教程] 4、LEDC使用

    ESP32当发现新的BT设备时向手机发送警报?

    我正在尝试对 ESP32 进行编程以扫描新的 BLE 设备,如果它检测到具有强 RSSI 的新设备,则向 Android 手机发送警报。该消息将包含新检测到的 BLE 设备的 BLE ID。 棘手
    发表于 05-12 07:32

    [esp32教程]2、按键中断

    基于Ubuntu,利用esp-idf进行esp32的教学
    的头像 发表于 05-05 09:04 2158次阅读
    [<b class='flag-5'>esp32</b>教程]2、按键中断

    [esp32教程]1、点灯之术

    基于Ubuntu下,利用esp-idf进行esp32开发的教程
    的头像 发表于 04-30 18:11 2337次阅读
    [<b class='flag-5'>esp32</b>教程]1、点灯之术

    如何将ESP8266 (ESP-01) 连接到LoRa 32u4?

    我已经尝试了几个教程来连接 esp-01 模块,但它没有用,因为对于 arduino GUI 的 esp8266 板,lora 串行端口似乎无法识别它所以我的问题是是否有办法桥接
    发表于 04-28 08:49

    ESP32端如何配置成收到服务端发送的数据就通过串口传出?

    使用AT固件 ,将模块配置为TCP Client模式。与服务端进行通信收发都正常。ESP32发送消息在两帧间隔>20ms后,服务端基本上能保持逐帧接收(2帧数据不会合为一帧)。而
    发表于 04-24 06:24

    esp32教程】0、环境搭建

    基于Ubuntu下,利用esp-idf进行esp32开发的教程
    的头像 发表于 04-21 16:54 3697次阅读