Hamza Deniz YILMAZPCBWay
Published © CC BY-NC-SA

ESP32-Controller-Board

Building a simple relay control circuit using an ESP32 microcontroller. To open and close the relays using the digital pins of the ESP32.

IntermediateFull instructions provided2 hours192
ESP32-Controller-Board

Story

Read more

Custom parts and enclosures

ESP32-Controller-Board

ESP32-Controller-Board

Schematics

Schematics

Schematics

ESP32-Controller-Board

ESP32-Controller-Board

Gerber

Code

Code_1

C/C++
#include <WiFi.h>

const char* ssid = "WiFi_SSID";
const char* password = "WiFi_PASSWORD";

// Röle pinleri
const int relay1Pin = 23;  
const int relay2Pin = 21;
const int relay3Pin = 22;
const int relay4Pin = 19;

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("WiFi bağlantısı bekleniyor...");
  }
  Serial.println("WiFi bağlandı!");

  pinMode(relay1Pin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);
  pinMode(relay3Pin, OUTPUT);
  pinMode(relay4Pin, OUTPUT);

  digitalWrite(relay1Pin, HIGH);
  digitalWrite(relay2Pin, HIGH);
  digitalWrite(relay3Pin, HIGH);
  digitalWrite(relay4Pin, HIGH);
}

void loop() {

  digitalWrite(relay1Pin, LOW);
  delay(1000);

  digitalWrite(relay1Pin, HIGH);
  delay(1000);

  digitalWrite(relay2Pin, LOW);
  delay(1000);

  digitalWrite(relay2Pin, HIGH);
  delay(1000);

  digitalWrite(relay3Pin, LOW);
  delay(1000);

  digitalWrite(relay3Pin, HIGH);
  delay(1000);

  digitalWrite(relay4Pin, LOW);
  delay(1000);

  digitalWrite(relay4Pin, HIGH);
  delay(1000);
}

Code_2

C/C++
#include <WiFi.h>

const char* ssid = "WiFi_SSID";
const char* password = "WiFi_PASSWORD";

const int relayPins[] = {23, 21, 22, 19};

const int numRelays = sizeof(relayPins) / sizeof(relayPins[0]);

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("WiFi bağlantısı bekleniyor...");
  }
  Serial.println("WiFi bağlandı!");

  for (int i = 0; i < numRelays; i++) {
    pinMode(relayPins[i], OUTPUT);
  }

  for (int i = 0; i < numRelays; i++) {
    digitalWrite(relayPins[i], HIGH);
  }
}

void loop() {

  for (int i = 0; i < numRelays; i++) {
    digitalWrite(relayPins[i], LOW);
    delay(1000);
  }

  for (int i = 0; i < numRelays; i++) {
    digitalWrite(relayPins[i], HIGH);
    delay(1000);
  }
}

ESP32_Code

ESP32_Code

Credits

Hamza Deniz YILMAZ

Hamza Deniz YILMAZ

19 projects • 7 followers
My YouTube Channel: https://www.youtube.com/channel/UCbete7WiB5nwUilmp1n7vFA
PCBWay

PCBWay

94 projects • 149 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments