YouTube Subscriber Counter
-=Using the NodeMCU=-
All my content is free.
If you feel that my videos 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.
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!
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.
If you’re not familiar with the NodeMCU board you can check these tutorials I’ve done previously:
SETTING UP THE GOOGLE YOUTUBE API
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: https://console.developers.google.com and make sure you are logged in to your gmail account.
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.
TESTING OUT THE YOUTUBE API
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:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=PUT 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.
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 https://github.com/witnessmenow/arduino-youtube-api
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
If you’re not sure how to install libraries this way, check out this tutorial video: