Home ARDUINO How to Program ESp8266 Esp01 with Arduino UNO

How to Program ESp8266 Esp01 with Arduino UNO

326
0
How to Program ESp8266 Esp01 with Arduino UNO

How to Program ESp8266 Esp01 with Arduino UNO

ESP8266 ESP-01 is a Wi-Fi module that allows microcontrollers access to a Wi-Fi network and we can program it with different sensors. This module Esp01 is a self-contained SOC (System On a Chip) which mean we did want another microcontroller we can control it with different sensors that don’t essentially need a microcontroller to manipulate inputs and outputs as you would normally do with an Arduino UNO or with other Similar, for example, because the ESP-01 acts as a small computer which has Wi-Fi and processor with small ram.

And it is depending upon the version of the ESP8266, it is possible to have up to 9 GPIOs (General Purpose Input Output) which is contained in the node MCU Micro Controllers. Thus, we can give a microcontroller internet access like the Wi-Fi shield does to the Arduino UNO or other Micro Controller which act like a controller, or we can simply program the ESP8266 to not only have access to a Wi-Fi network that means we can just program the esp01 for itself. For Example, we can blink the LED or Communicate the sensors between one Arduino to the web, but to act as a microcontroller as well. This makes the ESP8266 very adaptable, and it can save some money and space for your projects.

In this article, we are going to learn how to set up the ESP-01 Wi-Fi module, configure it, and verify that there is communication established between the module, sensor, and another device.

Step 1

 Collect the Hardware

These are the components that you will need:

Step 2

Setup the Hardware

Add the LED and button to the wiring setup from the previous tutorial as shown in the images above.

Note that TX and RX from the ESP-01 are now connected to pins 7 and 6 correspondingly.

Step 3

Upload Coding

//Techincalustaad.com
//Esp01

#include <SoftwareSerial.h>

#define TIMEOUT 5000 // mS

#define LED 5

SoftwareSerial mySerial(7, 6); // RX, TX

const int button = 11;

int button_state = 0;

 

void setup()

{

pinMode(LED,OUTPUT);

pinMode(button,INPUT);

Serial.begin(9600);

mySerial.begin(9600);

SendCommand(“AT+RST”, “Ready”);

delay(5000);

SendCommand(“AT+CWMODE=1″,”OK”);

SendCommand(“AT+CIFSR”, “OK”);

SendCommand(“AT+CIPMUX=1″,”OK”);

SendCommand(“AT+CIPSERVER=1,80″,”OK”);

}

 

void loop(){

button_state = digitalRead(button);

 

if(button_state == HIGH){

mySerial.println(“AT+CIPSEND=0,23″);

mySerial.println(”

Button was pressed!

“);

delay(1000);

SendCommand(“AT+CIPCLOSE=0″,”OK”);

}

 

String IncomingString=””;

boolean StringReady = false;

 

while (mySerial.available()){

IncomingString=mySerial.readString();

StringReady= true;

}

 

if (StringReady){

Serial.println(“Received String: ” + IncomingString);

 

if (IncomingString.indexOf(“LED=ON”) != -1) {

digitalWrite(LED,HIGH);

}

 

if (IncomingString.indexOf(“LED=OFF”) != -1) {

digitalWrite(LED,LOW);

}

}

}

 

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() < 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

}

Step 4

Result of Serial Monitor

Once we upload the code, we can open the serial monitor. We will get the information shown in the image above. This means that the configuration of the ESP was successful, and it is ready to be used as a server. If you do not know how to open Serial Monitor then follow this short key
Ctrl+Shift+M

Now we can open a web browser and type either of the following lines shown above in the screenshot images of the browser windows.

The first line is used to turn the LED on, and the second line is used to turn the LED off. The images above show the lines written into the browser as well as the corresponding action that occurs on the breadboard.

If we press the button, we get the following message in our web browser’s window.

DONE!

Conclusion

Now you can manipulate inputs and outputs via Wi-Fi using the Arduino UNO and the ESP-01 module in the ESP8266 series. If you have any question, then please do let me know.

You may also like to read these articles

Build Your Own Vehicle Tracking System using Arduino (Start with Sim808 )

How to Make Radar Detector with Arduino and Ultra Sonic Sensor

Hope my article “How to Program ESp8266 Esp01 with Arduino UNO ” helps you to Program ESp8266 Esp01 with Arduino UNO. if you have any query, feel free to comment.

Advertisements

LEAVE A REPLY

Please enter your comment!
Please enter your name here

17 − twelve =