Arduino

Electronics platform

Arduino

We'll be using the Arduino platform and IDE to write our code

Install Arduino IDE

Download and install the Arduino IDE.

Download Arduino IDE for

Install board definitions

Copy this URL

http://arduino.esp8266.com/stable/package_esp8266com_index.json
  1. Open the Arduino IDE preferences

  2. In the Additional Boards Manager URLs

Install the esp8266 boards definitions

Open the Board Manager in Tools › Board › Boards Manager

  1. Search for esp8266

  2. Install the boards definition

  3. Close Arduino and open it again so the board configurations are loaded

Configure Arduino for this project

Connect your board using the USB cable.

  • Make sure you are using the appropriate COM port under Tools › Port

  • Make sure you have selected the appropriate board board under Tools › Board:

Use LOLIN (WEMOS) D1 mini Pro

LOLIN (WEMOS) D1 mini Pro

Install libraries

AdaFruit Neopixel

We are going to use the Library Manager to install this library

Arduino IDE Library Manager
  1. Open the Library Manager by clicking on the menu Sketch Include Library

    Manage Libraries

  2. Search for neopixel

  3. Select Adafruit NeoPixel by Adafruit

  4. Click the Install button

  5. Don't close the Library Manager dialog yet

ArduinoJson

We will use the Library Manager again to install this one

  1. Open the Library Manager by clicking on the menu Sketch › Include Library › Manage Libraries

  2. Search for ArduinoJson

  3. Select ArduinoJson by Benoit Blanchon

  4. Make sure you select the v5 version

  5. Click the Install button

  6. Don't close the Library Manager dialog yet

Firebase ESP8266 Client

We will also install this library using the Library Manager

  1. Open the Library Manager by clicking on the menu Sketch › Include Library › Manage Libraries

  2. Search for firebase

  3. Select FirebaseESP8266 Client by Mobitz

  4. Click the Install button

  5. Close the Library Manager

Restart Arduino IDE

After updating or installing libraries, restarting Arduino IDE is required for changes to take effect

Test program

Let's write a program that tests our RGB LED and its connections. First, open the Arduino IDE

Notice that Arduino programs have at least two functions:

  • Setup runs once when the device starts

  • Loop runs again and again, indefinitely, while the device is powered on.

Let's copy the code below and make some magic happen

neopixel-test.ino
#include <Adafruit_NeoPixel.h>

// This code asumes your data pin is 2. Change it if you need to
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, D4, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.setBrightness(255);
  Serial.begin(9600);
}

void loop() {
    strip.setPixelColor(0, strip.Color(255, 0, 0));
    Serial.println("red");
    strip.show();
    delay(500);
    
    strip.setPixelColor(0, strip.Color(0, 255, 0));
    Serial.println("green");
    strip.show();
    delay(500);
    
    strip.setPixelColor(0, strip.Color(00, 0, 255));
    Serial.println("blue");
    strip.show();
    delay(500);
}

Flash your program

  • Click the upload button on the top bar of the Arduino IDE

  • Enjoy your blinking RGB led!

The upload button

Debugging

The serial monitor

Let's take a look under the hood. Open the Serial Monitor on Tools › Serial Monitor

Make sure the baud rate on this window matches the one in the code

Watch as your code runs

References

Last updated

Was this helpful?