WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11

hussain0075468 146 views 27 slides Apr 25, 2024
Slide 1
Slide 1 of 27
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27

About This Presentation

ESP01 WIFI module interfacing with Arduino and with Sensor DHT11 module


Slide Content

Showcased by: Hussain S
Enroll no. 2021BTBME009
1
INTERFACING OF
WIFI-MODULE
WITH ARDUINO

Objective
https://eldontronics.wordpress.com
/wp-
content/uploads/2017/08/img_4189
.jpg
The ESP-01 module's primary
goal is to make adding Wi-Fi to
electronic projects simple and
affordable.
It functions similarly to a tiny
chip that you can attach to other
electronic devices, such as
sensors or microcontrollers, to
enable wireless internet access.
Less expensive with less space
compatable
2

Core Components
Arduino Uno
http://image
WIFI Module: ESP01
http://image
3
DTH11 sensor
http://image

The Arduino Uno can be
programmed using the Arduino
software platform, which simplifies
the process of writing code for
controlling sensors, motors, lights,
and other electronic components.
The Arduino Uno is a popular
microcontroller board based on the
ATmega328P microcontroller
Arduino UNO
http://image
4

Features of Arduino UNO
The operating voltage is 5V
The recommended input voltage will range from 7v to 12V
The input voltage ranges from 6v to 20V
Digital input/output pins are 14
Analog i/p pins are 6
DC Current for each input/output pin is 40 mA
DC Current for 3.3V Pin is 50 mA
Flash Memory is 32 KB
SRAM is 2 KB
EEPROM is 1 KB
CLK Speed is 16 MHz
5

OTHER APPLICATIONS OF ARDUINO
Traffic Light Count Down Timer
Parking Lot Counter
Home Automation
Weighing Machines
Medical Instrument
Washing Machine
Microwave Over
Security Systems
CCTV Switchers
Advantages
No additional programmer/burner hardware is
required for the programming board
Portable
Low power consumption
6

The ESP01 WiFi module is
The ESP01 is a compact and power-efficient WIFI module that
seamlessly integrates with microcontrollers. It enables wireless
connectivity for a wide range of IoT and smart home applications.
http://image 7

8
Feature of ESP01
Compact size: Small footprint
GPIO Pins: GPIO pins for interfacing with sensors and peripherals.
power supply: 3.3 volts (V)
Serial communication: Utilizes UART for communication with
microcontrollers.
AT command support: Communicates with microcontroller via AT
commands
Cost-effective: Inexpensive

9
Applications
Home automation applications of
the ESP01
ESP01 module is widely used in IoT

10
Environmental Monitoring
Industrial control and monitoring
Wireless Control

Connection Description
VCC
Connect to a 3.3V
output from Arduino
GND
Connect to
Arduino's ground
TX
Connect Arduino's
TX pin to ESP-01's
RX pin
RX
Connect Arduino's
RX pin to ESP-01's
TX pin
11
ESP-01 Arduino Interfacing connection
Software Setup:
Install the Arduino IDE if you
haven't already.
Install the ESP8266 library in
Arduino IDE: Go to "Sketch" ->
"Include Library" -> "Manage
Libraries", then search for
"ESP8266" and install it.
Programming ESP-01
Communication with Arduino
Hardware Setup:
Note:
Remember to use a voltage divider or
level shifter

Code
#include<SoftwareSerial.h>
#include <Wire.h>
#include <DFRobot_DHT11.h>
SoftwareSerial comm(2, 3); //setting Tx and Rx pins
DFRobot_DHT11 DHT;
#define DHT11_PIN 11
String server = ""; //variable for sending data to webpage
boolean No_IP = false; //variable to check for ip Address
String IP = ""; //variable to store ip Address
char temp1 = '0';
int a = 0;
int b = 0;
String str1 = "<p>I am Arduino</p>"; //String to display on webpage
String str2 = "<p>Data Received Successfully.....</p>"; //another
string to
display on webpage
12

