ESP32 board: Turn ON and OFF 3 LED using Bluetooth from mobile device
ESP32 board: Turn ON and OFF 3 LEDs using Bluetooth from mobile device
This this video how to start using ESP32 to turn ON/OFF one or more LED using your smartphone
To learn how to control 1 LED see This page
The link to use in the "preferences" of Arduino IDE for ESP32 board https://dl.espressif.com/dl/package_esp32_index.jsonResources for this sketch
Arduion Code
/*
* Turn LED ON or OFF from your phone
*
* Using ESP32's Bluetooth and Mobile app
* turn ON and OFF LED
*
* Updated/Written by Ahmad Shamshiri
* On August 25, 2019 in Ajax, Ontario, Canada
* Watch video instruction for this cod:
* https://youtu.be/4OOFlS75owA
* www.Robojax.com
*
Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
/*
* Turn LED ON or OFF 3 LED from your phone
*
* Using ESP32's Bluetooth and Mobile app
* turn ON and OFF LED for 3 LED
*
* Updated/Written by Ahmad Shamshiri
* On August 25, 2019 in Ajax, Ontario, Canada
* Upldated for 3 LED on Aug 24, 2021
* Watch video instruction for this code:
* https://youtu.be/4OOFlS75owA
* www.Robojax.com
*
Get this code and other Arduino codes from Robojax.com
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can get early access to my videos via Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
#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;// received value will be stored in this variable
char receivedChar;// received value will be stored as CHAR in this variable
const char turnON1 ='a';
const char turnOFF1 ='b';
const int LEDpin1 = 23;
const int LEDpin2 = 22;
const char turnON2 ='c';
const char turnOFF2 ='d';
const int LEDpin3 = 20;
const char turnON3 ='e';
const char turnOFF3 ='f';
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32_Robojax"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(LEDpin1, OUTPUT);
pinMode(LEDpin2, OUTPUT);
pinMode(LEDpin3, 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 == turnON1)
{
SerialBT.println("LED1 ON:");// write on BT app
Serial.println("LED1 ON:");//write on serial monitor
digitalWrite(LEDpin1, HIGH);// turn the LED ON
}
if(receivedChar == turnON2)
{
SerialBT.println("LED2 ON:");// write on BT app
Serial.println("LED2 ON:");//write on serial monitor
digitalWrite(LEDpin2, HIGH);// turn the LED ON
}
if(receivedChar == turnON3)
{
SerialBT.println("LED3 ON:");// write on BT app
Serial.println("LED3 ON:");//write on serial monitor
digitalWrite(LEDpin3, HIGH);// turn the LED ON
}
if(receivedChar == turnOFF1)
{
SerialBT.println("LED1 OFF:");// write on BT app
Serial.println("LED1 OFF:");//write on serial monitor
digitalWrite(LEDpin1, LOW);// turn the LED off
}
if(receivedChar == turnOFF2)
{
SerialBT.println("LED2 OFF:");// write on BT app
Serial.println("LED2 OFF:");//write on serial monitor
digitalWrite(LEDpin2, LOW);// turn the LED off
}
if(receivedChar == turnOFF3)
{
SerialBT.println("LED3 OFF:");// write on BT app
Serial.println("LED3 OFF:");//write on serial monitor
digitalWrite(LEDpin3, LOW);// turn the LED off
}
}
delay(20);
}