Tutorial Belanja komponen

Tutorial › Layar

Papan Skor Pertandingan

ESP-12ED0D1D2D3D43VGD5D6D7D8RXTXG3VA0GVUS3S2S1SCS0SKG3VENRSTGVIN8888:CLKDIOVCCGNDDisplay 7 segmen 4 digit TM1637

Papan skor untuk futsal, bulu tangkis, atau lomba 17-an: skor tim A dan tim B tampil sebagai AA:BB di display merah, dan wasit menambah atau mengurangi skor dari HP. Penonton di rumah juga bisa melihat skor terkini di Klenik.

Display 4 digit dibagi dua: dua digit kiri untuk tim A, dua digit kanan untuk tim B, dipisah titik dua. Skor A dikali 100 lalu ditambah skor B, jadi A = 3 dan B = 12 menjadi 0312, yang tampil sebagai 03:12. Karena itu skor dibatasi 0-99.

Setiap tombol di dashboard berupa switch dengan topic sendiri. NodeMCU memproses pesan ON, lalu mengirim OFF kembali ke topic yang sama (mqtt.publish(t, ...), memakai topic yang baru diterima). Akibatnya switch langsung kembali ke posisi semula seperti tombol tekan.

Komponen

KomponenQtyHarga
NodeMCU ESP8266 V3 (Lolin)1Rp42.000
TM1637 Seven Segment 4 Digit Modul1Rp9.500
Kabel jumper female-female 10 cm (isi 10)isi 10, terpakai 41Rp3.500
Kabel micro USB data 30 cmopsional, kalau belum punya kabel micro USB data1Rp11.700
Total (tanpa opsional)Rp55.000
Daftar komponen proyek ini otomatis masuk ke pesan. Hapus yang sudah kamu punya sebelum dikirim.

Langkah 1: Rangkai komponen

Sambungkan kabel sesuai gambar di atas. Kalau gambar dan tabel terlihat berbeda, ikuti tabel.

DariKeKabel
Display 7 segmen 4 digit TM1637 CLK→D1 GPIO5kuning
Display 7 segmen 4 digit TM1637 DIO→D2 GPIO4biru
Display 7 segmen 4 digit TM1637 VCC→3Vmerah
Display 7 segmen 4 digit TM1637 GND→Ghitam

Langkah 2: Siapkan dashboard Klenik

Tim A +1ichibot/budi1234/p109/a_plus
A +1
0 detik lalu
Tim B +1ichibot/budi1234/p109/b_plus
B +1
0 detik lalu
Tim A −1ichibot/budi1234/p109/a_minus
A −1
0 detik lalu
Tim B −1ichibot/budi1234/p109/b_minus
B −1
0 detik lalu
Skor Ulangichibot/budi1234/p109/ulang
0:0
0 detik lalu
Skor Aichibot/budi1234/p109/skorA
0 – 303
0 detik lalu
Skor Bichibot/budi1234/p109/skorB
0 – 3012
0 detik lalu

Cara cepat: unduh p109.json, ganti budi1234 dengan KODE-mu, lalu import di Klenik (menu titik tiga → Export / Import → Import → Ganti total). Langkah lengkapnya ada di Panduan Klenik.

WidgetTopicSetting
Switch
Tim A +1
ichibot/KODE/p109/a_pluspayload ON / OFF
Switch
Tim B +1
ichibot/KODE/p109/b_pluspayload ON / OFF
Switch
Tim A −1
ichibot/KODE/p109/a_minuspayload ON / OFF
Switch
Tim B −1
ichibot/KODE/p109/b_minuspayload ON / OFF
Switch
Skor Ulang
ichibot/KODE/p109/ulangpayload ON / OFF
Gauge
Skor A
ichibot/KODE/p109/skorA0–30
Gauge
Skor B
ichibot/KODE/p109/skorB0–30

Langkah 3: Upload kode