void setup()
{
Serial.begin(115200);
comm.begin(115200);
wifi_init();
Serial.println("System Ready..");
}
void loop()
{
int temperature = 0;
int humidity = 0;
DHT.read(DHT11_PIN);
Serial.print("Temperature: ");
Serial.print(DHT.temperature);
temperature = DHT.temperature;
Serial.print(" °C\Humidity: ");
Serial.print(DHT.humidity);
Serial.println(" %");
humidity = DHT.humidity;
13

sendDataToServer(temperature, humidity);
delay(10000);
}
void findIp(int time1) //check for the availability of IP Address
{
int time2 = millis();
while (time2 + time1 > millis())
{
while (comm.available() > 0)
{
if (comm.find("IP has been read"))
{
No_IP = true;
}
}
}
}
void showIP()//Display the IP Address
{
14

IP = "";
char ch = 0;
while (1)
{
comm.println("AT+CIFSR");
while (comm.available() > 0)
{
if (comm.find("STAIP,"))
{
delay(1000);
Serial.print("IP Address:");
while (comm.available() > 0)
{
ch = comm.read();
if (ch == '+')
break;
IP += ch;
15

}
}
if (ch == '+')
break;
}
if (ch == '+')
break;
delay(1000);
}
Serial.print(IP);
Serial.print("Port:");
Serial.println(80);
}
void establishConnection(String command, int timeOut) //Define the
process for
sending AT commands to module
{
int q = 0;
while (1)
16

Serial.println(command);
comm.println(command);
while (comm.available())
{
if (comm.find("OK"))
q = 8;
}
delay(timeOut);
if (q > 5)
break;
q++;
}
if (q == 8)
Serial.println("OK");
else
Serial.println("Error");
}
17

void wifi_init() //send AT commands to module
{
establishConnection("AT", 100);
delay(1000);
establishConnection("AT+CWMODE=3", 100);
delay(1000);
establishConnection("AT+CWQAP", 100);
delay(1000);
establishConnection("AT+RST", 5000);
delay(1000);
findIp(5000);
if (!No_IP)
{
18

Serial.println("Connecting Wifi....");
establishConnection("AT+CWJAP=\"hussain\",\"hussain97\"", 7000);
//provide your
WiFi username and password here
}
else
{
}
Serial.println("Wifi Connected");
showIP();
establishConnection("AT+CIPMUX=1", 100);
establishConnection("AT+CIPSERVER=1,80", 100);
}
void sendData(String server1)//send data to module
{
int p = 0;
while (1)
{
19

unsigned int l = server1.length();
Serial.print("AT+CIPSEND=0,");
comm.print("AT+CIPSEND=0,");
Serial.println(l + 2);
comm.println(l + 2);
delay(100);
Serial.println(server1);
comm.println(server1);
while (comm.available())
{
//Serial.print(Serial.read());
if (comm.find("OK"))
{
20

p = 11;
break;
}
}
if (p == 11)
break;
delay(100);
}
}
void sendToServer()//send data to webpage
{
server = "<h1>Welcome to Data Receiving from Arduino</h1>";
sendData(server);
server = str1;
server += str2;
sendData(server);
delay(5000);
comm.println("AT+CIPCLOSE=0");
}
21

void sendDataToServer(int temperature, int humidity) {
String server1 = "</p>";
server1 += "<p>Temperature: ";
server1 += temperature;
server1 += "</p>";
server1 += "<p>Humidity: ";
server1 += humidity;
server1 += "</p>";
sendData(server1);
}
22

Explanation
1. Libraries: The code includes libraries like SoftwareSerial for
communication, Wire for I2C communication, and DFRobot_DHT11 for
interacting with the DHT11 sensor.
2. Global Variables: Variables like server, No_IP, IP, temp1, a, b,
str1, and str2 are declared for various purposes including storing
server information, IP address, and strings for webpage display.
3. setup() Function: Initializes serial communication, initializes the
WiFi module, and prints a message to indicate system readiness.
4. loop() Function: Continuously reads temperature and humidity from
the DHT11 sensor, sends the data to the server, and then delays for 10
seconds before repeating.
23

5. findIp() Function: Checks for the availability of an IP address.
6. showIP() Function: Retrieves and displays the IP address.
7. establishConnection() Function: Sends AT commands to the WiFi
module and waits for the response.
8. wifi_init() Function: Initializes the WiFi module by sending a
series of AT commands, connecting to the WiFi network if an IP address
is available, and configuring the module for server communication.
9. sendData() Function: Sends data to the server using
the AT command AT+CIPSEND.
10. sendToServer() Function: Constructs and sends HTML-formatted data
to the server.
11. sendDataToServer() Function: Formats and sends temperature and
humidity data to the server.
24

Result

25

9. References
1. https://www.arduino.cc/
2. https://www.electronicwings.com/nodemcu
3.https://www.instructables.com/Connect-Arduino-Uno-With-ESP8266/
4. https://docs.arduino.cc/retired/boards/arduino-uno-wifi
Conclusion
The ESP-01 WiFi module's integration with the Arduino Uno provides an
easy and practical way to integrate wireless connectivity into
electronic projects. This improves these projects' usefulness and
adaptability and creates new opportunities for IoT, home automation,
and industrial control, among other industries. This integration has
the potential to completely change how electronic devices communicate
and interact with one another with the right setup and programming.
26

27