INTERFACE ESP8266-01 WITH ARDUINO

F3QKTBHILCN3NKW.MEDIUM.jpg

Many ESP8266 have some problems with connecting to arduino. So it can be resolved by flashing the latest AT-firmware into it. Click here to see how to flash ESP8266-01.

CIRCUIT DIAGRAM:

ESP.png

PROGRAM:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#define TIMEOUT 5000 // mS
#define LED 13
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
 
void setup()
{
 pinMode(LED,OUTPUT);
 
 Serial.begin(9600);
 mySerial.begin(9600);
 SendCommand("AT+RST", "Ready");
 delay(5000);
 SendCommand("AT+CWMODE=3","OK");
 SendCommand("AT+CIFSR", "OK");
 SendCommand("AT+CIPMUX=1","OK");
 SendCommand("AT+CIPSERVER=1,80","OK");
}
 
void loop(){
 
 String IncomingString="";
 boolean StringReady = false;
 
 while (mySerial.available()&gt;0){
 IncomingString=mySerial.readString();
 StringReady= true;
 }
 
 if (StringReady){
 Serial.println("Received String: " + IncomingString);
 
 if (IncomingString.indexOf("LED=ON") != -1) {
 digitalWrite(LED,HIGH);
 mySerial.println("AT+CIPSEND=0,20");
 mySerial.println("&lt;h1&gt;LED IS ON!&lt;/h1&gt;");
 delay(1000);
 SendCommand("AT+CIPCLOSE=0","OK");
 }
 if (IncomingString.indexOf("LED=OFF") != -1) {
 digitalWrite(LED,LOW);
 mySerial.println("AT+CIPSEND=0,20");
 mySerial.println("&lt;h1&gt;LED IS OFF!&lt;/h1&gt;");
 delay(1000);
 SendCommand("AT+CIPCLOSE=0","OK");
 }
 }
 }
 
boolean SendCommand(String cmd, String ack){
 mySerial.println(cmd); // Send "AT+" command to module
 if (!echoFind(ack)) // timed out waiting for ack string
 return true; // ack blank or ack found
}
 
boolean echoFind(String keyword){
 byte current_char = 0;
 byte keyword_length = keyword.length();
 long deadline = millis() + TIMEOUT;
 while(millis() &lt; deadline){
 if (mySerial.available()){
 char ch = mySerial.read();
 Serial.write(ch);
 if (ch == keyword[current_char])
 if (++current_char == keyword_length){
 Serial.println();
 return true;
 }
 }
 }
 return false; // Timed out
}

AT COMMANDS:

Command Response Function
AT+RST OK Reset the module
AT+CWMODE=mode OK Set the correct Mode required

mode: An integer designating the mode of operation either 1, 2, or 3.
1 = Station mode (client)
2 = AP mode (host)
3 = AP + Station mode

AT+CIFSR +CIFSR:ip OK Get local IP address.
AT+CIPMUX=mode OK Enable / disable multiplex mode (up to 4 conenctions)

mode:

  • 0: Single connection
  • 1: Multiple connections (MAX 4)
AT+CIPSERVER=mode

[,port]

OK Configure ESP8266 as server

mode:

  • 0: Delete server (need to follow by restart)
  • 1: Create server
  • port: port number, default is 333
AT+CIPSEND=id,length SEND OK Set length of the data that will be sent.

  • id: ID no. of transmit connection
  • length: data length, MAX 2048 bytes
AT+CIPCLOSE=id OK Close TCP or UDP connection.

  • id: ID no. of transmit connection

RESULTS:

Thankyou
SHARE THIS!!!

Gowtham S

Gowtham is a programming enthusiast. His field of interest includes Arduino, NodeMCU, Raspberry Pi, and Python. To know more about him visit https://mybtechprojects.tech/about-us/.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.