Belajar Elektro

Random post

Belajar Elektro

Powered By Blogger

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Tuesday, 17 June 2025

KODE PROGRAM MOBIL REMOTE CONTROL 6 CH


WIRING :

Power Supply 8V DC

 +------------------+----------------------+

 |                  |                      |

Vin (Raw)        VCC Relay Module        GND

 |                  |                      |

 |                  |                      |

NodeMCU V3          Relay Module IN Pins   Ground (NodeMCU + Relay + Power Supply)

 |                   |                      |

 |                   |                      |

D1 (GPIO5) ----------> IN1

D2 (GPIO4) ----------> IN2

D5 (GPIO14) ---------> IN3

D6 (GPIO12) ---------> IN4

D7 (GPIO13) ---------> IN5

D8 (GPIO15) ---------> IN6

  |

  +---> 10kΩ resistor ---> GND

 

 

KODE :

#define BLYNK_TEMPLATE_ID "TMPL6WcQ5c_l1"

#define BLYNK_TEMPLATE_NAME "Mobil Remote Control"

#define BLYNK_AUTH_TOKEN "bkVNURBsLa_XXmVWyqeABM4tkUPXwDc8"

 

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

 

char ssid[] = "Tes123";

char pass[] = "1234Dcba12";

 

const int pins[] = {5, 4, 14, 12, 13, 15};

const int pinCount = sizeof(pins) / sizeof(pins[0]);

 

void setup() {

  Serial.begin(115200);

  Serial.println("Starting...");

 

  for (int i = 0; i < pinCount; i++) {

    pinMode(pins[i], OUTPUT);

    digitalWrite(pins[i], LOW);

    Serial.printf("Pin GPIO%d initialized as OUTPUT and set LOW\n", pins[i]);

  }

 

  Serial.printf("Connecting to WiFi SSID: %s\n", ssid);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

 

  // Tunggu koneksi WiFi dengan timeout (contoh 15 detik)

  unsigned long startAttemptTime = millis();

  while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 15000) {

    delay(500);

    Serial.print(".");

  }

  Serial.println();

 

  if (WiFi.status() == WL_CONNECTED) {

    Serial.println("WiFi connected!");

    Serial.print("IP address: ");

    Serial.println(WiFi.localIP());

  } else {

    Serial.println("Failed to connect to WiFi");

  }

}

 

BLYNK_CONNECTED() {

  Serial.println("Blynk connected, syncing virtual pins...");

  Blynk.syncAll();

 

  for (int i = 0; i < pinCount; i++) {

    digitalWrite(pins[i], LOW);

  }

  Serial.println("All pins set to LOW after sync");

}

 

// Debug untuk semua virtual pin dari V0 sampai V5

BLYNK_WRITE_DEFAULT() {

  int vpin = request.pin - V0;

  int val = param.asInt();

  Serial.printf("Virtual Pin V%d received value: %d\n", vpin, val);

  if (vpin >= 0 && vpin < pinCount) {

    digitalWrite(pins[vpin], val == 0 ? LOW : HIGH);

    Serial.printf("GPIO%d set to %s\n", pins[vpin], val == 0 ? "LOW (ON)" : "HIGH (OFF)");

  } else {

    Serial.printf("Warning: Virtual pin V%d out of range\n", vpin);

  }

}

 

void loop() {

  Blynk.run();

}