Bluetooth Enabled Messaging Device Code

 #include <LiquidCrystal.h>

#include "BluetoothSerial.h"


// Initialize the LCD with the numbers of the interface pins

LiquidCrystal lcd(4, 5, 18, 19, 21, 22);


// Create a BluetoothSerial object

BluetoothSerial SerialBT;


void setup() {

  // Initialize serial communication for debugging

  Serial.begin(115200);


  // Initialize Bluetooth

  SerialBT.begin("ESP32_Chat_Device"); // Bluetooth device name


  // Initialize the LCD

  lcd.begin(16, 2);

  lcd.clear();


  // Print a message to the LCD

  lcd.setCursor(0, 0);

  lcd.print("Waiting for");

  lcd.setCursor(0, 1);

  lcd.print("message...");

}


void loop() {

  // Check if a Bluetooth message is available

  if (SerialBT.available()) {

    String message = SerialBT.readStringUntil('\n');


    // Print the received message to the LCD

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print("Message:");

    lcd.setCursor(0, 1);

    lcd.print(message);


    // Also print the message to the Serial Monitor

    Serial.println("Received: " + message);

  }


  // Add a small delay to avoid overwhelming the loop

  delay(100);

}


Comments

Popular posts from this blog

ESP32 Wi-Fi Extender Code