You are currently viewing WiFi  YouTube subscribers counter wall frame using NodeMCU

WiFi YouTube subscribers counter wall frame using NodeMCU

SuperKitz.com ​Project Manual

WiFi YouTube subscribers counter wall frame using NodeMCU  (ESP8266) DIY Kit

TM1637 8 segment display and esp8266.

For this project, we will be making a simple In this tutorial a  DIY YouTube subscriber counter. It uses the 8  segment  display  to display the subscriber count with big easy to see from distance numbers. The enclosure of the counter is 3D printed/foam board. Hope the  YouTube subscriber counter to help me stay motivated! Producing videos requires a great amount of time and effort. When you know that tons people are waiting for a video from superkitz.com , we work harder and harder for you keep all these people satisfied, it gives you a great motive. So, this counter will help us stay focused. 

Requirements :

  • Computer/Smartphone with an internet connection
  • Download and install Arduino IDE

Components

NodeMCU ESp8266

1 nos

Breadboard

1 nos

TM1637 4 Digits 7 Segment Led Display Module

1 nos

Jumper wires

1 nos

photo frame 6*4''

1 nos

Hardware

NODE MCU esp8266

node mcu 8266 wifi

Node mcu is a micro controller which is made under the LUA based firmware and architecture made for IOT application . It also includes expressif systems and hardware firmware ,which is based on the ESP-12 module. It is a very capable microcontroller which can be used easily for IOT applications with the blynk-app . The features are :

  • The operating voltage is 5V
  • The input voltage is between 7-12 v
  • Digital input/output pins are 16
  • Analog i/p pins is 1
  • Flash Memory is 4 MB
  • SRAM is 64 KB
  • CLK Speed is 80 MHz
node mcu esp 8266 pin out

Pin out diagram
ESP8266

TM1637 4 Digits 7 Segment Led Display Module

4 digit 7-segment display is a very efficient module which is very cost effective ,we can see alot of devices using this module .TM1637 is the IC controlling this module .  We can use any microcontroller like the arduino or the NODE MCU to communicate with this module through the 2 signal pins .

Features of the TM1637 module

  • Common anode for the 4 ked segment display
  • 3.3/5v 
  • TM1637 is the IC used 
  • 2 signal lines to control all the 4 different 7 segment displays

Circuit Diagram

Reed Switch Connection Diagram
With ESP8266

Wiring – Connecting TM1637 4-digit 7-segment display to  NodeMCU

TM1637 4-Digit Display NodeMCU
VCC 5 V    GND GND
CLK D2         DIO D3

  • Connect all the components provided in the kit according to the provided wiring diagram mention in the documentation.

Print Paper Template [A4 ]

Here is a printable template.

