ESP32 YouTube Subscriber Counter with a MAX7219 LED Matrix
Build an ESP32 YouTube subscriber counter: API key, channel ID, ArduinoJson parsing, MAX7219 scrolling text, quota table plus Instagram and TikTok notes.
A YouTube subscriber counter is a small gadget that reads your channel's subscriber count from the internet and shows it on an LED display on your desk. In this project the brain is an ESP32 with built-in Wi-Fi, and the display is a MAX7219 8x32 LED matrix made of four 8x8 blocks. Every few minutes the ESP32 sends a request to Google's official YouTube Data API v3, pulls the subscriber, view and video counts out of the JSON reply and shows them as scrolling text. You can build it in an evening, and the API is free.
In this guide you'll get an API key step by step, find your channel ID, work out the update rate with a quota table, and write two sketches: one that runs in the Serial Monitor and one that drives the MAX7219 display. You'll see how to read a large reply with an ArduinoJson filter, format the number with thousands separators and make requests without breaking the scrolling text. The last section explains what changes when you adapt the same device into an Instagram or TikTok follower counter.

How does a YouTube subscriber counter work?
The flow has four steps. First the ESP32 joins your home Wi-Fi. Then it sends a GET request over HTTPS to googleapis.com containing your channel ID and API key. The server returns a JSON reply of a few hundred bytes; its statistics section contains the subscriberCount, viewCount and videoCount fields. The ESP32 converts these strings into numbers and scrolls them across the MAX7219 with the MD_Parola library. After the request the device waits five minutes and the loop starts again, while the display keeps showing the count without a break.
| Part | Role | Note |
|---|---|---|
| ESP32 development board (DevKit) | Wi-Fi, HTTPS request, JSON parsing | Any ESP32 board works; ESP32-C3 and S3 too |
| MAX7219 8x32 LED matrix (FC-16 type) | Shows the count as scrolling text | 4 chained blocks; you can add up to 8 for a longer display |
| 5 V 2 A USB adapter | Powers the board and display | At full brightness the matrix can draw up to 1 A |
| 5 female-to-female jumper wires | VCC, GND, DIN, CS, CLK | Keep them short to avoid signal problems |
How to get a YouTube Data API key
- Sign in to the Google Cloud Console with your Google account and create a New Project from the top menu (e.g. sub-counter). You don't need to enable billing for this API.
- On the APIs & Services > Library page, search for YouTube Data API v3 and click Enable.
- On the APIs & Services > Credentials page choose Create credentials > API key; a 39-character key starting with AIza appears.
- On the key's edit page, under API restrictions > Restrict key, tick only YouTube Data API v3 and save.
- Before uploading any code, try the request in your browser: opening googleapis.com/youtube/v3/channels?part=statistics&id=CHANNEL_ID&key=KEY should show JSON.
Finding your channel ID
The API doesn't identify a channel by its @handle but by a 24-character ID starting with UC. The easiest way is to click your profile picture on YouTube and open Settings > Advanced settings; your own channel ID is there, ready to copy. For another channel, use Share channel > Copy channel ID in the description pop-up on the channel page. If you'd rather not look up the ID at all, the API's forHandle parameter does the job: just replace id=CHANNEL_ID in the code with forHandle=@yourhandle.
| Method | Where | Result |
|---|---|---|
| YouTube settings | Profile picture > Settings > Advanced settings | Your own channel's UC… ID |
| Channel page | Description pop-up > Share channel > Copy channel ID | The ID of any channel |
| Channel URL | A URL in the form youtube.com/channel/UC… | The last part of the URL is the ID |
| API with the handle | channels?part=statistics&forHandle=@handle | Statistics directly, no ID needed |
API reply, rounding and quota table
In the reply to the channels request, the first element of the items array is your channel; its statistics object holds subscriberCount, viewCount, videoCount and hiddenSubscriberCount. Watch out for two details. First, the numbers arrive in quotes, as strings; the code converts them with strtoull(). Second, since 2019 YouTube has abbreviated public subscriber counts: for channels above 1,000 subscribers the API rounds the number to its first three digits. So a channel with 12,345 subscribers shows 12,300, and the count only changes every hundred subscribers. Views and video counts arrive exact. If the owner has hidden the subscriber count, hiddenSubscriberCount is true.
| Real subscriber count | What the API returns | On the display |
|---|---|---|
| 847 | 847 | ABONE 847 |
| 12,345 | 12300 | ABONE 12.300 |
| 123,456 | 123000 | ABONE 123.000 |
| 1,234,567 | 1230000 | ABONE 1.230.000 |
Each Google Cloud project gets a free quota of 10,000 units per day, and a channels.list request costs only 1 unit. The quota resets at midnight Pacific Time. Failed requests also count against the quota, which is why the code doesn't retry immediately after an error but waits a minute. Because of the rounding, polling every second is pointless; a five-minute interval uses less than 3 percent of the quota and keeps the number fresh enough. If you use the same key on several devices, multiply by the number of devices.
| Update interval | Requests per day | Quota used | Comment |
|---|---|---|---|
| 10 seconds | 8,640 | 86% | Very close to the limit; a second device exceeds it |
| 1 minute | 1,440 | 14% | Reasonable during a live stream |
| 5 minutes | 288 | 3% | Recommended setting |
| 15 minutes | 96 | 1% | For battery or deep-sleep devices |
Wiring: ESP32 and MAX7219
| MAX7219 pin | ESP32 | Note |
|---|---|---|
| VCC | VIN (5 V) | The matrix runs on 5 V; don't use the 3V3 pin |
| GND | GND | Common ground |
| DIN | GPIO 23 (MOSI) | Hardware SPI data line |
| CS (LOAD) | GPIO 5 | CS_PIN in the code |
| CLK | GPIO 18 (SCK) | Hardware SPI clock line |
Plug the wires into the module's input side marked DIN; the OUT side goes to the next module. At a 5 V supply the MAX7219 expects at least 3.5 V for a HIGH signal, while the ESP32 outputs 3.3 V. With short wires most modules work fine, but if you see random dots, adding a 74HCT125 or a logic level converter to DIN, CS and CLK is the sure fix. How the module works, special characters and the FC16_HW setting are explained in detail in the MAX7219 LED matrix guide. You can look up the ESP32 pins in the pinout tool.
Step by step: test in the Serial Monitor first
- In the Arduino IDE Boards Manager install the esp32 package (Espressif Systems) and select ESP32 Dev Module as the board.
- In the Library Manager install ArduinoJson (Benoit Blanchon, 7.x) and MD_Parola; accept if it offers to install MD_MAX72XX as well.
- In the test sketch below, fill in your Wi-Fi name, password, API key and channel ID.
- Upload the code, open the Serial Monitor at 115200 baud and check for the HTTP 200 line followed by the subscriber count.
- If everything is right, connect the display and move on to the full sketch.
1// ESP32 YouTube abone sayısı testi (Seri Monitör) / YouTube subscriber count test (Serial Monitor)
2#include <WiFi.h>
3#include <WiFiClientSecure.h>
4#include <HTTPClient.h>
5#include <ArduinoJson.h> // "ArduinoJson" (Benoit Blanchon) v7
6
7const char* WIFI_SSID = "WIFI_ADIN"; // Wi-Fi adın / your Wi-Fi name
8const char* WIFI_PASS = "WIFI_SIFRESI"; // Wi-Fi şifren / your Wi-Fi password
9const char* API_KEY = "API_ANAHTARIN"; // Google Cloud API anahtarı / API key
10const char* CHANNEL_ID = "UCxxxxxxxxxxxxxxxxxxxxxx"; // UC ile başlayan 24 karakter / 24 chars starting with UC
11
12void setup() {
13 Serial.begin(115200);
14 WiFi.mode(WIFI_STA);
15 WiFi.begin(WIFI_SSID, WIFI_PASS);
16 Serial.print("Wi-Fi");
17 while (WiFi.status() != WL_CONNECTED) { // bağlanana kadar bekle / wait until connected
18 delay(500);
19 Serial.print('.');
20 }
21 Serial.println(" OK");
22
23 WiFiClientSecure client;
24 client.setInsecure(); // sertifika doğrulaması yok (basit test) / no certificate check (simple test)
25 HTTPClient http;
26 String url = String("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=")
27 + CHANNEL_ID + "&key=" + API_KEY;
28 http.begin(client, url);
29 int code = http.GET(); // 200 = başarılı / success
30 String body = http.getString();
31 http.end();
32 Serial.printf("HTTP %d\n", code);
33 Serial.println(body); // ham JSON / raw JSON
34 if (code != 200) return;
35
36 JsonDocument doc;
37 if (deserializeJson(doc, body)) {
38 Serial.println("JSON hatasi / JSON error");
39 return;
40 }
41 JsonVariant stats = doc["items"][0]["statistics"];
42 if (stats.isNull()) { // items boş: kimlik yanlış / empty items: wrong ID
43 Serial.println("Kanal bulunamadi / channel not found");
44 return;
45 }
46 Serial.printf("Abone / Subscribers: %s\n", stats["subscriberCount"] | "?");
47 Serial.printf("Izlenme / Views: %s\n", stats["viewCount"] | "?");
48 Serial.printf("Video: %s\n", stats["videoCount"] | "?");
49}
50
51void loop() {}
52The test sketch prints the raw reply first, so you can see the structure of the JSON with your own eyes. The setInsecure() call opens the HTTPS connection without checking the server certificate. The connection is still encrypted, but nobody verifies that the server really is Google; for a desk counter that's an acceptable shortcut. For adding the root certificate with setCACert() and other HTTPS details, see the ESP32 weather API article. If the Serial Monitor shows a code other than 200, the table below tells you why.
| Result | Meaning | Fix |
|---|---|---|
| HTTP 400, API key not valid | The key was copied incorrectly | Copy the key again, including the leading AIza |
| HTTP 403, accessNotConfigured | YouTube Data API v3 isn't enabled in the project | Enable the API on the Library page and wait a few minutes |
| HTTP 403, quotaExceeded | The daily 10,000 units are used up | Lengthen the interval and wait for the reset |
| HTTP 200 but no items | Wrong channel ID | Check the 24 characters starting with UC or use forHandle |
| HTTP -1 or another negative code | Couldn't reach the server | Check the Wi-Fi signal and internet connection |
Full sketch: scrolling subscriber count on the MAX7219
The full sketch scrolls the subscriber, view and video counts one after another. The request is made right when a scrolling cycle ends, so even though the TLS connection takes a second or two, the text never freezes mid-scroll. The reply is read directly from the stream with http.getStream(), and the ArduinoJson filter keeps only three fields in memory. The useHTTP10(true) line stops the server from sending a chunked reply, which would otherwise break reading from the stream. If Wi-Fi drops, the ESP32 reconnects on its own and the display keeps showing the last known values meanwhile.
1// ESP32 + MAX7219 8x32: YouTube abone sayacı / YouTube subscriber counter
2#include <WiFi.h>
3#include <WiFiClientSecure.h>
4#include <HTTPClient.h>
5#include <ArduinoJson.h> // v7
6#include <MD_Parola.h> // MD_MAX72XX ile birlikte / together with MD_MAX72XX
7#include <MD_MAX72xx.h>
8#include <SPI.h>
9
10#define HARDWARE_TYPE MD_MAX72XX::FC16_HW // yaygın 4'lü modül / common 4-in-1 module
11#define MAX_DEVICES 4 // 8x8 blok sayısı / number of 8x8 blocks
12#define CS_PIN 5 // DIN = GPIO 23, CLK = GPIO 18 (donanım SPI / hardware SPI)
13
14const char* WIFI_SSID = "WIFI_ADIN";
15const char* WIFI_PASS = "WIFI_SIFRESI";
16const char* API_KEY = "API_ANAHTARIN";
17const char* CHANNEL_ID = "UCxxxxxxxxxxxxxxxxxxxxxx";
18const unsigned long UPDATE_MS = 5UL * 60UL * 1000UL; // 5 dakikada bir = 288 birim/gün / every 5 min = 288 units/day
19const unsigned long RETRY_MS = 60UL * 1000UL; // hata sonrası 1 dk bekle / wait 1 min after an error
20
21MD_Parola matrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
22char message[48] = "YouTube"; // ekrandaki yazı / text on the display
23uint64_t subs = 0, views = 0, videos = 0;
24bool haveData = false; // en az bir başarılı okuma / at least one good read
25bool tried = false;
26unsigned long lastTry = 0;
27byte page = 0; // 0 abone, 1 izlenme, 2 video / 0 subs, 1 views, 2 videos
28
29// 1234567 -> "1.234.567" (binlik ayırıcı nokta / dot as thousands separator)
30void formatNumber(uint64_t n, char* out) { // out en az 27 bayt / at least 27 bytes
31 char rev[32];
32 int i = 0, digits = 0;
33 do {
34 if (digits > 0 && digits % 3 == 0) rev[i++] = '.';
35 rev[i++] = '0' + (n % 10);
36 n /= 10;
37 digits++;
38 } while (n > 0);
39 for (int j = 0; j < i; j++) out[j] = rev[i - 1 - j]; // ters çevir / reverse
40 out[i] = '\0';
41}
42
43bool fetchStats() {
44 WiFiClientSecure client;
45 client.setInsecure(); // basitlik için / for simplicity
46 HTTPClient http;
47 http.useHTTP10(true); // parçasız cevap, akıştan oku / no chunked reply, read the stream
48 String url = String("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=")
49 + CHANNEL_ID + "&key=" + API_KEY;
50 if (!http.begin(client, url)) return false;
51 int code = http.GET();
52 bool ok = false;
53 if (code == 200) {
54 JsonDocument filter; // yalnız gereken alanlar / only the fields we need
55 filter["items"][0]["statistics"]["subscriberCount"] = true;
56 filter["items"][0]["statistics"]["viewCount"] = true;
57 filter["items"][0]["statistics"]["videoCount"] = true;
58 JsonDocument doc;
59 DeserializationError err = deserializeJson(doc, http.getStream(), DeserializationOption::Filter(filter));
60 JsonVariant s = doc["items"][0]["statistics"];
61 if (!err && !s.isNull()) {
62 subs = strtoull(s["subscriberCount"] | "0", nullptr, 10); // sayılar metin gelir / numbers arrive as text
63 views = strtoull(s["viewCount"] | "0", nullptr, 10);
64 videos = strtoull(s["videoCount"] | "0", nullptr, 10);
65 ok = true;
66 }
67 }
68 http.end();
69 Serial.printf("HTTP %d, abone/subs %lu\n", code, (unsigned long)subs);
70 return ok;
71}
72
73void showNext() {
74 char num[28];
75 switch (page) {
76 case 0: formatNumber(subs, num); snprintf(message, sizeof(message), "ABONE %s", num); break;
77 case 1: formatNumber(views, num); snprintf(message, sizeof(message), "IZLENME %s", num); break;
78 default: formatNumber(videos, num); snprintf(message, sizeof(message), "VIDEO %s", num); break;
79 }
80 page = (page + 1) % 3;
81 matrix.displayText(message, PA_CENTER, 40, 3000, PA_SCROLL_LEFT, PA_SCROLL_LEFT); // hız 40 ms, bekleme 3 sn / speed 40 ms, pause 3 s
82}
83
84void setup() {
85 Serial.begin(115200);
86 matrix.begin();
87 matrix.setIntensity(3); // parlaklık 0-15 / brightness 0-15
88 matrix.displayText(message, PA_CENTER, 40, 1000, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
89 WiFi.mode(WIFI_STA);
90 WiFi.begin(WIFI_SSID, WIFI_PASS);
91}
92
93void loop() {
94 if (!matrix.displayAnimate()) return; // animasyon sürüyor / animation still running
95 // Bir tur bitti: istek burada, kayan yazı takılmaz / a cycle ended: fetch here so scrolling never stutters
96 if (WiFi.status() == WL_CONNECTED) {
97 unsigned long wait = haveData ? UPDATE_MS : RETRY_MS;
98 if (!tried || millis() - lastTry >= wait) {
99 tried = true;
100 lastTry = millis();
101 if (fetchStats()) haveData = true;
102 }
103 }
104 if (haveData) {
105 showNext();
106 } else {
107 strcpy(message, WiFi.status() == WL_CONNECTED ? "API ?" : "WiFi...");
108 matrix.displayReset();
109 }
110}
111| Code part | What it does |
|---|---|
| FC16_HW, MAX_DEVICES 4 | Hardware type and block count of the common 4-in-1 module |
| UPDATE_MS / RETRY_MS | Waits 5 minutes after a good read and 1 minute after an error |
| DeserializationOption::Filter | Keeps only three numbers out of dozens of fields in the reply |
| strtoull() | Turns the number that arrives as text into a 64-bit integer; even billions of views fit |
| formatNumber() | Formats 1230000 as 1.230.000 |
| When displayAnimate() returns true | A text cycle has ended; the request and the next text are prepared here |
Update rate and scrolling text settings
The parameters of displayText() set the character of the display: 40 is the number of milliseconds between scroll steps (smaller is faster), and 3000 is how long the text pauses in the middle. Instead of PA_SCROLL_LEFT you can try effects such as PA_SCROLL_UP, PA_OPENING or PA_FADE. setIntensity() sets the brightness between 0 and 15; 1 is usually enough at night and 5 during the day, and lower brightness also reduces the current. About 5 digits fit on the 32-column display; once your subscriber count passes 99,999 the text scrolls anyway. The labels ABONE, IZLENME and VIDEO are Turkish; replace them with SUBS, VIEWS and VIDEOS in showNext() if you prefer. To add a clock page, take the code from the ESP32 NTP clock article, and to enter network details from your phone instead of hard-coding them, WiFiManager also makes the device easy to give as a gift.
Adapting it to Instagram and TikTok counters
The display, Wi-Fi and JSON parts stay the same; only the URL and the authentication change. Instagram and TikTok don't hand out a simple API key like YouTube: both require an access token obtained with the account owner's consent, and that token has to be refreshed regularly. That's why these counters only work for your own account and need a bit more setup. Scraping the public profile page for the number violates the platforms' rules and breaks whenever the page layout changes; the official APIs are always more reliable. Putting the reply's field name into the filter and the strtoull() line is all the rest of the code needs.
| Platform | Request URL and field | Requirements | Watch out |
|---|---|---|---|
| YouTube | youtube/v3/channels?part=statistics → subscriberCount | API key | 10,000 units per day; the count is rounded to 3 digits |
| graph.facebook.com/v21.0/{ig-user-id}?fields=followers_count | Business or creator account, linked Facebook Page, access token | A long-lived token lasts 60 days and must be refreshed before it expires | |
| TikTok | open.tiktokapis.com/v2/user/info/?fields=follower_count | TikTok for Developers app, user.info.stats scope, OAuth login | The access token lasts 24 hours and is renewed with the refresh token |
YouTube subscriber counter project ideas
- Goal bar: show how far you are from 1,000 or 10,000 subscribers as a percentage and flash the display when you reach it.
- Colour counter: use a WS2812B LED matrix instead of the MAX7219 and play a green animation when subscribers go up.
- Sound effect: play a short tune on a buzzer whenever a new subscriber arrives.
- Small-screen version: show the count and channel name on an SSD1306 OLED display and make it pocket-sized.
- Notification: send a message to your phone with a Telegram bot every time you gain another thousand subscribers.
Common mistakes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| The display keeps showing WiFi... | Wrong network name or password, or a 5 GHz network | The ESP32 only joins 2.4 GHz networks; check your details |
| The display shows API ? | The request failed | Read the HTTP code in the Serial Monitor with the test sketch and compare it with the table |
| The number never changes | The subscriber count is rounded | That's normal; numbers like 12,300 only change every hundred subscribers |
| Letters are mirrored or rotated | Wrong hardware type | Set HARDWARE_TYPE to FC16_HW |
| The display flickers or the ESP32 restarts | The USB port can't supply enough current | Use a 5 V 2 A adapter and lower the brightness |
| The counter stops the next day | Quota used up or the key is also used elsewhere | Check the quota chart in Google Cloud and lengthen the interval |
If you want to try the basic steps one at a time, such as connecting the ESP32 to Wi-Fi, fetching data from the internet and showing it on a display, the BlueGrays app has ESP32 projects for a Wi-Fi connection, a weather API with HTTPClient and an LED matrix animation, each with a circuit diagram and ready-made code; the subscriber counter is simply these pieces combined.
Frequently asked questions
Is the YouTube Data API free?
Yes. Every Google Cloud project gets a free quota of 10,000 units per day, and you don't need to enable billing. The channels.list request that reads the subscriber count costs 1 unit, so a single counter uses only a tiny part of that quota.
Why is the YouTube subscriber count rounded?
Since 2019 YouTube has abbreviated public subscriber counts, and the API returns the same rounded value. For channels above 1,000 subscribers the number is rounded to its first three digits; 12,345 subscribers arrive as 12,300. Only the channel owner can see the exact number in YouTube Studio.
How do I find a YouTube channel ID?
Click your profile picture on YouTube and open Settings > Advanced settings to see the 24-character ID starting with UC. For another channel, copy the ID from the Share channel menu on the channel page. Instead of the ID, you can also use the API's forHandle=@handle parameter.
How often should a subscriber counter update?
Updating every five minutes keeps the number fresh and uses less than 3 percent of the daily quota. Because the count is rounded, polling more often makes no visible difference. If several devices share the same API key, add up their requests.
Can I build a subscriber counter with an ESP8266?
Yes. On the ESP8266 you use ESP8266WiFi.h and ESP8266HTTPClient.h instead of WiFi.h, and the BearSSL version of WiFiClientSecure; the logic is the same. For the MAX7219, DIN goes to D7 and CLK to D5. The ESP32 has more RAM, so it handles HTTPS more comfortably.
How do I make an Instagram follower counter?
By reading the followers_count field with the Instagram Graph API. Your account must be a business or creator account linked to a Facebook Page, and you need a long-lived access token. The token is valid for 60 days, so it must be refreshed before it expires.
Projects to build after reading this
See all projects
LED Blink with ESP32
Teaches basic GPIO output usage with ESP32. We achieve a blinking effect by turning an LED on and off from a digital pin. ESP32 version of the classic blink project on Arduino UNO; the basic blink commands in the Arduino environment are the same, but the ESP32's pin layout and 3.3 V GPIO levels differ from those of the Arduino UNO.

ESP32 Wi-Fi STA Connection (with LCD Screen)
In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.

ESP32 HTTPClient + Weather API (with LCD Screen)
In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. The JSON response is parsed with ArduinoJson v7, and the city, temperature, humidity, weather and wind are shown on an I2C LCD. wttr.in needs no API key; just type the name of any city.

ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)
In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. Unlike the I2C LCD version, it uses an SSD1306 OLED (128×64) display, with large text and vector icons for a richer look. Seven weather icons (sunny, rainy, snowy and more) are drawn on the fly, with no bitmap files.

Real-Time Clock from the Internet via ESP32 NTP
The ESP32 connects to Wi-Fi and fetches the real time from NTP (Network Time Protocol) servers with millisecond precision. configTzTime() applies the Turkey time zone (TRT, UTC+3) automatically, and in countries with daylight saving time the DST switch is handled by a POSIX TZ string. The time is printed both to the Serial Monitor and to an optional I2C LCD.

4x 32x8 Matrix LED Animation and Text
Stack four long LED matrix modules on top of each other and you get a square screen with more than a thousand dots of light.

4x 32x8 LED Matrix - 6-Animation Pack
Four 32x8 LED panels stacked on top of each other form a square screen where six animations play in turn: falling digital rain, a growing spiral, cells that are born and die all by themselves…

Dot Matrix Clock and Calendar (MAX7219, DS1307)
A glowing board for your desk or wall that shows the time and date in scrolling text.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

