YouTube Desktop Notifier

Updated 28 April 2022

Do you get nightmares of losing your YouTube Subscribers? If you do, you are not the only one. Luckily I have made this "YouTube Desktop Notifier" to keep me up-to-date with my channels Subscriber and View Counts. This very simple DIY project cost me around $10 and it now keeps me in track with my channel. Other than displaying the Subscriber and View count this device also "Beeps and Glows" when my channel gains a new subscriber.

Step 1: Hardware Requirement

Materials required to create the Youtube Notifier

For this project, we need a mixture of both electronic components and woodworking tools.

The electronic components include:

Step 2: Hardware Requirement - 2

Woordworking tools required to build the Youtube Desktop Notifier

For the workworking bit we need:

  • Palate Wood
  • Pencil
  • Measuring Tape
  • Hand/Chop Saw
  • Hammer
  • Nails
  • Sanding Tool
  • and Personal Protective Equipments (PPE) for woodcutting

I am making the enclosure out of pallet-wood as I have a massive pile of pallets left over from my other DIY WoodWorking Projects. You can also make the box out of cardboard or plastic container and paint it to give it COOL look.

Step 3/4: The Plan

The plan to build our Youtube Desktop Notifier

The plan is to make a 24cm x 10cm box to hold the circuitry in it.

When the device is powered on, it will first connect to the specified Wi-Fi network using the SSID and password pair provided in the code. Once a connection is made the code uses a combination of the "Google API key" (I will show you how to generate it in the later section) and your "YouTube Channels’ ID" to fetch the data from the YouTube server. The device then displays the view and subscribers count using the 7segment display.

After displaying the information it waits for 5 minutes before fetching the next set of information from the YouTube server. A variable is used to store the current subscriber count. If the new subscriber count is greater than the old count the buzzer goes on and the blue and white LEDs flash (glows) alternatively.

Step 5: Wiring

A circuit diagram of all the parts, and how they connect

The wiring is very simple. We will start by connecting the 7-Segment displays to the microcontroller. Each of these displays have 4 pins, 2 for power and one for clock and the other one for data. Connect the data and clock pins to NodeMCU as per the instruction provided on screen.

Then we will connect all the VCC pins of the displays to the 3.3V pin of NodeMCU. Next, connect the buzzer shield/buzzer with the 100Ω Resistor to the D8 pin. After that connect the blue and white LEDs to D9 and D10 pins with a 220Ω current limiting resistor respectively.

Now, go ahead and link up all the ground pins to the GND pin of NodeMCU. Once all the pins are connected, connect the switch to the VIN of NodeMCU and GND to GND of the stepdown converter.

Step 6: Libraries Used

The libraries used to code the Youtube Notifier

Here is the list of libraries that we need for this project.

> Software Libraries:

  • TM1637 LED Driver: https://github.com/avishorp/TM1637ES
  • P8266WiFi: https://github.com/esp8266/Arduino/tree/master/li...
  • Arduino Json: https://github.com/bblanchon/ArduinoJson
  • Arduino YouTube API: https://github.com/witnessmenow/arduino-youtube-a...

You can download them all from GitHub, I have provided the links in the description below. Once downloaded unzip and rename the libraries by removing any special characters and the "master" from their names. Place the folder in your Arduino's libraries folder. You may need to create the Libraries folder if this is your very 1st library. Restart the IDE so that it properly loads the KEYWORD file, Examples, and adds the Library to the Library Menu.

> Unique Identifiers:

  • WiFi SSID/password
  • YouTube channel ID: https://support.google.com/youtube/answer/3250431...
  • Google API Key: https://cloud.google.com/docs/authentication/api-...

Along with the libraries you also need few unique identifiers for this project.The libraries used to code the Youtube Notifier

The first one is the SSID and password of your wireless network.

The libraries used to code the Youtube Notifier

Then, you need your YouTube Channel's unique channel ID. To get that:

  • Sign in to your YouTube account.
  • In the top right, click your account icon > Settings.
  • From left hand panel click on "Advanced settings".
  • The channel's user and channel IDs are listed under "Account information"

The libraries used to code the Youtube Notifier

And finally you need to generate the "Google API Key" for your channel. To generate the key

  • Google search "Using API Keys" or open the link provided in the description below.
  • Scroll down and click on "APIs & Services→Credentials"
  • If this is the very first time you are accessing this page then you will have to create a new project by clicking on the "Create" button.
  • Accept the terms and give your project a name then hit "Create" button to create the project
  • Once a project is created you just need to click on the "Create credentials" dropdown and select "API Key" from there
  • System will take its time to generate the key. Once generated, it will show you the key in a popup dialogue. - Copy and save it in your email.
  • Now click on the "Library" option from the left hand panel and Scroll down and enable "YouTube Data API v3" and "YouTube Reporting API" by clicking on them and hitting the "Enable" button
  • Wait for 5 to 10 minutes and then you should be able to use the API Key you just generated in your code.

Step 7: Wood Working

Cutting the wood for the box

Joining the box pieces together for enclosure

Sanding of the box for the Desktop Notifier

Drilling the holes for the Power Cord

Let’s start our project by assembling the wooden box. As discussed earlier, I am going to cut:

2 x 24x10cm, 2 x 10x6cm side panels and one 24x10cm back plate. After cutting all the wooden blocks I am going to join and sand them to give the box a nice and smooth look. At the back of the unit I am going to drill 2 holes, one of them would be for the power cord and the other one for the on and off switch.

Step 8: Soldering

Once the box is ready, I am going to solder all the electronics components and install them in the box.

Soldering the 100 ohm resistor

Soldering the buzzer

Soldering the 7 Segment displays

Soldering the LED pair

I will start by soldering the NodeMCU. Then, I will solder the 100Ω Resistor to the D8 pin of NodeMCU. After that I will solder the buzzer to a perfboard and will link it up to the NodeMCU. Next, I am going to solder the switch and install it at the back of the box. As per the schematic one pin of the switch will connect to the VIN of NodeMCU and the other one to the +ve terminal of the stepdown converter. The -ve end of the converter will connect to the GND pin of NodeMCU. Now, I am going to solder the 7-segments as per the schematic.

Next, I am soldering the blue and white LEDs to the D9 and D10 pins of NodeMCU. So, this is how my faceplate looks like. Let me do a quick test before installing the faceplate. Looks like everything is working the way they should. OK, so let me install the faceplate and then I will explain the code to you guys.

Step 9: The Code

/***********************************************************
 *  Read YouTube Channel statistics from the YouTube API   *
 *  By Brian Lough, Modified By Ashish Adhikari            *
 *  https://www.youtube.com/user/tarantula3                *
 ***********************************************************/

#include <YoutubeApi.h>       // A wrapper for the YouTube API for Arduino (works on ESP8266)
#include <ESP8266WiFi.h>      // The Wi-Fi library for ESP8266
#include <WiFiClientSecure.h> // Variant of WiFiClient with TLS support
#include <TM1637Display.h>    // This Library is to drive the TM1637 4 digits display
#include <ArduinoJson.h>      // This Sketch doesn't technically need this, but the library does so it must be installed.

// ------- Replace the following! ------ //
char ssid[]     = "XXXXXX";                                // your network SSID (name)
char password[] = "XXXXXXXX";                              // your network key
#define API_KEY "AIzaSyBNabchaXXXXXXXXXXXXXXXXX3ySg_mNbY"  // your google apps API Token
#define CHANNEL_ID "UCR0wao7J3htf9DjuVJ2uzUw"              // makes up the url of channel
// ------------------------------------- //

WiFiClientSecure client;
YoutubeApi api(API_KEY, client);

unsigned long api_mtbs = 120000; // Mean time between api requests - Change this to 5 minutes 
unsigned long counter = 0;       // Counter that increments every 10 milliseconds

// Module connection pins (Digital Pins)
#define CLK1 D3
#define DIO1 D2
#define CLK2 D1
#define DIO2 D0
#define CLK3 D5
#define DIO3 D4
#define CLK4 D6
#define DIO4 D7
TM1637Display display1(CLK1, DIO1);
TM1637Display display2(CLK2, DIO2);
TM1637Display display3(CLK3, DIO3);
TM1637Display display4(CLK4, DIO4);
long viewsLeft  = 0;
long viewsRight = 0;
long subLeft    = 0;
long subRight   = 0;
long OLDsub     = 0;

// Setting up the buzzer
int frequency = 1000; // Specified in Hz
int buzzPin   = D8;
int timeOn    = 500; // Specified in milliseconds
int timeOff   = 500; // Specified in milliseconds

// Setting up the LEDs
int BlueLED  = D9;
int WhiteLED = D10;
int LEDblinker = 0;

void setup() {

  Serial.begin(115200);

  // Set the LEDs
  pinMode(D9, OUTPUT);
  pinMode(D10, OUTPUT);
  digitalWrite(D9, HIGH);

  // Clear the display
  display1.setBrightness(0x0f);
  display1.showNumberDec(0, false, 4, 0);
  display2.setBrightness(0x0f);
  display2.clear();
  display3.setBrightness(0x0f);
  display3.showNumberDec(0, false, 4, 0);
  display4.setBrightness(0x0f);
  display4.clear();

  // Set WiFi to station mode and disconnect from an AP if it was Previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

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

void loop() {

  counter = counter + 10;
  if (counter > api_mtbs)  {      // Should a request be made?
    if(api.getChannelStatistics(CHANNEL_ID))
    {
      Serial.println("---------Stats---------");
      Serial.print("Subscriber Count: ");
      Serial.println(api.channelStats.subscriberCount);
      Serial.print("View Count: ");
      Serial.println(api.channelStats.viewCount);
      Serial.print("Video Count: ");
      Serial.println(api.channelStats.videoCount);
      Serial.println("------------------------");

      // Display the view count
      viewsRight = api.channelStats.viewCount % 10000;                 // Value on the right
      viewsLeft  = (api.channelStats.viewCount - viewsRight) / 10000;  // Value on the left     
      if(viewsLeft > 0) {       // Zero-padding to avoid a gap between the Left and Right displays
        display1.showNumberDec(viewsRight, true, 4, 0);
        display2.showNumberDec(viewsLeft, false, 4, 0);
      } else {
        display1.showNumberDec(viewsRight, false, 4, 0);
        display2.clear();
      }

      // Display the subscribers count
      subRight = api.channelStats.subscriberCount % 10000;               // Value on the right
      subLeft  = (api.channelStats.subscriberCount - subRight) / 10000;  // Value on the left
      if(subLeft > 0) {      // Zero-padding to avoid a gap between the Left and Right displays
        display3.showNumberDec(subRight, true, 4, 0);
        display4.showNumberDec(subLeft, false, 4, 0);
      } else {
        display3.showNumberDec(subRight, false, 4, 0);
        display4.clear();
      }

      // Ring the buzzer if a new subscriber is gained
      if ( api.channelStats.subscriberCount > OLDsub ) { // New subscriber Gained
        tone(buzzPin, frequency);
        delay(timeOn);
        noTone(buzzPin);
        delay(timeOff);
        OLDsub = api.channelStats.subscriberCount;
        LEDblinker = 1;
      }

    }
    counter = 0; // Reset counter after displaying the data
  }

  // Blink the LEDs
  if ( LEDblinker == 1 ) {
    if( counter == 10 || counter == 400 || counter == 800 || counter == 1200 || counter == 1600 || counter == 2000 ){
      digitalWrite(BlueLED, LOW); // Turn off the Blue LED
      digitalWrite(WhiteLED, HIGH); // Turn on the White LED
    } else if ( counter == 200 || counter == 600 || counter == 1000 || counter == 1400 || counter == 1800 ){
      digitalWrite(BlueLED, HIGH); // Turn on the Blue LED
      digitalWrite(WhiteLED, LOW); // Turn off the White LED      
    } else if ( counter == 2200 ) {
      LEDblinker = 0;               // Reset the blinker counter      
    }
  } else {
    digitalWrite(BlueLED, HIGH); // Turn on the Blue LED
    digitalWrite(WhiteLED, LOW); // Turn off the White LED
  }
  delay(10);
}

These are the list of the libraries that we need for this project.

Now, if you are using the same schematic as mine you don’t have to modify anything in this code other than these few lines. You just need to add the SSID and Password of your WiFI network and the Google API Key and the channels ID here. Rest you can leave as is and load the code to the NodeMCU.

The "api_mtbs" is the mean time between the API requests made by the microprocessor.

Then, I am initializing the displays by setting the clock and the data pins. After that I am setting up the buzzer and the 2 LEDs.
In the setup() section I am setting up the LED pin modes and turning the blue LED on at startup. Then I am clearing all the 7-Segments and displaying 0 on display 1 and 3. After that the device will connect to the WiFI network using the provided credentials.

In the loop() section when the value of the counter exceeded the api_mtbs or in simple terms, when the time comes to make the next request to the YouTube server, a API call with the channel ID is made and the result is displayed on the serial monitor and on the 7-Segment displays. You need to calculate the MOD of the count received to display the last 4 digits and then subtract the MOD value from the original value to get the first 4 digits. One thing I have noticed is that if the MOD is lets say 24 then the display only displays 24 and not 0024. So we will have to add the missing zeros to the display. This bit of the code is to add the missing 0's.

And finally, this bit of the code is to turn on the buzzer and the LEDs when the new subscriber count becomes greater than the old subscriber count.

Note: Pin D9 and D10 are the RX and TX pins of the NodeMCU. So, if you connect the LEDs to these pins you will not be able to get anything on the serial monitor. So, during the testing process do not connect anything to the D9 and D10 pins and comment the bit that sets the pin modes for these pins.

You can download the code from the link below.

Step 10: Future Enhancement

Planned future improvements

Attachment - Project Files

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Tags:

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.