In this illustration we will going to wire the ESP8266 Module on Arduino but before we can proceed we need to setup the ESP8266 module using AT-COMMAND please refer to this link. As you can see the illustration below our host control is the Arduino MCU board that controls the ESP8266 and the 4 channel relay.
By removing the ATMEGA328P Chip we consider that were going to use the TTL UART of the Arduino.
Sometimes the size of the message from ESP8266 is big for Arduino, you need to change the buffer which is defined in “HardwareSerial.h” it is located in directory “\arduino\hardware\avr\cores\arduino\HardwareSerial.h” and see the
“ #define SERIAL_BUFFER_SIZE 64” the default size of the buffer is 64 you need to change to bigger number, for example 256 or more.
Required Component
- Arduino UNO
- ESP8266 V1
- 4 Channel Relay Board or Shield
- Jumper Wires / DuPont Wires
- Solder Less Breadboard
- Home Appliance for Testing
- Android Phone or Tablet
Wiring Diagram Schematics
Arduino Sketch Code
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
/* ESP8266 library Connection: UNO board Connection ESP8266_TX->RX(Arduino Digital Pin 10) ESP8266_RX->TX(Arduino Digital Pin 11) ESP8266_CH_PD->3.3V ESP8266_VCC->3.3V ESP8266_GND->GND When you want to output the debug information, please use DebugSerial. For example, DebugSerial.println("hello"); */ //#define SSID "14CORE" //#define PASSWORD "14255252" #define SSID "14COREHOME" #define PASSWORD "25802514" #include "uartWIFIUNO.h" // Can be downloaded below on this page #include <SoftwareSerial.h> WIFIUNO wifi; extern int chlID; // set pin numbers: //const int ledPin = 13; // the number of the LED pin const int relay1 = 2; // Relay In 1 Defined at Arduino Pin 2 const int relay2 = 3; // Relay In 2 Defined at Arduino Pin 3 const int relay3 = 4; // Relay In 3 Defined at Arduino Pin 4 const int relay4 = 5; // Relay In 4 Defined at Arduino Pin 5 boolean device1 = false; boolean device2 = false; boolean device3 = false; boolean device4 = false; void setup(){ // pinMode(ledPin, OUTPUT); pinMode(relay1, OUTPUT); pinMode(relay2, OUTPUT); pinMode(relay3, OUTPUT); pinMode(relay4, OUTPUT); //pinMode(ESP8266_CHPD, OUTPUT); //digitalWrite(ESP8266_CHPD,LOW); digitalWrite(relay1,LOW); digitalWrite(relay2,LOW); digitalWrite(relay3,LOW); digitalWrite(relay4,LOW); DebugSerial.println("ESP8266 Server v0.21"); if(!wifi.begin()) { DebugSerial.println("Begin error"); } bool b = wifi.Initialize(STA, SSID, PASSWORD); if(!b) { DebugSerial.println("Init error"); } delay(8000); //make sure the module can have enough time to get an IP address String ipstring = wifi.showIP(); DebugSerial.println(ipstring); //show the ip address of module delay(1000); wifi.confMux(1); delay(100); if(wifi.confServer(1,80)) DebugSerial.println("Server is set up"); } void loop() { char buf[500]; int iLen = wifi.ReceiveMessage(buf); if(iLen > 0) { DebugSerial.print(buf); //delay(300); if (strncmp(buf, "GET /?status1=1", 15) == 0) { //DebugSerial.print("RELAY 1 ON"); digitalWrite(relay1, HIGH); device1 = true; } else if (strncmp(buf, "GET /?status1=0", 15) == 0) { //DebugSerial.print("RELAY 1 OFF"); digitalWrite(relay1, LOW); device1 = false; } if (strncmp(buf, "GET /?status2=1", 15) == 0) { //DebugSerial.print("RELAY 2 ON"); digitalWrite(relay2, HIGH); device2 = true; } else if (strncmp(buf, "GET /?status2=0", 15) == 0) { //DebugSerial.print("RELAY 2 OFF"); digitalWrite(relay2, LOW); device2 = false; } String cmd; cmd = "HTTP/1.1 200 OK\r\n"; cmd += "Content-Type: text/html\r\n"; cmd += "Connection: close\r\n"; //cmd += "Refresh: 15\r\n"; cmd += "\r\n"; //cmd += "<!DOCTYPE HTML>\r\n"; cmd += "<html>\r\n"; //cmd += "<header><title>ESP8266 Webserver</title><h1>\"14CORE ESP8266 Control Center\"</h1></header>"; if(device1){ cmd +=("<br/>Device1 : ON"); } else{ cmd +=("<br/>Device1 : OFF"); } if(device2){ cmd +=("<br/>Device2 : ON"); } else{ cmd +=("<br/>Device2 : OFF"); } if(device3){ cmd +=("<br/>Device3 : ON"); } else{ cmd +=("<br/>Device3 : OFF"); } if(device4){ cmd +=("<br/>Device4 : ON"); } else{ cmd +=("<br/>Device4 : OFF"); } cmd += "<html>\r\n"; wifi.Send(chlID,cmd); //delay(200); wifi.closeMux(chlID); //delay(1000); } } |
Arduino Wifi with ESP8266 Code Library
webserver_uno.ino:6:65: fatal error: uartWIFIUNO.h: No such file or directory
compilation terminated.
Error compiling.
hello sir i am getting this error
i am using same code as you given above
My IDE is ARDUINO 1.6.5
Hi! Yogi,
Download the Code Library named
uartWIFIUNO.h <----- and placed it into your Arduino Library located at My Documents/ Arduino / Libraries just copy the whole directory and phase. Let me know if you still having an error compiling the code above.
Hi Yogi,
I guess there some issue with the library it think it is absolute….
#include “ESP8266.h >
Use this library > https://github.com/itead/ITEADLIB_Arduino_WeeESP8266
1. Make it sure, you have complete library as required for the sketch code,
You don’t need to download this library.
#include “ESP8266.h > Download it Here “Use this library > https://github.com/itead/ITEADLIB_Arduino_WeeESP8266”
2. Make it sure you place a 200uf capacitor between GND and VCC to stabilize the logic voltage going to ESP8266.
3. Try fist using USB Serial Communication by placing the pin to ESP TX and RX to pin 0,& 1, Test the communication between the ESP8266 to Arduino by using AT Command.
———
hello, my code’re error when checking
‘Exit status 1
compiling error.
how can I fix
Error compiling.
Dear sir I am getting this error……..
………………………………………………………………………………………………………………………………………………
Arduino: 1.6.8 (Windows 7), Board: “Arduino/Genuino Uno”
C:\Users\Chinmay\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\libraries\ESP8266WiFi\examples\WiFiScan\WiFiScan.ino:23:65: fatal error: uartWIFIUNO.h: No such file or directory
#include “uartWIFIUNO.h” // Can be downloaded below on this page
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
where is uartWIFIUNO.h sir….? I cannot find it in your page and code library on your post…
please help me to solve the error
include “uartWIFIUNO.h” // Can be downloaded below on this page
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
You can download the library here :
http://www.14core.com/wp-content/uploads/2016/11/ESP8266UNO.rar
sir i succes to added library to Arduino IDE, and succes to compile and upload sketch to arduino UNO. But i find in serial monitor, that ”
AT+RST
Module have no response
Begin error
Init error
please tell me about this error..
my email : [email protected]
There are two possible error in your case first is your serial communication is busy, second is if your using Arduino or the code below try to shift your serial communication RX = 0; & TX = 1; add 100uf capacitor to GND and VCC to your ESP8266 module, then use coolterm serial tool to verify that your ESP8266 module is connected in a proper way.
Regards
Hi,
i like your instruction and got it to work…
I have some issues with the schematics. It would be great when the pinout of the esp8266-01 would be like its on the pc board.
Sorry for the bad english but i hope you know what i mean.
how to know the ip address of esp8266 wifi module
Serial or software serial, open your serial monitor then connect to the port.
you can used Arduino Serial Monitor, Putty, TermCool any Serial tools or Use LCD to print the IP Address of ESP82XX | lcd.println(IP Address: ); lcd.print(ipstring);
———————————————————
String ipstring = wifi.showIP();
DebugSerial.println(ipstring);
——————————————————–
sir one doubt the library pasting is in rar format or in extract file format
?????? you need to extract the file which is in the rar file then then upload the code using your IDE. don’t forget the code libraries to place in your code library directory. :)
Hi sir,
“Wiring ESP8266 WiFi Transceiver on Arduino with Relay” program run but actually,
when can i firmware in esp8266-01?
when can i use “at cammad “?
i am reading but no any idea firmware and at cammand.
please explain me.
I am getting this error
In file included from C:\Users\NEXUS\OneDrive\Documents\Arduino\sketch_mar29a\sketch_mar29a.ino:22:0:
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:67:0: warning: “OPEN” redefined
#define OPEN 1
^
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:55:0: note: this is the location of the previous definition
#define OPEN 0
^
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:75:0: warning: “SERIAL_TX_BUFFER_SIZE” redefined
#define SERIAL_TX_BUFFER_SIZE 128
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232:0,
from sketch\sketch_mar29a.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:46:0: note: this is the location of the previous definition
#define SERIAL_TX_BUFFER_SIZE 64
^
In file included from C:\Users\NEXUS\OneDrive\Documents\Arduino\sketch_mar29a\sketch_mar29a.ino:22:0:
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:76:0: warning: “SERIAL_RX_BUFFER_SIZE” redefined
#define SERIAL_RX_BUFFER_SIZE 128
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232:0,
from sketch\sketch_mar29a.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:53:0: note: this is the location of the previous definition
#define SERIAL_RX_BUFFER_SIZE 64
^
C:\Users\NEXUS\OneDrive\Documents\Arduino\sketch_mar29a\sketch_mar29a.ino:27:12: warning: type of ‘chlID’ does not match original declaration
extern int chlID;
^
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO\uartWIFIUNO.cpp:19:8: note: previously declared here
int8_t chlID; //client id(0-4)
^
Getting this error even after adding prescribed files to library
In file included from C:\Users\NEXUS\OneDrive\Documents\Arduino\sketch_mar29a\sketch_mar29a.ino:22:0:
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:67:0: warning: “OPEN” redefined
#define OPEN 1
^
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:55:0: note: this is the location of the previous definition
#define OPEN 0
^
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:75:0: warning: “SERIAL_TX_BUFFER_SIZE” redefined
#define SERIAL_TX_BUFFER_SIZE 128
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232:0,
from sketch\sketch_mar29a.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:46:0: note: this is the location of the previous definition
#define SERIAL_TX_BUFFER_SIZE 64
^
In file included from C:\Users\NEXUS\OneDrive\Documents\Arduino\sketch_mar29a\sketch_mar29a.ino:22:0:
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO/uartWIFIUNO.h:76:0: warning: “SERIAL_RX_BUFFER_SIZE” redefined
#define SERIAL_RX_BUFFER_SIZE 128
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232:0,
from sketch\sketch_mar29a.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:53:0: note: this is the location of the previous definition
#define SERIAL_RX_BUFFER_SIZE 64
^
C:\Users\NEXUS\OneDrive\Documents\Arduino\sketch_mar29a\sketch_mar29a.ino:27:12: warning: type of ‘chlID’ does not match original declaration
extern int chlID;
^
C:\Program Files (x86)\Arduino\libraries\ESP8266UNO\uartWIFIUNO.cpp:19:8: note: previously declared here
int8_t chlID; //client id(0-4)
^
Try to change the library use ESP8266WiFi
Download ESP8266 WebServer | Zip
http://www.14core.com/wp-content/uploads/2017/03/ESP8266WiFi.zip
Did we need to replace back the atmega328 after the set up of at-command??