Connecting ESP8266 (NodeMcu) to Arduino Uno to control LED

Hello,
My project is to control and LED over wifi using an ESP8226 module and Arduino. I am a web developer, so I understand code, but I'm new to electronics.

I purchased this from Amazon: HiLetgo ESP8266 NodeMCU CP2102 ESP-12E. Amazon.com: HiLetgo 2pcs ESP8266 NodeMCU CP2102 ESP-12E Development Board Open Source Serial Module (Pack of 2PCS): Computers & Acc

I have connected VIN->5v, GNC ->GND, TX->2, RX->3.

I'm using the following script from the internet

/*
   WiFiEsp test: BasicTest

   Performs basic connectivity test and checks.
*/

#include "WiFiEsp.h"

// Emulate Serial1 on pins 7/6 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif


// Replaced ssid and pwd before posting
char ssid[] = "XYZ";     // your network SSID (name)
char pwd[] = "XYZ";  // your network password
char pwdErr[] = "xxxx";   // wrong password


void setup()
{
    Serial.begin(115200);
    Serial1.begin(9600);
    WiFi.init(&Serial1);
}

void loop()
{
    assertEquals("Firmware version", WiFi.firmwareVersion(), "1.5.4");
    assertEquals("Status is (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
    assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
    assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
    assertEquals("Check SSID", WiFi.SSID(), ssid);

    IPAddress ip = WiFi.localIP();
    assertNotEquals("Check IP Address", ip[0], 0);
    Serial.print("IP Address: ");
    Serial.println(ip);

    byte mac[6]={0,0,0,0,0,0};
    WiFi.macAddress(mac);

    Serial.print("MAC: ");
    Serial.print(mac[5], HEX);
    Serial.print(":");
    Serial.print(mac[4], HEX);
    Serial.print(":");
    Serial.print(mac[3], HEX);
    Serial.print(":");
    Serial.print(mac[2], HEX);
    Serial.print(":");
    Serial.print(mac[1], HEX);
    Serial.print(":");
    Serial.println(mac[0], HEX);
    Serial.println();

    assertEquals("Disconnect", WiFi.disconnect(), WL_DISCONNECTED);
    assertEquals("Check status (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
    assertEquals("IP Address", WiFi.localIP(), 0);
    assertEquals("Check SSID", WiFi.SSID(), "");
    assertEquals("Wrong pwd", WiFi.begin(ssid, pwdErr), WL_CONNECT_FAILED);

    IPAddress localIp(192, 168, 168, 111);
    WiFi.config(localIp);

    assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
    assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);

    ip = WiFi.localIP();
    assertNotEquals("Check IP Address", ip[0], 0);


    Serial.println("END OF TESTS");
    delay(60000);
}


////////////////////////////////////////////////////////////////////////////////////


void assertNotEquals(const char* test, int actual, int expected)
{
    if(actual!=expected)
        pass(test);
    else
        fail(test, actual, expected);
}

void assertEquals(const char* test, int actual, int expected)
{
    if(actual==expected)
        pass(test);
    else
        fail(test, actual, expected);
}

void assertEquals(const char* test, char* actual, char* expected)
{
    if(strcmp(actual, expected) == 0)
        pass(test);
    else
        fail(test, actual, expected);
}


void pass(const char* test)
{
    Serial.print(F("********************************************** "));
    Serial.print(test);
    Serial.println(" > PASSED");
    Serial.println();
}

void fail(const char* test, char* actual, char* expected)
{
    Serial.print(F("********************************************** "));
    Serial.print(test);
    Serial.print(" > FAILED");
    Serial.print(" (actual=\"");
    Serial.print(actual);
    Serial.print("\", expected=\"");
    Serial.print(expected);
    Serial.println("\")");
    Serial.println();
    delay(10000);
}

void fail(const char* test, int actual, int expected)
{
    Serial.print(F("********************************************** "));
    Serial.print(test);
    Serial.print(" > FAILED");
    Serial.print(" (actual=");
    Serial.print(actual);
    Serial.print(", expected=");
    Serial.print(expected);
    Serial.println(")");
    Serial.println();
    delay(10000);
}

I get the following from the serial monitor
[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
********************************************** Firmware version > FAILED (actual="", expected="1.5.4")

I'm unsure what's going wrong and what I should be doing to debug it. Any help, articles, etc would be greatly appreciated.

Link cleaned up! Amazon.com: HiLetgo 2pcs ESP8266 NodeMCU CP2102 ESP-12E Development Board Open Source Serial Module (Pack of 2PCS): Computers & Accessories

Not sure of your code, but perhaps it does not like a zero MAC address!

Just wondering why a UNO would form any part of such a project?

No, even before that, WiFi.firmwareVersion() (first line in loop()) already gives an empty string. My guess is that WiFi.init(&Serial1) fails. Don't know why, though...

Question:

// Emulate Serial1 on pins 7/6 if not present
 ...
SoftwareSerial Serial1(2, 3); // RX, TX

Are you using 7/6 or 2/3?

Paul__B:
Just wondering why a UNO would form any part of such a project?

+1

Why make things more complicated.
The NodeMCU on it's own is far more capable than an Uno.
And, it does have a built-in LED, to try.
Leo..

@Paul__B - this is just phase one of the project I am making. It is a sunrise alarm clock in which I plan to use 30+ addressable RGB LEDS. I already have the LEDS working with the UNO, but now I'm trying to incorporate WIFI so I can set the alarm time from a web app.

@Erik_Baas sorry for the misleading comment - I tried a couple different pins during my debugging attempt so the code/comments got out of sync.

I have NodeMCU TX plugged into 2 and NodeMCU RX plugged into 3. I also tried reversing them, but the same result. I also think it’s something wrong with the Serial based on the firmware version being empty.

I also thought maybe there was something wrong with the NodeMcu, so I used GitHub - nodemcu/nodemcu-flasher: A firmware Flash tool for nodemcu to flash the firmware. I’m not 100% what it does, but it says it was successful.

Is this a school project? If not it seems a long winded way of doing it. I would have a look at random nerd tutorial they have a lot of networking info to try.

Have you tried just the ESP device to see if it connects without the UNO? I use the ESP32 with Arduino IDE and guidance from RandomNerd and have never had an issue finding WiFi.

aesdev421:
I already have the LEDS working with the UNO, but now I'm trying to incorporate WIFI so I can set the alarm time from a web app.

So you move the LEDs to the ESP. You need the command to suppress interrupts each time you update the LEDs.

You will need a level translator - a 74HCT14 is perfect for the job. :grinning:

Thanks for the tips everyone! I’m going to spend some time going through RandomNerd tutorials and learning more about the NodeMCU module, then I’ll circle back around to my project once I have the basics down. Thanks again

Hello all,

I wanted to report back that I dropped the Arduino and started only using the NodeMCU. I’ve successfully created V1 of my sunrise alarm clock now. Thanks for the help!!

That is going to make things so much easier. :sunglasses: