YouTube Subscriber Counter With ESP8266

10,507

105

22

Posted in TechnologyArduino

Introduction: YouTube Subscriber Counter With ESP8266

About: Becky Stern is a content creator at Autodesk/Instructables. She has authored hundreds of tutorials about everything from microcontrollers to knitting. Before joining Instructables, Becky worked for MAKE Maga...

I was inspired by the Play Button awards YouTube sends out for subscriber milestones, and built this circuit to display my realtime subscriber count using an ESP8266 wifi board and seven segment display. I built this one to celebrate surpassing 10k subscribers, so this is an upgrade to my previous counter, which only supports counts up to 9999. Personalize the code to work with your channel! For tracking other social media stats, check out my multi social tracker project.

Before attempting this project, you should be generally familiar with uploading new programs to your Arduino board and installing code libraries, both of which you can learn for free in my Arduino Class, though you really don't have to understand any of the actual Arduino code to get this project running.

For a more in-depth introduction to the ESP8266 board (and its installation and setup), check out my free Internet of Things Class.

For this project, you will need the following materials:

and the following tools:

Required software libraries:

Unique data required:

As an alternative to the NodeMCU board, you can also use your favorite ESP8266 microcontroller board, some of which require a 3V FTDI programmer to upload new programs.

Before you dive into this project, you should first make sure you've got your Arduino software set up properly to program the board you are using, which in my case involves installing the SiLabs USB driver and installing ESP8266 board support (explained in more detail in my Internet of Things Class):

  • Go to Arduino-> Preferences...
  • Look for a text field labeled "Additional Boards Manager URLs:" and paste the following URL into the field (separate multiple URLs with commas if applicable):
    <a href="http://arduino.esp8266.com/stable/package_esp8266com_index.json">http://arduino.esp8266.com/stable/package_esp8266c...</a>
  • Click OK
  • Go to Tools->Board-> Boards Manager...
  • Search for ESP8266 and click the Install button in the box "esp8266 by ESP8266 Community" when it shows up

To ensure you have a proper programming connection with your board, first load up the blink sketch. You can find a sample blink sketch by navigating to File->Examples->ESP8266->Blink, or copy it from here:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

Plug in your USB cable to the board and configure your settings under the Tools menu as follows:

  • Board: NodeMCU 1.0
  • CPU Frequency: 80MHz
  • Flash Size: 4M (3M SPIFFS)
  • Upload Speed: 115200
  • Port: whichever one ends in SLAB_USBtoUART (Mac) or COMx (Windows)

Click the Upload button to send the program to your board. This will take several seconds (longer than you are used to with Arduino Uno). After complete, the onboard LED should start blinking.

While many boards auto-detect when they're being sent a new program, some other ESP8266 boards may require a sequence of button presses to get into bootloader mode.

Do not proceed until you've successfully uploaded a blink test program to your board. Seriously, because how can you expect the project code to upload if the test didn't? =D

Step 1: Prepare Displays & Prototype

Follow the assembly instructions for your seven-segment displays, and also solder headers onto your ESP8266 board if it didn't come with headers pre-soldered.

For your microcontroller to tell the two displays apart, you'll need to change the address on one of them. Do this by applying a blob of solder to bridge the labeled pads on the back of the board. The board as-is has an address of 0x70, and the one with A0 bridged has an address of 0x71. More info on i2c addresses in the official product guide. I put the plain display on the right (lower digits), but you can easily switch it in the code if you accidentally install them differently.

When working with electronics, I always like to create a solderless prototype first.

I'm using a NodeMCU board this time, but any ESP8266 board with the I2C pins exposed will work fine. In my case that's D1 and D2.

Connections:

NodeMCU D1 to displays C (clock)

NodeMCU D2 to displays D (data)

NodeMCU Vin to displays + (power)

NodeMCU GND to displays - (ground)

Step 2: Customize Code & Program Board

Remember, you need ESP8266 board support and the following Arduino libraries to compile and upload the code for this project. Easily search and install each one using the Library Manager by navigating to Sketch->Include Library->Manage Libraries... or download from Github and install the old fashioned way:

Download the code attached to this step and open the file "YouTubeSubscriberCounter_v2.ino" in the Arduino IDE. Customize the variables (shown highlighted in teal in the Arduino screenshot above):

Upload the customized code to your board.

If you prefer, I've also created a version that uses WiFiManager, which adds configurability without the need to reprogram the microcontroller. Download the file "YouTubeSubscriberCounter_v2_wifiManager.ino" attached to this step and open it with your Arduino software, and make sure you also have WiFiManger library installed as well. Use Brian Lough's awesome guide to get it all set up.

Step 3: Solder Final Circuit

I put together the final circuit using a perma-proto, but because my frame is only 5" by 7", a full size one wouldn't fit-- I should have gotten a bigger size. I managed to put everything on the half size board but I wouldn't recommend you follow this layout exactly, since I sorta hacked away some of the pins on the NodeMCU and cut some traces to others on the back of the board.

I made a second display for the rest of my social trackers, and positioned things a bit differently, which I think worked out a little better (last photo).

Step 4: Print Paper Template

Download the paper template attached to this step and print it out (designed for 8.5x11" paper, and my shadow box capacity is 5x7"). Cut along the lines to separate the two pieces. The graphic goes right behind the glass, and the other section helps with display placement/alignment.

Step 5: Put It All Together

Clean the inside of your glass to be sure its free of dust and other contaminates (ahem cat hair). Glass is sharp, so be careful handling it.

Place the graphic template face down against the glass, then stack the shadow box separator inside.

Cut away a notch in the backing board to accommodate for the USB cable, and slot the back in place. Plug in and enjoy! Of if you're like me, disassemble several more times to get the notch just right, the dust out of the glass (again), and install a small folded piece of cardboard inside to to help the seven-segment display press flush against the paper/glass (otherwise the numbers are blurry).

Step 6: Enjoy!

Display your custom Play Button with pride!

I'd be delighted to see your version of this project in the comments. Let me know if you have any questions as well. Thanks for reading!

If you like this project, you may be interested in some of my others:

To keep up with what I'm working on, follow me on YouTube, Instagram, Twitter, Pinterest, and Snapchat.

Share

    Recommendations

    • Spotless Contest

      Spotless Contest
    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    6 Questions

    Is it possible to have multiple wifi networks that the board can connect to?
    I'm here from V1

    hopefully you can help me :p

    I have provided a version of the sketch with configurable wifi with the WiFiManager library, check it out in the code step! It lets you set up and change the wifi network by logging onto the device itself.

    I used Huzzah and uploaded the code. What am i doing wrong? I can see sub count in the terminal window, so its connected the wifi and got the data from youtube.

    2018-02-27 23.28.02.jpg

    0

    How would I wire it if I was using the adafruit featherwing backpack?

    Hi Becky, great to see the project updated! Could you please share also the full code for instagram display? Keep up the good work!

    0

    that would be awesome (y)

    So!!!
    Thanx for UPDATING...
    And this setup will work now also finally? Dear Miss Becky?

    IMG_20170904_153230_618.jpgIMG_20170321_200612.jpgIMG_20170321_200629.jpg

    great work, on my 10k sub mark i will build this.

    22 Comments

    I am super lost on how to get the API to work, Is there anyone who can help?

    11 replies

    I've Followed the instructions and made an API, I inserted it into my code and uploaded everything to the board. In serial Monitor it says that I am connected to my wifi but thats all it does, It doesn't display any other info and the 7 segments don't light up.

    Did you also paste in your unique channel ID? Can you get the seven-segment display sample code to work by itself?

    So when I run the sevenseg example I can get the displays to light up, I have also put in my unique youtube channel ID. Does it matter if I am using the featherwing display? I figured it didn't and looked up the pinout for the displays. My last idea was that I had done the API Key incorrectly?

    IMG_1306.JPG

    Your circuit looks good... are you on a wifi network with a captive portal, for example a school network where you have to sign in to use it? That could cause the behavior you describe. Also be sure there aren't any rogue spaces at the beginning or end of your API key and channel ID. I'll keep pondering, is there any more info/symptoms you think might be relevent?

    I am using the Wifi In my Home, and I have checked the code for any spaces and I don't see any. It seems as if the API Key just isn't active or something? Im sorry i'm such a noob but I appreciate the help. In serial monitor it prints that i'm connected to wifi and gives me the IP Address. But It Stops printing anything else and seems as if its stuck right there. When I set up my API I went to credentials and got an API Key and it just generated one for me. Was I supposed to enter any information into that page while setting it up? I imagine

    How does one use this tool to check their API? I am having the same issue as @blubflubify

    I think we are on to something.. I received this error

    {
    "error": {
    "errors": [
    {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. YouTube Data API has not been used in project 802084326280 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=802084326280 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "extendedHelp": "https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=802084326280"
    }
    ],
    "code": 403,
    "message": "Access Not Configured. YouTube Data API has not been used in project 802084326280 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=802084326280 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."
    }
    }

    Awesome! That was exactly what I needed! The link brought me to the Youtube Data API v3 all I had to click was the enable button and it showed right up! Thanks for all the help.

    IMG_1307.JPG

    Awesome! You should link your channel in your profile so we can subscribe! =D

    jokes on me for some reason I bought the featherwing for the display. now i have to figure out the wiring and pin address.

    3 replies

    So I got the esp board to print all my stats, and that is awesome but I could not get the display to work. I even burned a esp board out of frustration. Wasn't my best moment. I think I'll just order the breakout boards for the 7 segment that you have...and a few more ESP boards just in case. I hope to see one with the 15x7 led board and how to send it messages. I would love to update coworkers on my status if I am AFK.

    Lolz, I turned it on today and it worked.

    I already saw this idea somewhere idk but...well made and explained! thanks for sharing!! I voted for you. good luck in the contest
    PS I love your workbench area :O

    1 reply

    This would be equally as rad for Twitch streamers. Having it in the background showing the sub's updating in real time would be an interesting change from the normal pop up messages most people have.

    1 reply

    Working with the twitch API is on my todo list, just need to find the time to look at it!

    The Instagram library only took a few hours so hopefully twitch wont be too hard.

    I thought it would also be nice to be able to fetch sub notifications and donations, but I'm not too familiar whats available in the API or how it works (I'm sure this is)