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

步骤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();
}


PCB厂商金禄电子创业板IPO已获受理
基于STM32的酒精浓度检测报警proteus仿真设计
2021年网络安全行业将迎来什么挑战?
捆扎机远程监控运维数字化解决方案
新品 | 联讯仪器全新推出低泄漏电流开关矩阵RM1010-LLC
如何将此ESP32 LORA模块用作发送方和接收方
一家领先的全息AR应用技术提供商,获得用于全息AR系统的头戴显示器的专利
携手台积电,苹果去三星化任重而道远
难以证明又无法推翻的黎曼猜想被证明了吗?
紫光联发科要合并?
ATM机监控管理系统解决方案
基于串行通讯技术在冶金行业自动化系统中的应用分析
三级负荷的消防泵的配电是否可以单电源配电?
iphone8什么时候上市最新消息:苹果作死,这样的iphone7s会有人买?
一文解析源测量单元(SMU)仪器
浙江微针半导体官宣2D MEMS探针卡已成功实现量产
苹果获新专利--在MacBook和iMac键盘中集成天线的方法
USB vs IEEE1394
磁性电流传感器可提高电源应用的效率
全亮半亮爆闪IC 多功能 LED降压型恒流芯片