UNO+ESP8266+Blinker-Arduino中文社区 - Powered by Discuz! Archiver

努力编程小阿格 发表于 2022-4-11 19:03

UNO+ESP8266+Blinker

我想在uno上连接烟雾、火焰、人体红外、蜂鸣器、OLED,通过传感器收集数据,通过esp8266,wifi模块进行数据传输,在Blinker上显示烟雾浓度和火焰强度,及是否有人入侵。也可以在app上下发指令,通过esp进行传送数据,uno读取数据,进行处理,从而控制蜂鸣器鸣响。烟雾传感器连接uno引脚A1,火焰传感器连接uno数字引脚,uno和esp引脚RX TX交叉连接,请问这个可以实现吗?

有人说点灯APP占用esp的硬件定时器,uno无法将烟雾传感器数据通过wifi传送到app。我不知道他说的对不对。

求解大佬。

myself1820 发表于 2022-4-12 14:13

参考我这个帖子 https://www.arduino.cn/thread-104326-1-1.html

努力编程小阿格 发表于 2022-4-14 09:39

myself1820 发表于 2022-4-12 14:13
参考我这个帖子 https://www.arduino.cn/thread-104326-1-1.html

大佬你好,我看了看您的这个帖子,和我这个相似度挺高的。我这个esp8266用的是nodemcu,其实我特别想知道UNO的硬串口RX TX和esp8266串口RX TX相连,再使用bkinker可以实现在app上进行浓度显示以及门锁控制吗?

努力编程小阿格 发表于 2022-4-14 09:45

myself1820 发表于 2022-4-12 14:13
参考我这个帖子 https://www.arduino.cn/thread-104326-1-1.html

您好像用的开发板和我的不太一样,用的是开发板软串口连接的。

myself1820 发表于 2022-4-16 10:56

努力编程小阿格 发表于 2022-4-14 09:45
您好像用的开发板和我的不太一样,用的是开发板软串口连接的。

硬串口也可以,程序里稍微改动一下就可以了。我一开始也是用的硬串口,为了方便连接电脑调试,改成软串口了

myself1820 发表于 2022-4-16 11:01

努力编程小阿格 发表于 2022-4-14 09:39
大佬你好,我看了看您的这个帖子,和我这个相似度挺高的。我这个esp8266用的是nodemcu,其实我特别想知道 ...

可以,把程序里的软串口改成硬串口就可以了

努力编程小阿格 发表于 2022-5-4 17:49

myself1820 发表于 2022-4-16 11:01
可以,把程序里的软串口改成硬串口就可以了

大佬,您看我这个程序怎么改正呀,我对比了您的代码和我的,我不太会改正。这是uno采集数据串口通信向esp传输,但是人体红外 火焰传感我都想要通过串口通信,我不知道怎么改,您能帮我看看吗
//RC522
#include <SPI.h>
#include <String.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN);
byte nuidPICC;

//OLED显示屏
#include <DFRobot_SSD1306_I2C.h>
#define OLED_RESET 13


// 静态常量
const chCode chBuf[] = {
{0x667a, 0xe699ba, 0xD6C7, {0x20, 0x00, 0x3e, 0x7c, 0x48, 0x44, 0x08, 0x44, 0xff, 0x44, 0x14, 0x44, 0x22, 0x7c, 0x40, 0x00, 0x1f, 0xf0, 0x10, 0x10, 0x10, 0x10, 0x1f, 0xf0, 0x10, 0x10, 0x10, 0x10, 0x1f, 0xf0, 0x10, 0x10}},
{0x6167, 0xe685a7, 0xBBDB, {0x10, 0x10, 0xfe, 0xfe, 0x10, 0x10, 0x7c, 0x7c, 0x10, 0x10, 0xfe, 0xfe, 0x10, 0x10, 0x3f, 0xf8, 0x00, 0x08, 0x1f, 0xf8, 0x00, 0x08, 0x3f, 0xf8, 0x01, 0x00, 0x48, 0x84, 0x48, 0x12, 0x87, 0xf2}},
{0x5c0f, 0xe5b08f, 0xD0A1, {0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x10, 0x11, 0x08, 0x11, 0x04, 0x21, 0x04, 0x21, 0x02, 0x41, 0x02, 0x81, 0x02, 0x01, 0x00, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00}},
{0x533a, 0xe58cba, 0xC7F8, {0x00, 0x00, 0x7f, 0xfc, 0x40, 0x00, 0x40, 0x10, 0x44, 0x10, 0x42, 0x20, 0x41, 0x40, 0x40, 0x80, 0x41, 0x40, 0x42, 0x20, 0x44, 0x10, 0x48, 0x10, 0x40, 0x00, 0x40, 0x00, 0x7f, 0xfe, 0x00, 0x00}},
{0x5b89, 0xe5ae89, 0xB0B2, {0x02, 0x00, 0x01, 0x00, 0x3f, 0xfc, 0x20, 0x04, 0x42, 0x08, 0x02, 0x00, 0x02, 0x00, 0xff, 0xfe, 0x04, 0x20, 0x08, 0x20, 0x18, 0x40, 0x06, 0x40, 0x01, 0x80, 0x02, 0x60, 0x0c, 0x10, 0x70, 0x08}},
{0x9632, 0xe998b2, 0xB7C0, {0x00, 0x40, 0x7c, 0x20, 0x44, 0x20, 0x4b, 0xfe, 0x48, 0x80, 0x50, 0x80, 0x48, 0x80, 0x48, 0xfc, 0x44, 0x84, 0x44, 0x84, 0x44, 0x84, 0x68, 0x84, 0x51, 0x04, 0x41, 0x04, 0x42, 0x28, 0x44, 0x10}},
{0x7cfb, 0xe7b3bb, 0xCFB5, {0x00, 0xf8, 0x3f, 0x00, 0x04, 0x00, 0x08, 0x20, 0x10, 0x40, 0x3f, 0x80, 0x01, 0x00, 0x06, 0x10, 0x18, 0x08, 0x7f, 0xfc, 0x01, 0x04, 0x09, 0x20, 0x11, 0x10, 0x21, 0x08, 0x45, 0x04, 0x02, 0x00}},
{0x7edf, 0xe7bb9f, 0xCDB3, {0x10, 0x40, 0x10, 0x20, 0x20, 0x20, 0x23, 0xfe, 0x48, 0x40, 0xf8, 0x88, 0x11, 0x04, 0x23, 0xfe, 0x40, 0x92, 0xf8, 0x90, 0x40, 0x90, 0x00, 0x90, 0x19, 0x12, 0xe1, 0x12, 0x42, 0x0e, 0x04, 0x00}},
{0x53ef, 0xe58faf, 0xBFC9, {0x00, 0x00, 0x7f, 0xfe, 0x00, 0x10, 0x00, 0x10, 0x1f, 0x10, 0x11, 0x10, 0x11, 0x10, 0x11, 0x10, 0x11, 0x10, 0x11, 0x10, 0x1f, 0x10, 0x11, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x50, 0x00, 0x20}},
{0x71c3, 0xe78783, 0xC8BC, {0x11, 0x10, 0x11, 0x14, 0x11, 0xd2, 0x16, 0x50, 0x5a, 0x7e, 0x55, 0x50, 0x50, 0x90, 0x92, 0xa8, 0x11, 0x28, 0x11, 0x44, 0x12, 0x44, 0x2c, 0x82, 0x24, 0x08, 0x42, 0xa4, 0x42, 0x52, 0x84, 0x52}},
{0x6c14, 0xe6b094, 0xC6F8, {0x10, 0x00, 0x10, 0x00, 0x3f, 0xfc, 0x20, 0x00, 0x4f, 0xf0, 0x80, 0x00, 0x3f, 0xf0, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x06, 0x00, 0x02}},
{0x4f53, 0xe4bd93, 0xCCE5, {0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0x10, 0x40, 0x17, 0xfc, 0x30, 0x40, 0x30, 0xe0, 0x50, 0xe0, 0x91, 0x50, 0x11, 0x50, 0x12, 0x48, 0x15, 0xf4, 0x18, 0x42, 0x10, 0x40, 0x10, 0x40, 0x10, 0x40}},
{0x6d53, 0xe6b593, 0xC5A8, {0x00, 0x40, 0x20, 0x40, 0x10, 0x40, 0x17, 0xfc, 0x84, 0x84, 0x48, 0x88, 0x41, 0x40, 0x11, 0x44, 0x13, 0x48, 0x25, 0x30, 0xe9, 0x20, 0x21, 0x10, 0x21, 0x08, 0x21, 0x44, 0x21, 0x82, 0x01, 0x00}},
{0x5ea6, 0xe5baa6, 0xB6C8, {0x01, 0x00, 0x00, 0x80, 0x3f, 0xfe, 0x22, 0x20, 0x22, 0x20, 0x3f, 0xfc, 0x22, 0x20, 0x22, 0x20, 0x23, 0xe0, 0x20, 0x00, 0x2f, 0xf0, 0x24, 0x10, 0x42, 0x20, 0x41, 0xc0, 0x86, 0x30, 0x38, 0x0e}},
{0xff1a, 0xefbc9a, 0xA3BA, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x706b, 0xe781ab, 0xBBF0, {0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x08, 0x11, 0x08, 0x11, 0x10, 0x21, 0x20, 0x21, 0x00, 0x42, 0x80, 0x02, 0x80, 0x04, 0x40, 0x04, 0x40, 0x08, 0x20, 0x10, 0x10, 0x20, 0x08, 0xc0, 0x06}},
{0x7130, 0xe784b0, 0xD1E6, {0x10, 0x40, 0x10, 0x40, 0x10, 0x7c, 0x14, 0x84, 0x59, 0x08, 0x52, 0x00, 0x50, 0x20, 0x91, 0xce, 0x11, 0x02, 0x11, 0x02, 0x11, 0xce, 0x29, 0x02, 0x25, 0x02, 0x45, 0x02, 0x41, 0xfe, 0x81, 0x02}},
{0x53c2, 0xe58f82, 0xB2CE, {0x02, 0x00, 0x04, 0x40, 0x08, 0x20, 0x1f, 0xf0, 0x02, 0x00, 0x7f, 0xfc, 0x08, 0x20, 0x10, 0x90, 0x23, 0x08, 0xcc, 0x46, 0x01, 0x80, 0x06, 0x10, 0x18, 0x20, 0x00, 0xc0, 0x07, 0x00, 0x78, 0x00}},
{0x6570, 0xe695b0, 0xCAFD, {0x08, 0x20, 0x49, 0x20, 0x2a, 0x20, 0x08, 0x3e, 0xff, 0x44, 0x2a, 0x44, 0x49, 0x44, 0x88, 0xa4, 0x10, 0x28, 0xfe, 0x28, 0x22, 0x10, 0x42, 0x10, 0x64, 0x28, 0x18, 0x28, 0x34, 0x44, 0xc2, 0x82}},
{0x6709, 0xe69c89, 0xD3D0, {0x02, 0x00, 0x02, 0x00, 0xff, 0xfe, 0x04, 0x00, 0x04, 0x00, 0x0f, 0xf0, 0x08, 0x10, 0x18, 0x10, 0x2f, 0xf0, 0x48, 0x10, 0x88, 0x10, 0x0f, 0xf0, 0x08, 0x10, 0x08, 0x10, 0x08, 0x50, 0x08, 0x20}},
{0x4eba, 0xe4baba, 0xC8CB, {0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x80, 0x02, 0x80, 0x04, 0x40, 0x04, 0x40, 0x08, 0x20, 0x08, 0x20, 0x10, 0x10, 0x20, 0x08, 0x40, 0x04, 0x80, 0x02}},
{0x5165, 0xe585a5, 0xC8EB, {0x04, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x80, 0x02, 0x80, 0x02, 0x80, 0x04, 0x40, 0x04, 0x40, 0x08, 0x20, 0x08, 0x20, 0x10, 0x10, 0x20, 0x10, 0x40, 0x08, 0x80, 0x06}},
{0x4fb5, 0xe4beb5, 0xC7D6, {0x08, 0x00, 0x0b, 0xf8, 0x08, 0x08, 0x11, 0xf8, 0x10, 0x08, 0x33, 0xf8, 0x30, 0x00, 0x57, 0xfc, 0x94, 0x04, 0x13, 0xf0, 0x11, 0x10, 0x11, 0x10, 0x10, 0xa0, 0x10, 0x40, 0x11, 0xb0, 0x16, 0x0e}}
};
// 创建对象
DFRobot_SSD1306_I2C oled12864;
//设置烟雾上下限初始值
int smoke_max = 30;
int smoke = 0;
//设置硬件引脚
#definerenti8//红外
#defineflame7//火焰
#define buzzer6//蜂鸣器
#define relay 5//继电器
#define ESP8266_OUT14//蜂鸣器
#define ESP8266_OUT2 3//门禁
#define ESP8266_IN2//蜂鸣器
#define ESP8266_OUT3A0//蜂鸣器
#define MQ A1 //烟雾传感器
//声明变量
String comdata = "";
int a_1 = 0, a_2 = 0, a_3 = 0, a_4 = 0;
int b_1 = 0, b_2 = 0, b_3 = 0, b_4 = 0;
int sss = 0;


//初始化
void setup()
{
//定义字符
oled12864.setChCode(chBuf);
oled12864.begin(0x3c);
oled12864.setCursor(0, 0);
oled12864.print("智慧小区安防系统");
oled12864.setCursor(0, 1);
oled12864.print("可燃气体:");
oled12864.setCursor(0, 2);
oled12864.print("火焰参数:");
//串口
Serial.begin(9600);
//SPI
SPI.begin();
rfid.PCD_Init();
//设置引脚
pinMode(renti, INPUT_PULLUP);
pinMode(flame, INPUT_PULLUP);
pinMode(ESP8266_OUT1, INPUT_PULLUP);
pinMode(ESP8266_OUT2, INPUT_PULLUP);
pinMode(ESP8266_OUT3, OUTPUT);
digitalWrite(ESP8266_OUT3, 1);
pinMode(ESP8266_IN, OUTPUT);
digitalWrite(ESP8266_IN, 1);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, 1);
pinMode(relay, OUTPUT);
digitalWrite(relay, 1);
}

//烟雾传感器
void MQ_2() {

smoke = 100 - map(analogRead(MQ), 1023, 0, 0, 100);

Serial.print("S");
Serial.print(smoke);
Serial.print(',');

if (smoke < 10) {
    oled12864.setCursor(70, 1);
    oled12864.print(smoke);
    oled12864.setCursor(79, 1);
    oled12864.print("    ");
}
if (smoke >= 10) {
    oled12864.setCursor(70, 1);
    oled12864.print(smoke);
    oled12864.setCursor(87, 1);
    oled12864.print("    ");
}
if (smoke == 100) {
    oled12864.setCursor(70, 1);
    oled12864.print(smoke);
}


if (smoke > smoke_max) {
    b_1 = 1;
    //这里要蜂鸣器
}
}

//hex
void printHex(byte *buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++)
{
    //Serial.print(buffer < 0x10 ? " 0" : "");
    //Serial.print(buffer, HEX);
}
}
//==================开门用================//
void printDec(byte *buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++) {
    //Serial.print(buffer < 0x10 ? " 0" : "");
    //Serial.print(buffer, DEC);
}
//人员1
if (nuidPICC == 0x53 && nuidPICC == 0x25 && nuidPICC == 0x80 && nuidPICC == 0x94) // 卡号ID
{

    a_1 = 1;
    //这里要开门
}
//人员2
else if (nuidPICC == 0xA3 && nuidPICC == 0x02 && nuidPICC == 0x27 && nuidPICC == 0x98)
{

    a_1 = 1;
    //这里要开门
}
//人员3
else if (nuidPICC == 0xFA && nuidPICC == 0x9D && nuidPICC == 0x61 && nuidPICC == 0xBF)
{

    a_1 = 1;
    //这里要开门
}
}
//注册+识别
void zhuce() {
if ( ! rfid.PICC_IsNewCardPresent())
    return;
if ( ! rfid.PICC_ReadCardSerial())
    return;
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); // 将NUID保存到nuidPICC数组
for (byte i = 0; i < 4; i++)
{
    nuidPICC = rfid.uid.uidByte;
}

printHex(rfid.uid.uidByte, rfid.uid.size); //Hex:16进制

printDec(rfid.uid.uidByte, rfid.uid.size); //Dec:10进制


// 使放置在读卡区的IC卡进入休眠状态,不再重复读卡,Halt(停止)
rfid.PICC_HaltA();
// 停止读卡模块编码
rfid.PCD_StopCrypto1();
}
void zhixing() {
if ((a_1 + a_2) >= 1) {
    digitalWrite(relay, 0);
    delay(3000);
    digitalWrite(relay, 1);
    a_1 = a_2 = 0;
}
else {
    digitalWrite(relay, 1);
}
if ((b_1 + b_2 + b_3) >= 1 and sss == 0) {
    digitalWrite(buzzer, 0);
}
else {
    digitalWrite(buzzer, 1);
}
}
void huoyan() {
if (digitalRead(flame) == 0) {
    delay(10);
    if (digitalRead(flame) == 0) {
      b_2 = 1;
      oled12864.setCursor(70, 2);
      oled12864.print("NO");

      //蜂鸣器
      digitalWrite(ESP8266_IN, 0);
    }
}
else {
    b_2 = 0;

    digitalWrite(ESP8266_IN, 1);
    oled12864.setCursor(70, 2);
    oled12864.print("OK");
    //蜂鸣器
}
}
void hongwai() {
if (digitalRead(renti) == 0) {
    delay(10);
    if (digitalRead(renti) == 0) {
      b_3 = 1;
      digitalWrite(ESP8266_OUT3, 0);
      oled12864.setCursor(42, 3);
      oled12864.print("有人入侵");

    }
}
else {
    b_3 = 0;

    digitalWrite(ESP8266_OUT3, 1);
    oled12864.setCursor(42, 3);
    oled12864.print("         ");
}
}
void ESP8266() {
if (digitalRead(ESP8266_OUT1) == 0) {
    delay(10);
    if (digitalRead(ESP8266_OUT1) == 0) {
      a_2 = 1;

    }
}
else {
    a_2 = 0;

}
if (digitalRead(ESP8266_OUT2) == 0) {
    delay(10);
    if (digitalRead(ESP8266_OUT2) == 0) {
      sss = 1;

    }
}
else {
    sss = 0;

}
}
void loop() {
zhuce();
zhixing();
MQ_2();
zhixing();
huoyan();
hongwai();
ESP8266();
zhixing();
}

myself1820 发表于 2022-5-8 13:32

努力编程小阿格 发表于 2022-5-4 17:49
大佬,您看我这个程序怎么改正呀,我对比了您的代码和我的,我不太会改正。这是uno采集数据串口通信向esp ...

你把人体红外、火焰传感器的变量逐个通过Serial.print();函数打印就可以了,记得每两个变量之家加英文的逗号
void Send_Data()
{   
      espSerial.print('W');   
      espSerial.print(Temp_val_amplify);    //串口输出温度值
      espSerial.print(',');
      espSerial.print('H');
      espSerial.print(FD_averge);    //串口输出火焰传感器值
      espSerial.print(',');
      espSerial.print('T');
      espSerial.print(MQ4_averge);    //串口输出天然气传感器值
      espSerial.print(',');
      espSerial.print('Y');
      espSerial.print(MQ135_averge);    //串口输出烟雾报警器值
      espSerial.println('\n');
}

努力编程小阿格 发表于 2022-5-8 20:57

myself1820 发表于 2022-5-8 13:32
你把人体红外、火焰传感器的变量逐个通过Serial.print();函数打印就可以了,记得每两个变量之家加英文的 ...

好的 多谢大佬 我仔细改改
页: [1]
查看完整版本: UNO+ESP8266+Blinker