#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
BluetoothSerial SerialBT;
int received;
char receivedChar;
const char turnON ='1';
const char turnOFF ='0';
const int servo = 23;
void setup() {
Serial.begin(9600);
SerialBT.begin("logee");// set your willing name
Serial.println("The device started, now you can pair it with bluetooth!");
//Serial.println("To turn ON send: a");//print on serial monitor
//Serial.println("To turn OFF send: b"); //print on serial monitor
pinMode(servo, OUTPUT);
}
void loop() {
receivedChar =(char)SerialBT.read();
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
SerialBT.print("Received:");// write on BT app
SerialBT.println(receivedChar);// write on BT app
Serial.print ("Received:");//print on serial monitor
Serial.println(receivedChar);//print on serial monitor
//SerialBT.println(receivedChar);//print on the app
//SerialBT.write(receivedChar); //print on serial monitor
if(receivedChar == turnON)
{
SerialBT.println("MOTOR ON:");// write on BT app
Serial.println("MOTOR ON:");//write on serial monitor
digitalWrite(servo, HIGH);// turn the LED ON
}
if(receivedChar == turnOFF)
{
SerialBT.println("MOTOR OFF:");// write on BT app
Serial.println("MOTOR OFF:");//write on serial monitor
digitalWrite(servo, LOW);// turn the LED off
}
}
delay(20);
}