Let’s do that first. So, we have log in to our Google Account and visit the developer console. (https://console.developers.google.com) We click to create a new project, we give it a name and we press create. Then with the new project selected we enable the YouTube Data API. The last step is create Credentials. We press the Credentials key and then from the window that appears we select to create a new API key. We press close and we are done. For more details, check screenshot  the video attached to the first step.

Then we connect to the WiFi and we get the subscribers every minute. In order to get the subscriber count, we send a request to a google server, and we parse the JSON fine it responds using the ArduinoJSON library. We save the subscriber count into a variable. In the loop function we check if there is a change in the subscriber count, we clear the display and we print the new number.

Getting a Google Apps API key

https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UCezJOfu7OtqGzd5xrP3q6WA&key=PutYourNewlyGeneratedKeyHere

If everything is working correctly you should see the JSON channel statistics for my YouTube channel!

Getting a channel ID

Go to youtube Settings –> Advance Setting –> Youtube Channel ID 

PROGRAMMING

The NodeMCU programming can be as easy as in Arduino, the main difference is the distribution of pins in the nodemcu board. Following below operations and enjoy your first NodeMCU & Arduino IDE

Step 1: Install the Arduino IDE 1.6.4 or Greater

Download Arduino IDE from Arduino.cc / superkitz.com You can use your existing IDE if you have already installed it. You can also try downloading the ready-to-go package from the ESP8266-Arduino project if the proxy is giving you problems.

Download Arduino IDE

In order to upload code to the ESP8266 and use the serial console, connect any data-capable micro USB cable to ESP8266 IOT Board and the other side to your computer’s USB port.

 

The new version NodeMCUv1.0 comes with the CP2102 serial chip, you can download (also provided with the kit)  and install the driver from https://www.silabs.com/products/development-tools/…. The NodeMCUv0.9 comes with the CH340 serial chip, you can download and install the driver from: https://github.com/nodemcu/nodemcu-devkit/tree/mas…

 

 

Step 2: Installing NodeMCU package for Arduino IDE

Paste the copied link(givenbelow) and insert it(add. boad Manager URL) in Arduino IDE using the following sequence->File menu -> Preferences-> Paste copied link into the area shown in the black box in the above image. Close and restart the Arduino IDE.

The link should look something like this:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Paste the copied link and insert it in Arduino IDE using the following sequence->File menu -> Preferences-> Paste copied link into the area shown in the black box in the above image. Close and restart the Arduino IDE.

Tools -> Boards manager and search for ESP8266 and install the libraries/files given under the heading ESP8266 by ESP community.

Restart the Arduino IDE once again.

The NodeMCU programming can be as easy as in Arduino, the main difference is the distribution of pins in the nodemcu board. Following below operations and enjoy your first NodeMCU & Arduino IDE

Step 1: Install the Arduino IDE 1.6.4 or Greater

Download Arduino IDE from Arduino.cc / superkitz.com You can use your existing IDE if you have already installed it. You can also try downloading the ready-to-go package from the ESP8266-Arduino project if the proxy is giving you problems.

Scroll down, select the ESP8266 board menu and install “esp8266 by ESP8266 Community”, as shown in the figure below.

If you used the Installer, Windows – from XP up to 10 – 

  1. Delete the Documents -> Arduino -> Libraries to remove all your libraries.
  2. Delete the User -> AppData -> Local -> Arduino15 folder to remove all the preferences.
  3. Uninstall Arduino IDE.
  4. Install a fresh one.

If you used the -Mac OX  from  –

First of all, make sure to log into your Mac with an administrator account, or you will be asked for a password when you try to delete something.

Open the Applications folder in the Finder (if it doesn’t appear in the sidebar, go to the Menu Bar, open the “Go” menu, and select Applications in the list), search for Arduino 1.6.4 application by typing its name in the search field, and then drag it to the Trash (in the dock) to begin the uninstall process. Alternatively you can also click on the Arduino 1.6.4 icon/folder and move it to the Trash by pressing Cmd + Del or choosing the File and Move to Trash commands.

Remove all components related to Arduino 1.6.4 in Finder
Though Arduino 1.6.4 has been deleted to the Trash, its lingering files, logs, caches and other miscellaneous contents may stay on the hard disk. For complete removal of Arduino 1.6.4, you can manually detect and clean out all components associated with this application. You can search for the relevant names using Spotlight. Those preference files of Arduino 1.6.4 can be found in the Preferences folder within your user’s library folder (~/Library/Preferences) or the system-wide Library located at the root of the system volume (/Library/Preferences/), while the support files are located in “~/Library/Application Support/” or “/Library/Application Support/”.

Open the Finder, go to the Menu Bar, open the “Go” menu, select the entry:|Go to Folder… and then enter the path of the Application Support folder:~/Library

Search for any files or folders with the program’s name or developer’s name in the ~/Library/Preferences/, ~/Library/Application Support/ and ~/Library/Caches/ folders. Right click on those items and click Move to Trash to delete them.

 

Go to Tools – Boards (scroll down the list of boards) – Select NodeMCU 1.0 ( ESP-12EModule).

Select the Port number at which you have connected nodeMCU. The rest of the settings can be left to default values.

Install Libraries for Arduino IDE

 Install Arduino-youtube-api as ZIP file in Arduino IDE

Arduino-youtube-api library is available as a downloadable ZIP . Starting with Arduino IDE version 1.0.5, you can install 3rd party libraries in the IDE.

Download Blynk Library by clicking the button: Download arduino-youtube-api

Do not unzip the downloaded library, leave it as is.

  1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At the top of the drop down list, select the option to “Add .ZIP Library‘. 
  2. Then select the library zip file you have downloaded. 
  3. Return to the Sketch > Include Library menu. menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch. The zip file will have been expanded in the libraries folder in your Arduino sketches directory.

Install Arduino-youtube-api as ZIP file in Arduino IDE

Arduino-youtube-api library is available as a downloadable ZIP . Starting with Arduino IDE version 1.0.5, you can install 3rd party libraries in the IDE.

Download Blynk Library by clicking the button: Download arduino-youtube-api

Install Grove_4Digital_Display-master as ZIP file in Arduino IDE

Grove_4Digital_Display-master library is available as a downloadable ZIP . Starting with Arduino IDE version 1.0.5, you can install 3rd party libraries in the IDE.

Download Blynk Library by clicking the button: DownloadGrove_4Digital_Display-master ArduinoJson-6

Arduino Code

Download the Arduino source code.

 There are two functions to send data to the Blynk App. The first function sends water and soil moisture levels.

The Arduino Blynk library has a method called virtualWrite ( ) to write the sensor reading into virtual pins we have already configured in our Blynk app.

Before sending the values, we must configure the Wi-Fi settings.

Then, click the Upload button in the Arduino IDE and wait a few seconds until you see the message “Done uploading.” in the bottom left corner.


#include "TM1637.h"
#define CLK D2//pins definitions for TM1637 and can be changed to other ports
#define DIO D3
TM1637 tm1637(CLK,DIO);
#include
#include 
int8_t ListDisp[4];
int NumTab;
#include 
//------- Replace the following! ------
char ssid[] = "YourWIFI";       // your network SSID (name)
char password[] = "password";  // your network key
#define API_KEY "AIzaSyDZ_7MOasxejg9U_IZ7iUWCRVYm2ux-4a4"  // your google apps API Token
#define CHANNEL_ID "UCAEAFiaYwHexG4lm2U_JiNA" // makes up the url of channel
//------- ---------------------- ------
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);
unsigned long timeBetweenRequests = 60000;
unsigned long nextRunTime;
long subs = 0;
void setup() {
   tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  Serial.begin(115200);
  // 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);

  // Required if you are using ESP8266 V2.5 or above
  client.setInsecure();

  // If you want to enable some extra debugging
  api._debug = true;
}

void loop() {

  if (millis() > nextRunTime)  {
    if(api.getChannelStatistics(CHANNEL_ID))
    {
      Serial.println("---------Stats---------");
      Serial.print("Subscriber Count: ");
      Serial.println(api.channelStats.subscriberCount);
      NumTab = api.channelStats.subscriberCount;
      Serial.print("View Count: ");
      Serial.println(api.channelStats.viewCount);
      Serial.print("Comment Count: ");
      Serial.println(api.channelStats.commentCount);
      Serial.print("Video Count: ");
      Serial.println(api.channelStats.videoCount);
      // Probably not needed :)
      //Serial.print("hiddenSubscriberCount: ");
      //Serial.println(api.channelStats.hiddenSubscriberCount);
      Serial.println("------------------------");
      unsigned char i = 0;
      unsigned char count = 0;
      for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++)
    {
      ListDisp[BitSelect] = NumTab%10;
      NumTab=NumTab/10;
      i ++;
      if(i == sizeof(NumTab)) i = 0;
    }
    tm1637.display(3,ListDisp[0]);
    tm1637.display(2,ListDisp[1]);
    tm1637.display(1,ListDisp[2]);
    tm1637.display(0,ListDisp[3]);
    }
    nextRunTime = millis() + timeBetweenRequests;
  }
} 

Output

Whenever the new subscribers is aviable to your channel the    segment display will be updated.

Here is an example

Open the serial monitor to view the details.

Leave a Reply