Introduction: YouTube Subscriber Counter With ESP8266

I was inspired by the Play Button awards YouTube sends out for subscriber milestones and whipped up a simple circuit using an ESP8266 wifi board and seven segment display to show off my realtime subscriber count. This is a great IoT beginner project, with just a little soldering and a code personalization required to make it work for your own account.

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 this project, you will need the following materials:

and the following tools:

Required software libraries:

Unique data required:

As an alternative to the Feather Huzzah, you can also use your favorite ESP8266 microcontroller board, some of which require an FTDI cable to upload new programs. Use the standard 7-segment backpack rather than the FeatherWing version.

Step 1: Assemble Circuit

Follow the official assembly instructions for the Feather Huzzah using female headers (or stacking headers, though you'd have to cut the long legs off) Likewise follow the assembly instructions for your seven-segment FeatherWing display.

Before you dive into the code for 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 the Feather Huzzah tutorial):

  • 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

Huzzah ESP8266 boards have an LED connected to pin 0, and you can find a sample blink sketch by navigating to File->Examples->ESP8266->Blink, or copy it from here:

void setup() {
  pinMode(0, OUTPUT);
void loop() {
  digitalWrite(0, HIGH);
  digitalWrite(0, LOW);

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

  • Board: Adafruit Huzzah ESP8266
  • 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 the Feather Huzzah auto-detects when it's being sent a new program, 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.

Step 2: Customize Code & Program Board

For this project, you will need the following Arduino Libraries. 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.ino" in the Arduino IDE. Customize the variables (shown highlighted in teal in the Arduino screenshot above):

Upload the customized code to your board.

Step 3: 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 4x6"). Cut along the lines to separate the two pieces. The graphic goes right behind the glass, and the other part is for easy placement of the circuit.

Step 4: Put It All Together

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

Place the graphic template face down against the glass, then stack the shadow box separator inside. Glue the other template piece to a 4x6 piece of illustration board or scrap cardboard using a glue stick, then tape the circuit sandwich in place over the template rectangle. You could avoid the glue-up step by printing the template on stiff paper.

Cut away a notch in both backing boards 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 shim under the USB plug to help the seven-segment display press flush against the paper/glass (otherwise the numbers are blurry).

Step 5: Enjoy!

Display your custom Play Button with pride!

You may have noticed the display only supports subscriber counts up to 10,000. If you're popular enough to have that problem, add another four-digit display to yours, soldering a jumper to change the I2C address of the second one.

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 the other IoT projects in the series:


witnessmenow made it! (author)2017-03-23

Hey Becky,

A user pointed out an issue with the example sketch of the library, that I just checked that you have the same issue in your sketch. Sorry, my bad!

The issue is that millis() will eventually roll over and start counting up from 0 again (I think it roughly about 40 days when this happens). When that happens your sketch will stop checking youtube as the if statement in the loop will never be true.

It's fixed on github now if you want to check it out (just change the two time holding variables to unsigned long):

I added a new example to the library as well that uses WiFiManager library, you should check it out as it means you don't need to reprogram the device to change the Wifi Network and you can also configure the API key and Channel ID using it too.

I've More Info on WifiManager here.

WannaDuino made it! (author)WannaDuino2017-06-29


i uploaded the code with SUCCES, yes finally. And is working in the serial screen of Arduino.

but my 7 segment is different!! i only have 4 pins. do you know how i can let mine work to?

beckys youtube counter serial picture of working code.pngIMG_20170321_200612.jpgIMG_20170321_200629.jpg
witnessmenow made it! (author)witnessmenow2017-07-04

Hey WannaDuino

I think I use the same 7 segment display in my Commute Checker project. Unfortunately the library for it is not on the library manager but I have instructions on how to install it here (scroll to the part about TM1637)

There will be an example with the library that will show you its features, but I think what you are looking for is

display.showNumberDec(numSubs, false);

hopefully that helps!

WannaDuino made it! (author)WannaDuino2017-07-04

thank you so much sir for answering,

but i do not know what to do with this, and on what 2 pins i must connect it.

i put the librairy in it and uploaded it, still not working of corce because i dont know what to do with the ( display.showNumberDec(numSubs, false); ) and where to paste it. i am trying to learn this for over a year now, but i have so much respect for you people who can read this codething, i am still a copy paste user. is there a way you can make a copy of a working code with false credentials of corse, because i am getting frustraited sir. i am trying this counter for over 7 months, and i have it working in my serial page, but i want to see it on this lsd. sir.

witnessmenow made it! (author)witnessmenow2017-07-06


It would be better if for you in the long run if you figured it out yourself

Follow the instructions in my instructables I linked to install the library. Once it is installed you will have an example for the library under File->Examples->TM1637

Try get that example working (hint, your node MCU board has pins labeled D1, D2 etc, so change CLK and DIO pins up the top of the example to have be the same as your pin label, with the D infront of it). You can connect Vcc to 3V and GND to G

Once you have that working try figure out what you need to add to Becky's sketch from the example to get it working.

WannaDuino made it! (author)WannaDuino2017-07-07

Master, Sir.

It is 6 HOURS later, and i tried 5 hours long to figure it out. sorry, i did not get it to work. but your examle WORKED 100%

I had the TM library already, and that example also, so that was working in no time, but i only got to work because of your TIP, i did not know that you need to type the D in front of it, ( so i think that it`s on every controller so, what the pin name is, must be also typed in the sketch pinout.

also, the first try with the EXAMPLE did not work because i used D1 and D2, but it works on D5 and D6 ( probably SPI pins??) i have for all my boards pinout reference pictures. also included here.

Then i tried t Miss Becky's sketch, i copied parts in it, also the libraries.from the WORKING TM example, see pictures,

but i also got fault messages of the MATRIX display becky used, i do not think this only works with adding the tm librairy and some extra lines!!

i also copied the complete example in the becky sketch, would not upload,

I only copied the the lines but WITHOUT the loop test of the DONE example ( the digits and the DONE part of the code.but also i do not know where to paste it so tryed several places with NO effords.

Because i think that the rest needs to be taken out, ( the adafruit lines or whatever has to do with her display )OR AM I WRONG on that? maybe a new hint.? i really think that the complete code needs to be rewritten, and that is NOT my cup off tea,

I hope AGAIN that i am wrong, so i will not stop untill i get it to work I HOPE.

codeB.pngcode a.pngPINOUT-NodeMCU_1.0-V2-y-V3.pngNot working but uploads ok.pngother place pasted.pngworking TM code on espLOLIN.png
witnessmenow made it! (author)witnessmenow2017-07-07

Hi WannaDuino,

If you got the example for the 7-segment working you are very close!

Yes you can remove the Adafruit and Matrix code (You have it highlighted in the first and second picture).

4th picture looks good!

Try put the code for printing done at the bottom of the setup. (If it doesn't work, at the start of the setup in TM library example they set the brightness, maybe try adding that to the start of your setup)

Becky writes to the seven segment in the code in her second picture, this is where you will need to use the line i gave in my first comment.

WannaDuino made it! (author)WannaDuino2017-07-14

i can not let it go, please help. it drives me crazy to get it it not working, i was so close. you say, but i tryed so many things the last few days sir, i wanna cry.

#include <Arduino.h>

#include <TM1637Display.h>

// YouTube Subscriber Counter

// by Becky Stern 2017

// based on library sample code by:

// Giacarlo Bacchio (Gianbacchio on Github)

// Brian Lough (witnessmenow on Github)

// Adafruit (adafruit on github)

// Displays your current subscriber count on a seven-segment display

// This version supports up to 9999 subscribers

// 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> //

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

// Module connection pins (Digital Pins)

#define CLK D5

#define DIO D6

TM1637Display display(CLK, DIO);

//------- Replace the following! ------

char ssid[] = "ME"; // your network SSID (name)

char password[] = "1234567890"; // your network password

// google API key

// create yours:

#define API_KEY "abcdefghijklmnop"

// youtube channel ID

// find yours:

#define CHANNEL_ID "mychannelid"

//Adafruit_7segment matrix = Adafruit_7segment();

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

long subs = 0;

void setup() {



// 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();



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: ");



//matrix.print(api.channelStats.subscriberCount, DEC);



api_lasttime = millis();



WannaDuino made it! (author)WannaDuino2017-07-09

Sorry but thanx for your input, but i have no clue what i am doing, i have no coding experience, so i do not know where or what i only get red bars, because i don`t know what i am doing, it's like giving a kid the keys to your F16.

i give up, thanx for all your time. this is just not for me.


WannaDuino made it! (author)WannaDuino2017-07-07

I take this challenge, Sir, I see you as a MASTER, so I will NEVER back down, to get finally a,

( well done WannaDuino, from you )

I really LACK in the code things, yeah it is easy to follow and paste and so, but this is my struggle the last 2 years in Arduino.

I understand the basics and how to get ( some ) ibles to work, but the most time, it ends up in a box. and to show you that I will include the picture MASTER. I really hope to learn as much you have, and I still have some time on this planet, so I will use that to learn this. And thin out that pile of awesomeness.

Thank you for responding sir. I needed that.

I have bin tru a very hard LiVe, and have not much time anymore because my health, but to say this, INSTRUCTABLES and Arduino, and Youtube saved my LiVe. ( and this is no joke mr W. )


bekathwia made it! (author)bekathwia2017-03-24

Thank you! I've updated the sketch to correct the variable types. And I will check out your new example soon too! Sounds like a great upgrade for v2, configurable wifi would allow this project to be given as a gift! Thanks again for your great code and amazing follow-through.

BrunoG85 made it! (author)2017-07-04

You inspired me to make one of that. But, I did make some changes in project and in the code.

I used a Amica Nodemcu v2 and a MAX7219 8 digits 7 segments lcd display.

If you want to see my code you can check here:

Screenshot 2017-07-04 20.04.43.png
bekathwia made it! (author)bekathwia2017-07-05

Awesome, thanks for sharing with us!!

witnessmenow made it! (author)2017-03-04


I wrote the Youtube api library and i absolutely love coming across somebody using it!

Project looks great, thanks a lot for sharing!

I haven't even made one for myself yet, although i would only need 3 digits! (And only just!).

For people asking about making other counters, if you let me know which services you'd like i can take a look into if it possible!


WannaDuino made it! (author)WannaDuino2017-07-02

Then i need your help, i use the 4 pins 4digit 7 segment display.

i got it all working in the serial page of arduino GUI, but my lcdis not working, bcause of my 4 pins i think, what to change ti get it to work sir?

witnessmenow made it! (author)witnessmenow2017-07-04

Sorry for the delay I only saw your messages now, I replied to your other comment :)

WannaDuino made it! (author)WannaDuino2017-07-04

Please don`t say sorry, i am humbled you take the time for me sir. hope you can guide me for 1 time.

bekathwia made it! (author)bekathwia2017-03-05

Yay hi Brian! Great library, thank you so much!

DGW made it! (author)DGW2017-03-06

What does API stand for?

witnessmenow made it! (author)witnessmenow2017-03-07

Hey DGW,
It stands for Application Program Interface. But I guess more important this is what is it!

Basically it's a way for an application or service to be easily interacted with by a program. So the library mentioned is making a call to the YouTube API and returning the results. Lots of APIs are available for different services

Riclebre made it! (author)2017-05-19

Super Cool, now I need more subscribers! LOL I upgrade the looks with a 3D printed play button if anybody is interested the files are here:

bekathwia made it! (author)bekathwia2017-05-19

Super great work, thanks for sharing!! Subbed to your channel too =D

JScottMO made it! (author)2017-03-29

Made a few small changes. Increased the update time to 10mintes. Had it check my personal channel and my branded channel (project management fundamentals) and total the number of subscribers. Works and looks great!

GaliotB made it! (author)2017-03-23

Nice Project for my YouTube Channel Subs.

I would love it to have the source code also for Instagram, Facebook Page or Twitter. Maybe i have to learn the API´s Requests:(

mthobbies made it! (author)2017-03-10

I am almost finished with this project but when I uploaded the code
to the board, it looks like this! I uploaded the basic 7-segment example
sketch and it works fine. So I know for sure its not a problem with the
hardware. Please help!!


bekathwia made it! (author)bekathwia2017-03-10

Looks like it's not connecting to the net-- the display will spit out random info until it gets told what to display for the first time. Work on your Feather Huzzah setup, follow the setup tutorial to verify your network settings etc.

mthobbies made it! (author)mthobbies2017-03-10

Its working now! Thanks for your help Becky

bekathwia made it! (author)bekathwia2017-03-10

Additionally, there could be a problem with your Google API key. Brian who wrote the library has a step for verifying that your key and youtube id are working:

Technovation made it! (author)2017-03-04

wow cool, great job and a very neat project!!!! was wondering whether instead of counting the number of subscribers, whether it could count the number of views or likes instead?

witnessmenow made it! (author)witnessmenow2017-03-04


if you look at the example on the github page of the YouTube API library you'll see the stats the library supports.

View count is one, likes isn't though (doesnt come back in the statistics api request)


Titan Grey made it! (author)2017-03-04

that is so cool

Papimo made it! (author)2017-03-04

Live counters are awesome! Like it very much ^^

woodbywright made it! (author)2017-02-28

I LOVE IT!! now I just need to find a 6 digit display.

DavidG179 made it! (author)2017-03-02

You got my vote. Great proyect. i will to make this project this afternoon. Great to learn about IoT

iparolisi made it! (author)2017-03-01

Can i use this tutorial for a instagram follower counter?

bekathwia made it! (author)bekathwia2017-03-01

Thanks! The code uses the Google API right now, so a significant change would be required to make it work for other platforms.

cptsilvertooth made it! (author)2017-02-28

great project! I wonder if this would work for a Facebook business page "likes" counter?

jf_blanco made it! (author)2017-02-28

Wires. No thanks ;-) Anyway a nice app

DIY-with-MOON made it! (author)2017-02-28

I love it sooo much. I need one. Because I'm a Youtube too. Amazing post.

haxquiz made it! (author)2017-02-28

Could this be easily transformed to count Facebook likes for a certain page?

bekathwia made it! (author)bekathwia2017-02-28

Easy is a relative term, depending on your skills/background! To switch to any other site would require a substantial edit to the code, which may be easy for you!

RichP25 made it! (author)2017-02-28

This is great but what will you do when you get over 9999?

bekathwia made it! (author)bekathwia2017-02-28

Add another display to add more digits! You have to solder a jumper to change the I2C address of the second one:

Jakes workshop made it! (author)2017-02-28

That is exactly what I have been looking around how to make! Thanks

About This Instructable




Bio: Becky Stern is a content creator at Instructables. She has authored hundreds of tutorials about everything from wearable electronics to knitting. Before joining Instructables, Becky ... More »
More by bekathwia:Helmet Compatible HairstylesMatte Finish Motorcycle Tank PaintingSmart Lamp With ESP8266 & Amazon Echo
Add instructable to: