top of page

Safari browser sometimes has issues displaying images...

I.e: *you have to click on the images to see them...

For a better browsing experience on Brainy-Bits

Please use Chrome, Edge or Firefox browser.

  • Writer's pictureBrainy-Bits

Making something that’s been done so many times before!


Oh, the infamous YouTube Counter project!

I know there’s a lot of them out there, but I always wanted to build one for myself.

And since I told myself that I would try to film more stuff and put out more tutorial videos from now on, here’s my take on it!

This will be a two part tutorial:

In this first part we will have a look at:

  • How to setup the Google API for YouTube *This part can be confusing if you look at other tutorials on the internet, so I will try to make it easier

  • Then we will look at the code to get the information from it, and make sure it works correctly

In the next part we will build it and make it look nice with all the bells and whistles!

So let’s get started!



NodeMCU V2

MAX7219 Matrix Module

These are Amazon affiliate links...

They don't cost you anything and it helps me keep the lights on

if you buy something on Amazon. Thank you!



Now since we’re getting the YouTube information from the internet we need something that has at least a WiFi connection.

That’s why I chose to use the NodeMCU board which has WiFi built in.

The NodeMCU is built around the popular ESP8266 WiFi module.

Using the NodeMCU makes it easy to connect and use the capabilities of the ESP8266 as well as use the Arduino IDE we are familiar with to upload sketches.



Like I said at the beginning, I feel the most confusing part of this project is “how do I setup the Google YouTube API?”

All the other tutorials I’ve seen on the subject don’t seem to go through all the steps in details, so I decided to go through it step by step to help with this part.

I will go through them here, but please don’t forget to watch the tutorial video below to see them in real life.

*note: this method works at the time this tutorial was created, so if Google makes changes in the future, these steps might be different.

Step 1: Go to the Google API webpage:  and make sure you are logged in to your gmail account.

Then Click on "CREATE" on the left to create a new project.

Give your project a Name, you don’t need to select an organization.

Then click CREATE to finish.

You should get a notification that the project was created and make sure it is selected in the upper left.

Now click on the “API library” Link next to the text that says “You don’t have any API’s available to use yet…..”

Now on this page type “YouTube” in the Search box.

Click on “YouTube Data API v3” to select the API.

Click on “ENABLE” to install the API.

Now that the API is installed and Enabled, click on “CREATE CREDENTIALS”.

Now on this page you are gonna click the link “API key”, I’ve highlighted it in green in the above picture.

Here you can give the API a name if you want, but before you click on Create, click on the “API restrictions” Tab.

Here, under the “Select API” drop down, select “YouTube Data API v3”

Once it shows up above the drop down box, then you can Click “Create” to finish.

And that’s it!  You now have your API Key ready to go and test in the next step.



Now before we actually get to coding, we can test to see if the YouTube API is working just using a web browser.

For this you will need the API KEY we created in the prior step, as well as your YouTube ID.

You can find out your YouTube ID by going to YouTube main page and then clicking on Settings under your username:

Once there, click on Advanced settings, and there you will see your Channel ID.  Make a note of it for the next step.

Ok so now that we have the API key number and the YouTube ID we can open a browser (I use Google Chrome for this) and type in this URL: YOUR YOUTUBE ID HERE&key=PUT YOUR API KEY HERE

Now of course, replace the “PUT YOUR….” text with the appropriate ID or KEY that you got from the prior steps.

If everything is working you should see this type of information after pressing enter:

If you see this type of information, yours will be different since it’s using a different YouTube Channel…  

Then you’re all set to move on to programming the NodeMCU to get that information itself.



The connections for this first part are pretty simple:

Pin D5, D7 and D8 of the NodeMCU are connected to CLK, DIN and CS of the LED Matrix

3.3V and GND of the NodeMCU are connected to VCC and GND of the LED Matrix



Ok so we confirmed that the YouTube API is working so now we can start the code that will retrieve this information using the NodeMCU.

We need a couple of libraries to make this work, the main one created by Brian Lough will make it easy to get the YouTube information we need.

There’s a list of the needed libraries with links at the bottom of this page.

As always, please watch the tutorial video for more information on how this code works.

/* YouTube Counter LED Display

Modified by Yvan / from example code of Brian Lough
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!


#include <YoutubeApi.h>  // created by Brian Lough
#include <ArduinoJson.h> // *Version 5.13.5 needed* - created by bblanchon
#include <ESP8266WiFi.h> // Library for WiFi communication (installed by default with NodeMCU board)

#include <MD_Parola.h>   // Library to control LED Matrix
#include <MD_MAX72xx.h>  // Library needed for MD_Parola
#include <SPI.h>

/*  PAROLA_HW,    ///< Use the Parola style hardware modules.
    GENERIC_HW,   ///< Use 'generic' style hardware modules commonly available.
    ICSTATION_HW, ///< Use ICStation style hardware module.
    FC16_HW       ///< Use FC-16 style hardware module.

#define MAX_DEVICES 1  // Number of modules connected
#define CLK_PIN   D5   // CLK pin of matrix connected to pin D5 on NodeMCU
#define DATA_PIN  D7   // DATA pin of matrix connected to pin D7 on NodeMCU
#define CS_PIN    D8   // CS pin of matrix connected to pin D8 on NodeMCU

MD_Parola MATRIX = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);  // Create instance of MD_Parola named MATRIX

#define wifi_name "HOME5GHZ"     // your network SSID (name)
#define wifi_password "cryogenics"  // your network key
#define google_api_key "AIzaSyB9JiEN5vXYtSpsD8OGEyLm0IP0XbyCAmg"  // your google API Key
#define youtube_channel_id "UCH2m9XX8jSyVMkZUXwETPTw" // your YouTube Channel ID

WiFiClientSecure client;  // create instance of WiFi named client

YoutubeApi get_from_youtube(google_api_key, client);  // Create instance of YoutubeAPI named get_from_youtube

unsigned long refresh_time = 6000; // Time in milliseconds that needs to pass before a refresh
unsigned long last_refresh;   // Last time a refresh of the info occured

long subs = 0;  // Variable to save number of Subscribers YouTube 
long total_views = 0;  // Variable to save number of total views on YouTube

int counterdigit=0;  // Variable to change number on led matrix

void setup() {

  client.setInsecure(); // Needed to get information for the YouTube API on the NodeMcu

  Serial.print("Connecting Wifi: ");
  WiFi.begin(wifi_name, wifi_password);  // connect to the WiFi network
  while (WiFi.status() != WL_CONNECTED) {  // wait for a connection
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();

void loop() {

  if (millis() - last_refresh > refresh_time)  {  // if enough time has expired between refresh
    if(get_from_youtube.getChannelStatistics(youtube_channel_id))  // if info received from YouTube
      Serial.print("Subscriber Count: ");
      Serial.print("View Count: ");
      Serial.print("Video Count: ");
    last_refresh = millis();  // set last time info was refreshed


So that will do it for Part 1 of the YouTube Subscriber Counter.

We confirmed that the NodeMCU can get the information we need from the YouTube API by viewing it on the Serial Monitor.

In the next part, we will build something more interesting to display all this information…

I’m still thinking about how to do this, so I hope to see you again when I do and see how it turns out!

Thanks for stopping by!





Copy and Paste the above code/sketch in your Arduino IDE software.

Link to the libraries used in this tutorial:

Arduino YouTube Library by Brian Lough

ArduinoJson library written by Benoît Blanchon – Install this library using the Arduino IDE Library manager – You need to choose version 5.13.8 since the new versions will not work

1,222 views0 comments

Recent Posts

See All


All my content is and will always be Free.

If you feel that my Videos / Tutorials are helping, and you would like to contribute...

 You can toss some coins in the Tip Jar via PayPal.

Select amount then click the “Donate” button.

bottom of page