Get to Know ESP32 #6: Bluetooth

Audrey Betsy Rumapea
2 min readMar 2, 2020

--

Welcome aboard!

These are the equipments you’re going to need:

  • 1 PC/Laptop
  • 1 Breadboard
  • 1 NodeMCU ESP-32S Development Board
  • Wire Jumpers
  • 1 DHT22
  • 1 LCD
  • 1 USB-A to MicroUSB cable

Then, I made a circuit that looked like this.

This is how my code looked like. In the initial experiment, my team used three different files but with my friend’s help, we changed the program and combined those three programs into one. Fortunately, the project suceed.

#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT11 // DHT 11
#include <LiquidCrystal_I2C.h>
DHT dht(DHTPIN, DHTTYPE);
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
#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;void setup() {
dht.begin();
Serial.begin(115200);
SerialBT.begin("JJS"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
lcd.begin(16,2);
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop() {
lcd.clear();
String message;
if (SerialBT.available()) {
message = "";
lcd.clear();
while(SerialBT.available()){
char incomingChar = SerialBT.read();
message += String(incomingChar);
}
}
// Display Text
lcd.setCursor(0,0);
lcd.print(message);
Serial.println(message);

delay(3000);

lcd.clear();
lcd.clear();

//SENSOR
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
SerialBT.print(F("Humidity: "));
SerialBT.print(h);
SerialBT.println(F("%"));
SerialBT.print(F("Temp: "));
SerialBT.print(t);
SerialBT.println(F(" C"));
delay(1000);

}

And this was how my project went.

Make sure to drop comments if you need help with this project. Adios, see you!

--

--

No responses yet