Professional Documents
Culture Documents
● A feature-rich MCU with integrated Wi-Fi and Bluetooth connectivity for a wide range of applications such as
● The ESP32 is actually cheaper than Arduino Uno, which means that you get a more powerful board for a lower
price.
● In particular, ESP32 has built-in dual-mode WiFi and Bluetooth that allows us to transfer data to the network or
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
#define OLED_RESET 4
String x = Serial.readString();// Biến x lưu chuỗi dữ liệu được nhập từ
Adafruit_SSD1306 display(OLED_RESET); Serial
Serial.begin(9600); display.clearDisplay();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Khởi tạo OLED với địa chỉ 0x3C. display.setCursor(0,0);
display.setTextSize(1);// Thiết lập kích thước kí tự bằng 1. display.display();// Hiển thị dữ liệu nhận được lên màn hình OLED.
display.setTextColor(WHITE);// Thiết lập màu chữ là màu trắng.
}
display.setCursor(28,12);// Thiết lập con trỏ tại vị trí cột 28 hàng 12.
}
display.println("Hello World!");// Thiết lập chuỗi cần in là "Hello World!".
}
V. OLED & Sensor Combination
Wiring Diagram
void setup(){
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
#include <Adafruit_MLX90614.h>
Serial.println("Cam bien nhiet do MLX90614");
#include <Adafruit_GFX.h>
pinMode(bt, INPUT_PULLUP);
#include <Adafruit_SSD1306.h>
display.clearDisplay();
#define SCREEN_WIDTH 128
display.setCursor(25, 15);
#define SCREEN_HEIGHT 64
display.setTextSize(1);
delay(5000);}
void loop() void display_temp_obj()
{ {
temp_amb = mlx.readAmbientTempC(); display.clearDisplay();
temp_obj = mlx.readObjectTempC(); display.setCursor(25, 10);
display.setTextSize(1);
//Serial Monitor display.setTextColor(WHITE);
display.println(" Nhiet do Obj");
if (digitalRead(bt) == LOW) display.setCursor(25, 30);
{ display.setTextSize(2);
display_temp_obj(); display.print(temp_obj);
delay(1000); display.print((char)247);
} display.print("C");
else { display.display();
Serial.print("Nhiet do phong = "); }
Serial.println(temp_amb);
Serial.print("Nhiet do doi tuong = ");
Serial.println(temp_obj);
display.clearDisplay();
display.setCursor(25, 10);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Nhiet do phong");
display.setCursor(25, 30);
display.setTextSize(2);
display.print(temp_amb);
display.print((char)247);
display.print("C");
display.display();
}
delay(1000);
}
VI. Introduction to Blynk App
Create an account in Blynk IoT Cloud Platform
● https://blynk.cloud/dashboard/register ● Enter your email ID and click on Sign Up. After
that, you will receive a verification email from
Blynk. In that email click on Create Password to
set the password for Blynk cloud account.
Create Template in Blynk IoT Cloud
● After login to Blynk IoT account, first you have create a template. In the dashboard click on the Templates from the
left side menu
● Then click on New Template. ● Give the template a name, choose ESP32 on
Hardware and Wifi on Connection Type.
1. Install the Blynk IoT NEW app from Google Play Store or App Store. Then log in to the Blynk IoT Platform.
3. Tap on the template which you have already made in Blynk cloud.
4. Now tap on the plus icon (on the right) to add widgets.
How to install new Blynk Library for Arduino IDE?
● In Arduino IDE go to Sketch — Include Library — Manage Libraries to open the Library manager. Then search
for Blynk in the search box. Then click on Install to install the Blynk Library (Current version 1.0.0). After that, you
can access all the Blynk Edgent examples code for ESP32 from File — Examples — Blynk — Blynk.Edgent path.
How to install new Blynk Library for Arduino IDE?
● Access https://github.com/blynkkk/blynk-library and Download Zip
● Install the library from Sketch — Include Library — Add .ZIP Library path in Arduino IDE.
● Browse to the folder where you download the library Zip file and click Open.
Wiring Diagram
How to get the BLYNK TEMPLATE ID and BLYNK DEVICE NAME
● Go to your Blynk IoT Cloud account and select the template. In the template go to the Info tab. On the right side,
you will find the BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME for that template. Click on “Click to copy
code”, then go to Arduino IDE and paste it into the code.
Source Code
#define BLYNK_TEMPLATE_ID "TMPL3PsNlMWb" BLYNK_WRITE(V1)
#define BLYNK_DEVICE_NAME "LED on off" {
// The 2 red lines are copied from the website like the int pinValue = param.asInt(); //Assigning incoming
previous slide value from pin V1 to a variable
#define BLYNK_FIRMWARE_VERSION "0.1.0" digitalWrite(2,pinValue);
}
#define BLYNK_PRINT Serial void setup()
//#define BLYNK_DEBUG {
pinMode(2,OUTPUT);
#define APP_DEBUG Serial.begin(115200);
delay(100);
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7 BlynkEdgent.begin();
}
#include "BlynkEdgent.h"
void loop() {
BlynkEdgent.run();
}
Connect Mobile Blynk App to ESP32
Finally, we can control the LED by tap on the
Button on our smartphone
Video Reference
● https://youtu.be/IKbbvEzZ7wg