一、ESP32Cam引脚示意图
二、ArduinoIDE程序编写
public.h
#ifndef _public_H
#define _public_H
#include "Arduino.h"
//类型重定义
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
#endif
main.c
#include "public.h"
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
#define LED1 4
char buf[9];
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
//设置LED1引脚为输出模式
pinMode(LED1, OUTPUT);
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
// Serial.write(SerialBT.read());
for(u8 i=0;i<9;i++)
{
buf[i]=SerialBT.read();
Serial.print(buf[i]); //串口输出蓝牙接收数据
}
if(buf[0]=='o' && buf[1]=='n')
digitalWrite(LED1, HIGH);//LED1引脚输出高电平,点亮
else if(buf[0]=='o' && buf[1]=='f' && buf[2]=='f')
digitalWrite(LED1, LOW);//LED1引脚输出低电平,熄灭
}
delay(20);
}
最后打开蓝牙调试助手连接ESP8266test并且波特率设置为115200,发送on打开LED发送off关闭LED。