#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial BTSerial(11, 10); // RX, TX
void setup()
{
// Initialize the LCD display
lcd.init();
// Turn on the backlight
lcd.backlight();
// Set the cursor to the first column of the first row
lcd.setCursor(0, 0);
Serial.begin(9600); // Start the serial communication
BTSerial.begin(9600); // Start the serial communication over Bluetooth
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Send Number:”);
while (!BTSerial.available()); // Wait until data is available
// Set pin modes
pinMode(2, OUTPUT); // Set pin 2 as an output to control the LED
pinMode(3, OUTPUT); // Set pin 3 as an output to control the fan
}
void loop()
{
// Check if there is data available on the serial port
if (BTSerial.available()) {
Serial.println(“available”);
String input = BTSerial.readStringUntil(‘\n’); // Read the data until newline
input.remove(input.length() – 1); // Remove the newline character
Serial.println(input); // Print the input data to the Serial Monitor
lcd.clear(); // Clear the LCD display
if (input.length() <= 16) {
lcd.setCursor(0, 0); // Set cursor to the first column of the first row
lcd.print(input); // Print the input string on the LCD display
} else {
lcd.setCursor(0, 0); // Set cursor to the first column of the first row
lcd.print(input.substring(0, 16)); // Print the first 16 characters
lcd.setCursor(0, 1); // Set cursor to the first column of the second row
lcd.print(input.substring(16)); // Print the remainder of the string
}
// Additional functionality
if (input == “1”) {
digitalWrite(2, HIGH); // Turn on the LED
lcd.clear();
lcd.setCursor(0, 1); // Set cursor to the first column of the second row
lcd.print(“Switch Lamp”); // Display message for lamp
delay(2000);
lcd.clear();
} else {
digitalWrite(2, LOW); // Turn off the LED
}
if (input == “2”) {
digitalWrite(3, HIGH); // Turn on the fan
lcd.clear();
lcd.setCursor(0, 1); // Set cursor to the first column of the second row
lcd.print(“Switch Fan”); // Display message for Fan
delay(2000);
lcd.clear();
} else {
digitalWrite(3, LOW); // Turn off the fan
}
}
}