Printing Sensor Measurements via Bluetooth on ESP32 using Arduino IDE
Hello, again!
Welcome to another tutorial with me, the ESP32 and the Arduino IDE! :)
If you have been reading my previous articles in this blog you might already know that I am about to try out new stuff using the same basic equipments. So, today I will be sharing with you how to use the Bluetooth feature that is built in the ESP32 and also provided on the Arduino IDE. I will divide this post into two sections: Testing Bluetooth connection to Bluetooth Device and Integrating the DHT11 weather sensor together with an I2C LCD to a Bluetooth Device.
Okay, without further talking let us begin!
Section 1
Testing Bluetooth Connection to Bluetooth Device
In this section I will basically teach you how to use the Bluetooth feature, so if you're feeling confident about your skills in using this feature you can skip this section and scroll down to Section 2.
Step 1: Hardware Requirement
All we need is:
- 1 Laptop/PC
- 1 ESP32 Development Board
- 1 MicroUSB cable
- 1 Android Device
Basically, every software requirement needed is just the same as in the very first project I did called the "Blinking program". If you haven't checked it out, you can click here and look for Step 2: Software Requirement then come back and continue down below:
For the Bluetooth Device you will be using, you will need to download the following Android Application, which you can easily find on Google Play Store.
Step 3: Circuit
Since we are only testing the Bluetooth connection from the Bluetooth device to the ESP32, all you need to do is plug in the ESP32 to your computer.
Step 4: Code
Load this code on the Arduino IDE, which you can find under File > Examples > BluetoothSerial > SerialtoSerialBT.
Notice that in the SerialBT.begin() function you can name the your ESP device. In the loop procedure you can see how the program detects inputs coming either from the Serial Monitor on the Bluetooth Android Application or on the Serial Monitor in the Arduino IDE. If one of the conditions are fulfilled, the program commands to write the readings on the other Monitor.
Step 5: Compile, Upload & Observe
After you're done uploading the code, you can test out the Bluetooth connection by opening the Serial Monitor from Tools and press the Enable button on the ESP32. The underlined line should appear once the ESP32 Bluetooth is enabled and ready to connect to.
When this is done, open the Bluetooth application on your Android device and connect to the corresponding name of your ESP. Now you can start sending messages from one to the other Serial Monitor.
Section 2
Integrating the DHT11, an I2C LCD to a Bluetooth Device
Before we start this section, if you've never used the DHT11 weather sensor or an I2C LCD on the ESP32 before. You might want to check out my previous tutorials on them here and there.
This project is going to look a lot like my last article about: Printing Weather Sensor Measurements in I2C LCD on ESP32 using Arduino IDE. But this time, the weather measurements will be printed on your Android Device Serial Monitor and what you write into it will appear on the LCD.
Step 1: Hardware Requirement
What we will be using for this project is:
- 1 Laptop/PC
- 1 ESP32 Development Board
- 1 MicroUSB cable
- 1 Android Device
- Several Wire Jumpers (Male-Male & Female-Male)
- 1 DHT11 weather sensor
- 1 I2C LCD
- 1 BreadBoard
- 1 Resistor (330kOhm)
One more time, every software requirement needed is just the same as in the "Blinking program" I wrote before. If you haven't checked it out, you can click here and look for Step 2: Software Requirement then come back and continue down below:
For the Bluetooth Device you will be using, you will need to download the following Android Application, which you can easily find on Google Play Store.
Step 3: Circuit
Remake the circuit down below using the equipments you have prepared before.
If you have read my last article you might notice that this circuit is just the same.
Step 4: Code
This is the code I am using to make it happen.
Notice that I am converting the char readings from the Android device to strings that can be printed on the LCD.
Note: Always make sure to define the correct GPIO pin numbers you are using in your code.
Step 5: Compile, Upload & Observe
After building the circuit and finishing the code, you can move on to compiling and uploading the program. Check your Serial Monitor and press the Enable button on the ESP32 just like in Section 1. Then connect your Android the the ESP32 via the Bluetooth application and now you should be able to see the DHT11 measurements on your screen like on this picture.
Also, try typing a line as an input in the Bluetooth app, it will appear on the LCD like this.
That's it for this article!
See you next time:)
keren banget kaka, aku ngefans deh
ReplyDelete