4. Smartfoningizda bluetooth-ni yoqing va ESP32-ni ulang.
Smartfonni ESP32test bilan ulang
5. ESP32 ga ulaning.
Ilovani oching > ESP32test-ni bosing > Quyidagi rasmda aylanada joylashgan yuqori tugmani bosing. Keyin siz "Ulangan" xabarini olishingiz kerak.
ESP32 testiga ulangan
6. Ikki qurilma oʻrtasida xabar almashishga harakat qiling.
Serial Bluetooth Terminal ilovasida biror narsa yozing va siz bu xabarni darhol Arduino IDE Serial Monitor-da olishingiz kerak. Shuningdek, siz xabarni Serial Monitordan yuborishingiz va ushbu xabarni smartfoningizdagi Serial Bluetooth Terminal ilovasida bir zumda olishingiz mumkin.
E SP32 uchun smartfon
Smartfon uchun ESP32
-loyiha : Smartfondan LEDni yoqish va o'chirish
Loyihaning ikkinchi qismi uchun quyidagi amallarni bajaring!
1 . Quyidagi ilova qilingan rasmga muvofiq sxemani joylashtiring.
LED bilan sxematik tartibga solish
Pinout:
ESP32 GND pin - Breadboard salbiy qutb
ESP32 3V3 pin - Breadboard musbat qutb
ESP32 GPIO5 pin - LED musbat pin
LED salbiy pin - Breadboard salbiy qutb
Sizning tartibingiz shunday ko'rinishi kerak.
M alumot uchun mening kelishuvim2. Serial Bluetooth Terminal ilovasining M1 va M2 tugmalarining qiymatini o'rnating.M1 va M2 tugmalarining qiymatini o'rnating
3. Quyidagi kodni nusxalash, kompilyatsiya qilish va yuklash.
#include
// Check if Bluetooth configs are enabled
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
// Bluetooth Serial object
BluetoothSerial SerialBT;
// GPIO where LED is connected to
const int ledPin = 5;
// Handle received and sent messages
String message = "";
char incomingChar;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
// Bluetooth device name
SerialBT.begin("ESP32");
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
unsigned long currentMillis = millis();
// Read received messages (LED control command)
if (SerialBT.available()){
char incomingChar = SerialBT.read();
if (incomingChar != '\n'){
message += String(incomingChar);
}
else{
message = "";
}
Serial.write(incomingChar);
}
// Check received message and control output accordingly
if (message == "led_on"){
digitalWrite(ledPin, HIGH);
}
else if (message == "led_off"){
digitalWrite(ledPin, LOW);
}
delay(20);
}
Dostları ilə paylaş: |