Library: PubSubClient (Nick O'Leary), TM1637 (Avishay Orpaz). Board di Arduino IDE: NodeMCU 1.0 (ESP-12E Module). Isi dulu nama WiFi dan password di bagian ISI DULU, lalu ganti budi1234 di baris topic dengan KODE-mu, lalu upload dan buka Serial Monitor (115200).

p109.inoUnduh .ino
// Proyek 109 - Papan Skor Pertandingan
// Board: NodeMCU ESP8266 V3 | Dashboard: klenik.ichibot.id
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <TM1637Display.h>

// ===== ISI DULU =====
const char* WIFI_NAMA = "nama-wifi-kamu";
const char* WIFI_PASS = "password-wifi-kamu";

// topic MQTT: ganti budi1234 dengan KODE-mu (sama dengan di dashboard Klenik)
const char* TOPIK_SKOR_A  = "ichibot/budi1234/p109/skorA";
const char* TOPIK_SKOR_B  = "ichibot/budi1234/p109/skorB";
const char* TOPIK_A_PLUS  = "ichibot/budi1234/p109/a_plus";
const char* TOPIK_B_PLUS  = "ichibot/budi1234/p109/b_plus";
const char* TOPIK_A_MINUS = "ichibot/budi1234/p109/a_minus";
const char* TOPIK_B_MINUS = "ichibot/budi1234/p109/b_minus";
const char* TOPIK_ULANG   = "ichibot/budi1234/p109/ulang";

const char* BROKER = "mqtt.ichibot.id";
WiFiClient wifi;
PubSubClient mqtt(wifi);
TM1637Display angka(D1, D2);
int skorA = 0, skorB = 0;

void tampilkan() {
  angka.showNumberDecEx(skorA * 100 + skorB, 0b01000000, true);   // AA:BB
  mqtt.publish(TOPIK_SKOR_A, String(skorA).c_str(), true);
  mqtt.publish(TOPIK_SKOR_B, String(skorB).c_str(), true);
}

void pesanMasuk(char* t, byte* isi, unsigned int panjang) {
  String topik = t;
  String p;
  for (unsigned int i = 0; i < panjang; i++) p += (char)isi[i];
  if (p != "ON") return;              // semua tombol berupa switch: hanya ON yang diproses
  if (topik == TOPIK_A_PLUS) skorA++;
  else if (topik == TOPIK_B_PLUS) skorB++;
  else if (topik == TOPIK_A_MINUS) skorA--;
  else if (topik == TOPIK_B_MINUS) skorB--;
  else if (topik == TOPIK_ULANG) { skorA = 0; skorB = 0; }
  skorA = constrain(skorA, 0, 99);
  skorB = constrain(skorB, 0, 99);
  mqtt.publish(t, "OFF");             // kembalikan switch ke OFF
  tampilkan();
}

void langganan() {
  mqtt.subscribe(TOPIK_A_PLUS);
  mqtt.subscribe(TOPIK_B_PLUS);
  mqtt.subscribe(TOPIK_A_MINUS);
  mqtt.subscribe(TOPIK_B_MINUS);
  mqtt.subscribe(TOPIK_ULANG);
}

sambungWiFi() dan sambungMQTT(): sama di semua proyek (klik untuk lihat)void sambungWiFi() { WiFi.begin(WIFI_NAMA, WIFI_PASS); Serial.print("WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" OK, IP " + WiFi.localIP().toString()); } void sambungMQTT() { while (!mqtt.connected()) { if (mqtt.connect(WiFi.macAddress().c_str())) { Serial.println("Terhubung ke Klenik"); langganan(); } else { Serial.println("Broker gagal, coba lagi 3 detik"); delay(3000); } } }
void setup() { Serial.begin(115200); angka.setBrightness(7); sambungWiFi(); mqtt.setServer(BROKER, 1883); mqtt.setCallback(pesanMasuk); tampilkan(); } void loop() { if (!mqtt.connected()) sambungMQTT(); mqtt.loop(); }

Langkah 4: Pahami kodenya

  1. Dua skor digabung jadi satu bilangan 4 digit, dengan titik dua menyala dan nol di depan.
  2. t adalah topic pesan yang baru masuk, jadi satu baris ini melayani kelima switch.
  3. Lima switch berarti lima topic. Semuanya didengarkan, dan pesanMasuk() membedakannya dengan membandingkan topic.