#include "BluetoothSerial.
h"
// 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 ledPin1 = 25;
const int ledPin2 = 32;
// Handle received and sent messages
String message = "";
char incomingChar;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
Serial.begin(115200);
// Bluetooth device name
SerialBT.begin("bimoalifwijaya");
Serial.println("The device started, now you can pair it with bluetooth!");
void loop() {
// 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 =="on"){
digitalWrite(ledPin1, HIGH);
if (message =="onn"){
digitalWrite(ledPin2, HIGH);
else if (message =="off"){
digitalWrite(ledPin1, LOW);
else if (message =="offf"){
digitalWrite(ledPin2, LOW);
delay(20);