99精品伊人亚洲|最近国产中文炮友|九草在线视频支援|AV网站大全最新|美女黄片免费观看|国产精品资源视频|精彩无码视频一区|91大神在线后入|伊人终合在线播放|久草综合久久中文

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

如何將此ESP32 LORA模塊用作發(fā)送方和接收方

454398 ? 來源:網(wǎng)絡整理 ? 作者:網(wǎng)絡整理 ? 2019-11-14 17:14 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

步驟1:操作(數(shù)據(jù)傳輸)

這是裝配體工作原理圖。

步驟2:使用的資源

2 ESP32 LORA OLED顯示屏

1 Arduino Nano ATmega328

1 Arduino以太網(wǎng)模塊ENC28J60

1氣體傳感器模塊MQ2

1濕度和溫度傳感器DHT22( AM2302)

2330歐姆電阻

1 4k7歐姆電阻

1蜂鳴器5V

1個綠色LED

1紅色LED

跳線

步驟3:功能-發(fā)送方

1 ESP32 LORA Display

1氣體傳感器模塊MQ2

1濕度和溫度傳感器DHT22(AM2302)

1個4k7歐姆電阻器

跳線

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

1個ESP32 LORA OLED顯示屏

1個Arduino Nano ATmega328

1個用于Arduino的以太網(wǎng)模塊ENC28J60

2330 ohm r電阻器

1個蜂鳴器5V

1個綠色LED

1個紅色LED

跳線

步驟5:MQ-2氣體傳感器靈敏度

傳感器的電阻(Rs/Ro)根據(jù)現(xiàn)有的氣體濃度(ppm)更高或更低。此濃度可以通過引腳A0的輸出來顯示。

MQ-2氣體傳感器對氣體具有高靈敏度:

?LPG(液化石油氣);

?丙烷(C3H8);

?氫氣(H2);

?甲烷(CH4);

?燃料氣體,例如丙烷, CO,酒精和丁烷(用于打火機)。

步驟6:發(fā)送器安裝--- Pinout ESP32 LORA OLED

步驟7 :發(fā)送器電路

步驟8:發(fā)送器安裝

步驟9:安裝接收器---引腳排列Arduino Nano ATmega328

步驟10:接收器電路

步驟11:接收器安裝

綠色LED指示Arduino已連接到以太網(wǎng)客戶端。

紅色LED指示已發(fā)送SMS。

發(fā)送SMS時,Arduino已斷開連接,因此不再發(fā)送任何消息。

步驟12:DHT庫安裝

1。轉到草圖-》包含庫-》庫管理器。

2。搜索SimpleDHT,然后單擊“安裝”。

步驟13:發(fā)件人-代碼的組織

設置 》

循環(huán)

-readDhtSensor:負責讀取傳感器和獲取溫度和濕度值。

-gasDetected:負責讀取傳感器并驗證是否已檢測到氣體的功能。

-sendPacket:負責通過LORA發(fā)送包裹的功能

-showDisplay:負責顯示在顯示屏上獲得的消息和值的功能。

步驟14:發(fā)件人代碼[包含和定義]

首先,我們將包含定義引腳的庫。

#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:發(fā)送方除了定義氣體傳感器的最小觸發(fā)值外,還帶有用于接收模擬數(shù)字信號的變量的傳感器。代碼[設置]

在設置中,我們將首先配置引腳和顯示。

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進行串行通信。然后,我們將繼續(xù)進行配置。

//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:發(fā)件人代碼[循環(huán)]

在循環(huán)中,我們還使用顯示器的特性,并指示讀取傳感器的步驟以及LORA的氣體檢測和警報發(fā)送的方法。

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發(fā)送的信息。

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:發(fā)件人代碼[showDisplay]

同樣,我們處理LORA顯示屏上的數(shù)據(jù)顯示。

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:發(fā)件人代碼[gasDetected]

在這里,如果傳感器檢測到某種類型的氣體泄漏,我們具有觸發(fā)消息的功能。

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步:發(fā)送方代碼[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步:發(fā)送方代碼[sendPacket]

最后,我們打開了一個程序包,以添加用于SMS發(fā)送的數(shù)據(jù)。

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

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 傳感器
    +關注

    關注

    2565

    文章

    52965

    瀏覽量

    767102
  • 蜂鳴器
    +關注

    關注

    12

    文章

    895

    瀏覽量

    46934
  • ESP32
    +關注

    關注

    21

    文章

    1017

    瀏覽量

    19234
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    ESP32用作經(jīng)典藍牙串口透傳模塊與手機進行串口通信

    本文介紹了如何把ESP32用作一個藍牙串口透傳設備使用,其功能和常用的HC-05/06串口藍牙設備一樣。并與手機藍牙串口APP進行雙向藍牙通信。
    的頭像 發(fā)表于 06-20 17:45 ?899次閱讀
    <b class='flag-5'>ESP32</b><b class='flag-5'>用作</b>經(jīng)典藍牙串口透傳<b class='flag-5'>模塊</b>與手機進行串口通信

    ESP32驅動MFRC522 RFID模塊讀寫IC卡數(shù)據(jù)

    本文將介紹ESP32開發(fā)板驅動MFRC522 RFID模塊,讀取RFID卡原始數(shù)據(jù)、獲取RFID卡的UID,并將個人數(shù)據(jù)添加到RFID卡中。
    的頭像 發(fā)表于 05-28 15:52 ?216次閱讀
    <b class='flag-5'>ESP32</b>驅動MFRC522 RFID<b class='flag-5'>模塊</b>讀寫IC卡數(shù)據(jù)

    esp32如何接入豆包

    要在 ESP32 上接入豆包工具,本質上是讓 ESP32 設備與豆包的 API 進行通信,以獲取相關服務
    的頭像 發(fā)表于 02-05 13:40 ?1954次閱讀
    <b class='flag-5'>esp32</b>如何接入豆包

    ESP32-S3-WROOM-1/ESP32-S3-WROOM-1U技術規(guī)格書

    電子發(fā)燒友網(wǎng)站提供《ESP32-S3-WROOM-1/ESP32-S3-WROOM-1U技術規(guī)格書.pdf》資料免費下載
    發(fā)表于 12-07 15:30 ?11次下載

    【代碼分享】基于樂鑫ESP32的串口不定長數(shù)據(jù)接收方

    【代碼分享】基于樂鑫ESP32的串口不定長數(shù)據(jù)接收方
    的頭像 發(fā)表于 11-15 01:02 ?1447次閱讀
    【代碼分享】基于樂鑫<b class='flag-5'>ESP32</b>的串口不定長數(shù)據(jù)<b class='flag-5'>接收方</b>法

    基于ESP32-C3FN4為核心自主研發(fā)的Wi-Fi+BT模塊-RF-WM-ESP32B1

    WI-FI模組 - RF-WM-ESP32B1是基于ESP32-C3FN4為核心自主研發(fā)的Wi-Fi+BT模塊,支持IEEE 802.11b/g/n (2.4 GHz Wi-Fi)和低功耗藍牙5.0,可廣泛用于各種消費類電子、手
    的頭像 發(fā)表于 11-07 09:45 ?656次閱讀
    基于<b class='flag-5'>ESP32</b>-C3FN4為核心自主研發(fā)的Wi-Fi+BT<b class='flag-5'>模塊</b>-RF-WM-<b class='flag-5'>ESP32</b>B1

    【AI技術支持】ESP32-WROOM-32E模組WiFi自適應發(fā)送數(shù)據(jù)失敗處理

    你是否曾遇到過?在使用ESP32-WROOM-32E模組,ESP-IDF版本為idf4.x時,客戶把模組貼在主板上做整機測試,由串口工具供電,WiFi自適應測試時可以連接路由器的AP名稱和密碼
    的頭像 發(fā)表于 11-02 08:00 ?1349次閱讀
    【AI技術支持】<b class='flag-5'>ESP32</b>-WROOM-32E模組WiFi自適應<b class='flag-5'>發(fā)送</b>數(shù)據(jù)失敗處理

    【AI技術支持】ESP32模組PSRAM的CS引腳上拉導致功耗上升處理

    esp32芯片類型使用了QSPIPSRAM的情況下,IO16引腳必須接上拉電阻10K且不能用作其他功能。在這個設計下,外部psram啟用時,psram的cs是輸出低
    的頭像 發(fā)表于 10-31 08:01 ?2174次閱讀
    【AI技術支持】<b class='flag-5'>ESP32</b>模組PSRAM的CS引腳上拉導致功耗上升處理

    esp32上使用chatGPT做一些有意思的事情

    對OpenAI API的請求。 4、使用HTTP請求向OpenAI API發(fā)送文本輸入,接收JSON格式的響應。 5、解析響應并使用它來控制ESP32微控制器
    的頭像 發(fā)表于 10-18 10:04 ?1067次閱讀

    使用ESP32開發(fā)板點亮LED燈

    ESP32是一款由Espressif Systems開發(fā)的高性能、低功耗的Wi-Fi+藍牙雙模微控制器芯片。它集成了天線開關、RF balun、功率放大器、低噪聲接收放大器、濾波器以及電源管理模塊
    的頭像 發(fā)表于 10-05 11:44 ?4985次閱讀

    esp32esp8266代碼共用嗎

    本文將介紹ESP32ESP8266兩款流行的微控制器在代碼共用性方面的可能性與差異性。 一、引言 隨著物聯(lián)網(wǎng)技術的飛速發(fā)展,越來越多的智能設備開始進入我們的生活。其中,ESP32ESP
    的頭像 發(fā)表于 08-19 18:23 ?2333次閱讀

    esp8266和esp32區(qū)別是什么

    以下是關于ESP8266和ESP32的主要區(qū)別: 處理器和架構 : ESP8266 :使用一個Tensilica L106 80MHz的處理器,屬于Xtensa架構。 ESP32 :使
    的頭像 發(fā)表于 08-19 18:16 ?7304次閱讀

    esp32用什么軟件編程

    ESP32是一款由樂鑫(Espressif)推出的低功耗、高性能的Wi-Fi和藍牙雙模微控制器,廣泛應用于物聯(lián)網(wǎng)、智能家居、智能穿戴等領域。要對ESP32進行編程,需要選擇合適的編程軟件和開發(fā)環(huán)境
    的頭像 發(fā)表于 08-19 17:24 ?6915次閱讀

    如何將ESP8266-01模塊用作物理層設備?

    嗨,大家好。我想將 ESP8266-01 模塊用作物理層設備,就像射頻發(fā)射器和接收器一樣。 一個模塊
    發(fā)表于 07-19 12:18

    ESP32-WROOM-32E、ESP32-WROOM-32D、ESP32-WROOM-32U 有什么區(qū)別?ESP32-WROOM-32 后綴字母代表的意思是?

    相信很多人心里都有這樣的疑問,今天就教大家怎么區(qū)分它們。 32D和32U是同一個芯片ESP32-D0WD的模組,主要區(qū)別的天線模式,分別是板載和IPEX外接天線。 32E是用的升級版的芯片
    的頭像 發(fā)表于 07-17 10:09 ?1.6w次閱讀
    <b class='flag-5'>ESP32</b>-WROOM-32E、<b class='flag-5'>ESP32</b>-WROOM-32D、<b class='flag-5'>ESP32</b>-WROOM-32U  有什么區(qū)別?<b class='flag-5'>ESP32</b>-WROOM-32 后綴字母代表的意思是?