load the arduino code

 

This part of the instructions cover loading Arduino code onto your WiFi controller. If you already have the Arduino code installed onto the NodeMCU ESP8266-12E development board, you can skip this step. These directions are valid for loading the code the first time, as well as replacing the code with an updated or modified version.

Getting, installing and setting up Arduino IDE. If you already have Arduino IDE installed and setup to use an ESP8266 board, download the ZIP file here, unzip it, then load the contained sketch onto the ESP. Otherwise, get Arduino IDE from here and install it. There are a few steps in getting the ESP board recognized by the Arduino IDE. I will give them in terse bullet points. If you want a full explanation of what you’re doing and why, you can read about it here.

  • Open Arduino IDE and click File > Preferences (on macOS, that’ll be Arduino IDE > Preferences)
  • Put this address into the Additional Boards Manager URLs box:
    http://arduino.esp8266.com/stable/package_esp8266com_index.json
  • Click OK
  • Back in the main Arduino IDE screen, click Tools > Board > Boards Manager…
  • Search for “esp8266” and when you find it, click Install and close the Boards Manager window
  • Click Tools > Board and select NodeMCU 1.0 (ESP8266-12E Module)
  • Click Tools > Port and select the USB port to which the ESP board is connected

You will need to perform the last two steps any time you develop on a different type of Arduino board and switch back to the ESP8266. The rest of that only needs to be done once.

To compile this sketch, you will need to get a few libraries loaded into the IDE, so click Sketch > Include Library and click ESP8266WiFi. You’ll need to load the following libraries in the same way (Click Sketch > Include Library, then click the library name): ESP8266mDNS, ESP8266WebServer, WiFi, ArduinoJson, EEPROM, ArduinoOTA. If you do not see any of those in the list of libraries, you will find it by clicking Sketch > Include Library > Manage Library and searching for the library name. Once you find it, click Install, then go through the steps again to include it in your sketch.

Compiling the code and sending it to the boardBefore you do this, if you installed a voltage regulator, verify that there is no power to the Vin pin of the ESP board. Download this zip file and unzip it or get it at github. (github link) Plug your ESP board into your computer through USB, select the proper Board and Port through the Tools menu, then click the Upload button. Watch the console, and in a little bit, the code will be loaded. If you want to see what the device is logging, open the Serial Monitor and set the baud rate to 57600. The sketch isn’t very chatty, but it does display some status information such as the device’s IP address.

To connect the controller to your network and get it configured:

  1. Power on the controller
  2. On your computer or on a mobile device, connect to the WiFi network that the controller creates. It will create a network with an SSID that begins with “appideas-“
  3. Open a web browser and go to http://192.168.4.1:5050
  4. Provide the credentials to connect to your network, then click the CONNECT button
  5. Get the IP address that was assigned to the controller. I’m sorry that this part isn’t easier yet. If you know how to get to your WiFi router’s DHCP device list, the WiFi controller will appear on it with a device name that contains “esp” and the four characters that were after “appideas-“ in the device’s Access Point SSID. The Arduino Serial Monitor will also show the device’s assigned IP address.

If you want to know how the Arduino code works, you can read about it on step 4 of my previous Instructable. (Instructable link) That Instructable also talks about how to use a web browser to test your lights and the WiFi controller, so if you get impatient getting to the mobile app installation, you can check that out.