Wi-Fi Module ESP8266_12 Tutorial (Data Logger) - Future ... ?? · Wi-Fi Module ESP8266_12 Tutorial (Data Logger) ESP8266-12 (ESP-12) is the enhanced version of ESP8266 WIFI module. The

  • View
    228

  • Download
    8

Embed Size (px)

Transcript

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 1

    Wi-Fi Module ESP8266_12 Tutorial (Data Logger)

    ESP8266-12 (ESP-12) is the enhanced version of ESP8266 WIFI module. The ESP8266-12 has an integrated 80 MHz microcontroller with a full WiFi capability (both as client and access point) and TCP/IP stack with DNS support as well. Now you can add Internet and powerful WIFI networking capability to your project with

    Compared to ESP8266, The The ESP8266-12 onboard antenna impedance matching was modified to improve output signal strength and quality. Both stability and RF interference resistance has been improved to reduce the data losses during transmit and receive. It has the additional six pins with IO and SPI ports which allow more freedom to the developer.

    ESP8266 Wi-Fi Analog data Logger Example

    http://store.fut-electronics.com/products/wifi-esp8266-12-serial-ttl-module-esp-12http://store.fut-electronics.com/products/wifi-esp8266-12-serial-ttl-module-esp-12http://store.fut-electronics.com/products/wifi-esp8266-12-serial-ttl-module-esp-12http://store.fut-electronics.com/products/wifi-esp8266-12-serial-ttl-module-esp-12

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 2

    Application of ESP8266_12 with Arduino Mega

    Pin connection:

    Arduino Mega ESP8266

    3.3v VCC & EN & GPIO2 & GPIO0

    GND GND & GPIO15TX2 PIN(16) RX

    RX2 PIN(17) TX

    - Open https://thingspeak.com/ and following the figures.

    https://thingspeak.com/https://thingspeak.com/

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 3

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 4

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 5

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 6

    Open Arduino code and change it as below

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 7

    Open the Serial Monitor:

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 8

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 9

    Arduino code:-

    #define SSID "Your Wireless Name"

    #define PASS "Your Password"

    #define IP "api.thingspeak.com" // thingspeak.com

    String url = "/update?key=Write API Key&field1="; //thingspeak channel taking readings

    void setup() {

    Serial2.begin(115200); // for arduino mega

    Serial.begin(115200); //for serial port

    //delay(4000);

    while(Serial2.available()>0)

    //Serial.read();

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 10

    delay(1000);

    Serial.println("AT"); //Testing module

    Serial2.println("AT");

    if(Serial2.find("OK"))

    {

    Serial.println("Module is ready");

    }

    else

    {

    Serial.println("Module have no response.");

    }

    Serial2.println("AT+CWMODE=1"); // SETTING mode

    Serial.println("AT+CWMODE=1");

    delay(200);

    if(Serial2.find("OK"))

    {

    Serial.println("Mode set");

    }

    else

    {

    Serial.println("Module have no response.");

    }

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 11

    while(Serial2.find("OK") == false)

    {

    String wifi="AT+CWJAP=\"";

    wifi+=SSID;

    wifi+="\",\"";

    wifi+=PASS;

    wifi+="\"";

    Serial.println(wifi);

    Serial2.println(wifi);

    delay(5000);

    }

    Serial.println("Connected");

    Serial2.println("AT+CIPMUX=1"); // changing mode

    Serial.println("AT+CIPMUX=1");

    delay(200);

    if(Serial2.find("OK"))

    {

    Serial.println("Mode set");

    }

    else

    {

    Serial.println("Module have no response.");

    }

    Serial.print("Connecting to ");

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 12

    Serial.println(IP);

    while(Serial2.find("OK") == false)

    {

    String page = "AT+CIPSTART=4,\"TCP\",\"";

    page += IP;

    page += "\",80";

    Serial2.println(page);

    Serial.println(page);

    delay(5000);

    }

    Serial.println("Linked");

    }

    void loop() {

    int x=analogRead(A0);

    String cmd = "GET ";

    cmd += url;

    cmd += x;

    cmd += " HTTP/1.0\r\n\r\n";

    Serial.print("AT+CIPSEND=4,");//determine how many bytes

    Serial.println(cmd.length());

    Serial2.print("AT+CIPSEND=4,");

    Serial2.println(cmd.length());

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 13

    if(Serial2.find("OK"))

    {

    Serial.println("OK");

    }else{

    Serial.println("ERROR");

    }

    Serial2.print(cmd);//send request

    delay(250);

    // delay bta3 el channel 300

    while (Serial2.available())

    {

    char c = Serial2.read();

    Serial.write(c);

    if(c=='\r') Serial.print('\n');

    }

    Serial.println("\r\n.............................");

    delay(5000);

    while(Serial2.find("OK") == false)

    {

    String page = "AT+CIPSTART=4,\"TCP\",\"";

    page += IP;

    page += "\",80";

  • Futur

    e Elec

    tronic

    s

    w w w . f u t - e l c t r o n i c s . c o m Page 14

    Serial2.println(page);

    Serial.println(page);

    delay(7000);

    }

    Serial.println("Linked");

    }