0% found this document useful (0 votes)
14 views22 pages

SCADA Group6 pp

Uploaded by

Thuận Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views22 pages

SCADA Group6 pp

Uploaded by

Thuận Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

The communication

PROTOCOL BY WIFI
MEMBERS:
Trầ n Thiên Thuận
Nguyễ n Sinh Tùng
Nguyễ n Bá Tiế n
Tôn Đứ c Thành
Lê Đứ c Anh
Đoàn Duy Thắng
Table of
CONTENTS
01 02 03 04
Overview Operating Product App support
principle details
OVERVIEW
Product This system is a temperature control relay and

INTRODUCTION monitoring device, which can be connected and


monitored from the Blynk application. The device uses a
DHT11 sensor to measure temperature and humidity,
displays the results on the LCD screen, and synchronizes
with the Blynk application for display and control. In
addition, the device can also control a push button to
relay information or through the Blynk application.
EVENT INTRODUCTION
ESP8266: This is the main control system, which is
capable of connecting to WiFi and sending/receiving
via the data network. It connects to other events such
as DHT11 sensors, relays, and LCD screens to perform
monitoring and control functions.

DHT11 sensor: Temperature and humidity sensor. This is a


popular sensor with relatively good accuracy in application
facilities, suitable for monitoring conditions.
EVENT INTRODUCTION
Relay: An electrical circuit closing device, used to control
larger operating devices. The relay in this system is
controlled by ESP8266 and can be turned on/off by
notification button or remotely controlled via Blynk.

LCD 16x2 I2C: The 16x2 LCD screen displays data


temperature and humidity, making it easy for users to
observe information directly from the device without
opening the application.

Push button: Used to control the relay operation. When the


button is pressed, the relay will change state (on or off).
OPERATING PRINCIPLE
The system operates based on the process of collecting data from sensor variables and
controlling relays, combined with the ability to remotely monitor via WiFi:
WiFi and Blynk connection: After being powered, the ESP8266 will connect to the WiFi network
and log in to the Blynk server with an authentication code.
Read data from the DHT11 sensor: The DHT11 sensor collects the ambient temperature and
humidity, sending the data to the ESP8266 via pin D5.
Relay controlled via Blynk and push button: The relay can be turned on/off by pressing the button
or from the Blynk application:
Display on LCD: The LCD screen updates the temperature and humidity from the sensor, making
it easy for users to observe the information directly.
This system helps monitor temperature, humidity and control devices remotely, suitable for
smart home applications, environmental monitoring or IoT infrastructure projects.
PRODUCT
DETAILS
CODE
CODE EXPLANATION
1, DEFINE CONSTANTS, LIBRARIES, AND CONNECTION INFORMATION
BLYNK_TEMPLATE_ID, BLYNK_TEMPLATE_NAME, and BLYNK_AUTH_TOKEN are used for device
authentication and identification with Blynk.
BLYNK_PRINT Serial allows Blynk messages to be printed to the Serial Monitor (useful for debugging)
ESP8266WiFi.h and BlynkSimpleEsp8266.h libraries help to connect the ESP8266 to Wi-Fi and Blynk.
DHT.h is a library for the temperature and humidity sensor (DHT).
Wire.h and LiquidCrystal_I2C.h are used for controlling the I2C LCD display.
CODE EXPLANATION
2, INITIALIZE VARIABLES FOR WI-FI, LCD, SENSOR, AND CONTROL PINS
Initializes lcd with I2C address 0x27, with 16
columns and 2 rows.
auth, ssid, and pass store connection information
for Blynk and Wi-Fi.
DHTPIN is the D5 pin, used to connect to the DHT
sensor.
button1_pin (D6) is the pin connected to the physical
push button.
relay1_pin (D7) is the pin for controlling the relay.
relay1_state stores the state of the relay (on or off).
button1_vpin (V2) is the virtual pin in Blynk to control
the relay from the app.
DHTTYPE specifies the type of sensor as DHT11.
CODE EXPLANATION
3, CONNECT AND SYNC WITH BLYNK

BLYNK_CONNECTED() is a Blynk function that gets called when the device connects successfully
to the Blynk server.
Blynk.syncVirtual(button1_vpin); synchronizes the relay control button's state from the Blynk app.
CODE EXPLANATION
4, HANDLE SIGNAL FROM BLYNK APP TO CONTROL RELAY

BLYNK_WRITE(button1_vpin) is called when the relay control button state changes in the Blynk
app.
param.asInt() gets the value from the app and stores it in relay1_state.
digitalWrite(relay1_pin, relay1_state); sets the relay state (on or off)
CODE EXPLANATION
5, SENDSENSOR() FUNCTION TO READ SENSOR DATA
AND UPDATE LCD AND BLYNK
sendSensor() reads the temperature t and humidity h from
the DHT sensor.
If the data is invalid (temperature or humidity is NaN), the
function exits without doing anything.
Blynk.virtualWrite(V0, t); and Blynk.virtualWrite(V1, h); send
the temperature and humidity data to Blynk through virtual
pins V0 and V1.
Updates the LCD display with temperature and humidity
values.
CODE EXPLANATION
6, SETUP FUNCTION IN SETUP()
Serial.begin(115200); initializes Serial to print data
to the computer screen.
pinMode(button1_pin, INPUT_PULLUP); sets the
button as INPUT_PULLUP.
pinMode(relay1_pin, OUTPUT); sets the relay as
OUTPUT.
digitalWrite(relay1_pin, HIGH); turns off the relay at
startup (output is HIGH)
Blynk.begin(auth, ssid, pass); connects to Wi-Fi and
Blynk
dht.begin(); initializes the DHT sensor
timer.setInterval(100L, sendSensor); calls
sendSensor() every 100ms to read sensor data and
update Blynk
CODE EXPLANATION
7, MAIN LOOP TO RUN BLYNK AND TIMER

Blynk.run(); maintains the connection with Blynk.


timer.run(); calls the timer functions (like sendSensor())
listen_push_buttons(); checks and processes the physical button.
CODE EXPLANATION
8, CHECK PHYSICAL BUTTON IN LISTEN_PUSH_BUTTONS()

If button1_pin is pressed (LOW), it calls control_relay(1) to toggle the relay state.


Blynk.virtualWrite(button1_vpin, relay1_state); updates the relay state in the Blynk app
to sync with the physical button
CODE EXPLANATION
9, CONTROL_RELAY(INT RELAY) FUNCTION TO CONTROL THE RELAY

control_relay() toggles the state of relay1_state.


digitalWrite(relay1_pin, relay1_state); sets the new relay state on the control pin.
delay(50); adds a short delay to debounce the button.
App
SUPPORT
Arduino IDE 2.3.3 is a significant
update of the popular integrated
development environment (IDE) for
Arduino boards. This version brings
many significant improvements
over previous versions, making the
process of programming and
developing Arduino projects more
efficient and enjoyable.
Blynk is an IoT platform that simplifies creating App
SUPPORT
applications to control and monitor devices
remotely. The system includes:
How It Works?
Connecting Devices: Users configure the device
with a token from the Blynk app, then connect it to
Wi-Fi.
Control & Monitoring: Users control the device and
receive real-time data through the Blynk app.
Virtual Pins: Used to send/receive data between
the device and app without physical wiring.
Applications
Blynk is commonly used in home automation,
environmental monitoring, and industrial IoT
projects.
Thanks for
WATCHING

You might also like