Friday, December 6, 2024

Home Automation using Bluetooth of ESP32 with Videos (Hindi & English)

- Advertisement -

[defineweblang title=”Change Video Language” language=”English,Hindi”]

[getvideolang url= “https://www.youtube.com/embed/zZUs_GRprpY” language=”English”][/getvideolang]

[getvideolang url= “https://www.youtube.com/embed/zhRBOhu8T0g” language=”Hindi”][/getvideolang]

- Advertisement -

[/defineweblang]

In this project, we will be dealing with the inbuilt Bluetooth feature in ESP32 Development board and try to build an application around it. The Bluetooth system can be divided into two different categories: Classic Bluetooth and Bluetooth Low Energy (BLE). ESP32 supports dual-mode Bluetooth, meaning that both Classic Bluetooth and BLE are supported by ESP32. Here, we will control General Purpose Input Output (GPIO) pins of the ESP32 board using Bluetooth in classic mode and a customized Android application.

For more documentation, you can refer to Espressif IoT Development Framework here.  So, let’s get started.

Material required for the Bluetooth project

1. ESP32 NodeMCU (Check the datasheet, if you are using a different version.)

Fig. 2: ESP32

2. USB Type C cable to program ESP32 from a laptop or PC (most Android phones use this type of cable).

Fig. 3: USB Cable

3. LED with Resistor(1K) – To test the Bluetooth

Fig. 4: LED with a resistor

4. Breadboard – To place the components

Fig. 5: Breadboard

Steps for the ESP32 support in Arduino IDE:

(Ignore this step if you already have the setup of ESP boards in Arduino IDE)

Fig. 6: ESP32 support in Arduino IDE

Here, to program the ESP32 we need an Integrated Development Environment and we will use Arduino IDE software. Arduino IDE is a cross-platform application. It is written in Java and coded in C/C++ with some special rules. To download the latest Arduino IDE from here.

Arduino IDE does not contain support of ESP32 family so to install the ESP-32 Board in Arduino IDE, you can refer here.

The Code for Bluetooth in ESP32

Download the Code from the link below and Open it in Arduino IDE. Let’s understand the code.

Fig. 7: Code declarations

Firstly, we will declare the Bluetooth libraries in the code. All the declaration like Led pin, states and UUIDs are declared here. To have more details on UUID refer here.

Fig. 8: Classes

Then, we will create two classes. MyServerCallbacks is created to check the server connection and MyCallbacks to perform the various functions.

Hence, this function contains the LED controlling part of the Bluetooth and prints the value received. One may also include some inputs to fetch data like temperature or humidity. The android application will give commands like “A” and “B” which will be received by the ESP-32 BLE and will generate the same results. These classes are created to call in the Void Setup() and most of the part of the code is set up here only.

Fig. 9: Void Setup()

All the characteristics of Bluetooth and device name will be declared here including the start of various services like UART and BLE Server.

The baud rate is by default set to 115200  and pin 5 declared as LED will be set to OUTPUT.

Circuit Connections:

There is only one Output (LED) in the circuit you can add many more outputs or set inputs.

ESP32 Pin 5 -> Resistor

Resistor -> LED +ve

LED -ve -> Ground

Fig. 10: Connections

Using the Android Application:

You can download the android application from here(.apk download link) and use it or edit this using Thunkable.

Fig. 11: Thunkable

We have created this app for the ESP Bluetooth and you may use it to control the LED or Light.

Fig. 12: App Interface

Turn On your phone’s Bluetooth and then start the app. Click Connect and choose the device you named in the code.

Fig. 13: Connect Bluetooth

After connecting the app interface will get active by changing its colour you can turn On and Off the Led.

Fig. 14: App Interface

 

Fig. 15: App Interface 3

Assemble everything and try this out.

Fig. 16: Circuit on the breadboard
Fig. 17: Initial testing with the LED

Let’s try it out with a relay and control an AC bulb. For relay connections, you can refer here.

Fig. 18: Testing with AC bulb

Download Source Code & .apk file here.

Components for this project can be purchased from kitsNspares.


3 COMMENTS

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics