YouTube Subscriber Counter With ESP8266




About: Making and sharing are my two biggest passions! In total I've published hundreds of tutorials about everything from microcontrollers to knitting. I'm a New York City motorcyclist and unrepentant dog mom. My ...

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=""></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() {
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(LED_BUILTIN, LOW);

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

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.


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.

Arduino Contest 2017

Participated in the
Arduino Contest 2017



  • Indoor Lighting Contest

    Indoor Lighting Contest
  • Make It Fly Challenge

    Make It Fly Challenge
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest

62 Discussions


Question 5 months ago

I've run into a roadblock and wonder if anyone has advice.
I've plugged in my API key and channel details, and wifi info.
I can confirm that the API key works by going to>
which spits out the appropriate JSON.

When I send the program to the board, the Serial Monitor display gets as far as:
WiFi connected
IP address:

After that, nothing happens. That is to say, the LEDs don't light up, and nothing further appears in the Serial Monitor.

I've installed version 5.x of ArduinoJson (in accordance with the error messages I got when using version 6.x).

Is there a chance the YouTube API has been updated such that this code is outdated? Becky, does your still function properly to this day?
Thanks so much! I'm so excited by the progress I'm making with this!! :)

N.B. - I opted to the version of the code without WiFi manager, since I don't anticipate a big change with our WiFi setup, and don't mind having to change the code, if that happens.

2 answers

Answer 8 weeks ago

Hi, I have the same problem with mine, did you get correct it?
Please help me.


Reply 8 weeks ago

Yup, I corrected this particular issue by adding the line of code "client.setInsecure();", as detailed in a comment I made below this one.
I hope that helps!


Tip 5 months ago

If using version 2.5.x or later of the ESP8266 manager, I believe you may need to append the setup section to include the line "client.setInsecure();" as follows:

void setup() {


for(uint8_t i=0; i<2; i++) { // Initialize displays

// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected

// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();


This, according to the code at
I wasn't able to get stats in the Serial Monitor until I added this line.

1 reply

Reply 5 months ago

Interesting, thank you for sharing! I haven't tried to use this code using the latest versions.


5 months ago

I've run into a problem - I believe I've ordered the correct ESP-12e board, but when I attach it to my breadboard (which looks to be the same size as the one in your wiring picture), there are no remaining holes to which I can connect wires.
Have a I ordered the wrong ESP-12e??

I could get a bigger breadboard I suppose. But this discrepancy has me worried, so I thought I'd check in first. :) Thanks!

3 replies

Reply 5 months ago

Oh. I've subsequently found
Well, darnitall.
So I initially asked for a board at my local store and was given an ESP-01. To which I told the shop staff, "Wow, it's much smaller than in the pictures." My mistake.
And then I just ordered the above-pictured dude via (Being in Canada, it's best to avoid links, to avoid a delivery that's both slow and expensive).

So, I guess I need something in between!? Gosh, I'm certain building my collection of useless ESP8266's. :(

This could be sage advice for anyone else reading. Follow the link if you can. Cuz this thing does _not_ appear to be standardized.


Reply 5 months ago

I've subsequently gotten around this issue by using a second breadboard.


6 months ago

Love this! Is there a way to make it work with a tm1637 display? It has the power and negative pins and CLK and DIO.
Using esp8266 board but can’t get anything on the display, even with trying to tweak the code, still quite new at this so any help would be amazing :)


7 months ago

I have been working on recreating your counter for youtube only. I've run into several issues that I have figured out doing research. However, I am now stuck with 3 errors that seem to be connected and cannot find any answers. Please see the errors below. This is your code with WifiManager.
src\main.cpp: In function 'void setup()':
src\main.cpp:68:14: error: 'loadConfig' was not declared in this scope
src\main.cpp:86:16: error: 'saveConfig' was not declared in this scope
src\main.cpp:96:21: error: 'forceConfigMode' was not declared in this scope

I am unable to find these methods used in the library files. I'm at a loss. Any and all help is welcome.

ps. Love the content here and on YouTube. Keep it up.

4 answers
Fubar1342 bekathwia

Answer 7 months ago

I've double checked and it is installed and included in the script. In the Arduino IDE, it compiles and I get the errors through the serial monitor. In Vscode, it errors out before it's compiled. Could this be a version issue? I'm using the latest version of the WiFiManager library. I'll keep digging in the mean time. Still have yet to find the callouts for the mentioned methods. Thank you.

Fubar1342 Fubar1342

Answer 7 months ago

These are the 3 errors. I haven't messed with any of the code other than what was required.


Answer 7 months ago

The wifimanager version of this project is Brian's code, I recommend dropping him a question here:
What version of the Arduino IDE are you using? Did you try the simpler sketch for this project, which hard-codes your credentials? It's at least a starting point...


7 months ago

YouTube Counter v2. I am having issues with nothing happening on the LED. I am sure the coding is correct along with the wires but nothing is happening. How do I check to make sure things are correct? Could it just be my youtube API?

// YouTube Subscriber Counter v2
// by Becky Stern 2018
// Displays your current subscriber count on a seven-segment display
// This version uses two four digit displays to support more than 10k subs
// based on library sample code by:
// Giacarlo Bacchio (Gianbacchio on github)
// Brian Lough (witnessmenow on github)
// Adafruit (adafruit on github)
// requires the following libraries, search in Library Manager or download from github:
#include <Wire.h> // installed by default
#include <Adafruit_GFX.h> //
#include <Adafruit_LEDBackpack.h> //
#include <YoutubeApi.h> //
#include <ArduinoJson.h> //
// these libraries are included with ESP8266 support
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //
char ssid[] = "ATTaz55Gs2"; // your network SSID (name)
char password[] = "mywifipassword"; // your network key
//------- enter your API key and channel ID here! ------
#define API_KEY "youtube google API key" // your google apps API Token
#define CHANNEL_ID "UCNhmy9YYBNdCVe3tcM8qsHQ" // makes up the url of channel
// label the displays with their i2c addresses
struct {
uint8_t addr; // I2C address
Adafruit_7segment seg7; // 7segment object
} disp[] = {
{ 0x71, Adafruit_7segment() }, // High digits
{ 0x70, Adafruit_7segment() } // Low digits
int subscriberCount; // create a variable to store the subscriber count
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);
unsigned long api_mtbs = 1000; //mean time between api requests
unsigned long api_lasttime; //last time api request has been done
void setup() {
for(uint8_t i=0; i<2; i++) { // Initialize displays
WiFiManager wifiManager;
wifiManager.autoConnect ("Blackjack");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
void loop() {
if (millis() > api_lasttime + api_mtbs) {
Serial.print("Subscriber Count: ");
Serial.print("View Count: ");
Serial.print("Comment Count: ");
Serial.print("Video Count: ");
// Probably not needed :)
//Serial.print("hiddenSubscriberCount: ");
subscriberCount = api.channelStats.subscriberCount;
uint16_t hi = subscriberCount / 10000, // Value on left (high digits) display
lo = subscriberCount % 10000; // Value on right (low digits) display
disp[0].seg7.print(hi, DEC); // Write values to each display...
disp[1].seg7.print(lo, DEC);
// print() does not zero-pad the displays; this may produce a gap
// between the high and low sections. Here we add zeros where needed...
if(hi) {
if(lo < 1000) {
disp[1].seg7.writeDigitNum(0, 0);
if(lo < 100) {
disp[1].seg7.writeDigitNum(1, 0);
if(lo < 10) {
disp[1].seg7.writeDigitNum(3, 0);
} else {
disp[0].seg7.clear(); // Clear 'hi' display
disp[0].seg7.writeDisplay(); // Push data to displays
api_lasttime = millis();

1 answer

Best Answer 7 months ago

This is the more complex version of the sketch, with wifi manager so you don't have to hard-code your wifi credentials. This requires a one-time setup following Brian's instructions, nothing will show until you configure the wifi:
Did you try the simpler sketch, where you edit the Arduino code to include your credentials? You might try that first, as it doens't require the same setup.


7 months ago

Hey, I am trying to build this. I have installed all the relevant libraries but I am getting the below errors:

C:\Users\chris\Documents\Arduino\libraries\YoutubeApi\src\YoutubeApi.cpp: In member function 'bool YoutubeApi::getChannelStatistics(String)':
C:\Users\chris\Documents\Arduino\libraries\YoutubeApi\src\YoutubeApi.cpp:95:2: error: 'DynamicJsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
C:\Users\chris\Documents\Arduino\libraries\YoutubeApi\src\YoutubeApi.cpp:95:20: error: expected ';' before 'jsonBuffer'
DynamicJsonBuffer jsonBuffer;
C:\Users\chris\Documents\Arduino\libraries\YoutubeApi\src\YoutubeApi.cpp:96:21: error: 'jsonBuffer' was not declared in this scope
JsonObject& root = jsonBuffer.parseObject(response);
C:\Users\chris\Documents\Arduino\libraries\YoutubeApi\src\YoutubeApi.cpp:97:10: error: 'ArduinoJson::JsonObject' has no member named 'success'
if(root.success()) {
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

1 reply

Reply 7 months ago

This error is complaining about not being able to find the YouTube API library, so perhaps it's not installed in the correct place, or maybe your code is missing the #include line that references it. What version of the Arduino IDE are you using?