Werktags vor 14:00 Uhr bestellt = am selben Tag versendet 30 Tage Widerrufsrecht 1 Jahr Garantie
← Zurück zur Übersicht

Schaltplan und Codebeispiel

So schließt du den Relais Modul 5v für Arduino an einen Arduino UNO oder ESP32 an, mit einem Beispiel-Sketch, den du direkt hochladen kannst.

Ein 5V-Relais mit Arduino UNO steuern

Dieses Projekt zeigt, wie man ein 5V-Relaismodul mit einem Arduino UNO steuert. Der Sketch schaltet das Relais alle zwei Sekunden EIN und AUS und gibt den Status im Serial Monitor aus. Bei jedem Zustandswechsel hört man ein hörbares Klicken des Relais.

Anschlussplan: Relais Modul 5v für Arduino an einem Arduino UNO
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Relais Modul 5v für Arduino an einem Arduino UNO
Anschlusstabelle · Zum Vergrößern klicken
Control_a_5V_Relay_with_Arduino_UNO.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : Control a 5V Relay with Arduino UNO
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Relay Module 5V
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// 5V Relay Module Example
const int RELAY_PIN = 7;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  Serial.begin(115200);
  Serial.println(F("Relay module demo started."));
}

void loop() {
  // Turn relay ON
  digitalWrite(RELAY_PIN, HIGH);
  Serial.println(F("Relay: ON"));
  delay(2000);

  // Turn relay OFF
  digitalWrite(RELAY_PIN, LOW);
  Serial.println(F("Relay: OFF"));
  delay(2000);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

5V-Relais mit ESP32 steuern

Dieses Projekt zeigt, wie man ein 5V-Relaismodul mit einem ESP32 ansteuert. Das Relais schaltet alle zwei Sekunden EIN und AUS und gibt seinen Status auf dem Serial Monitor aus. Das Relais wird direkt über den ESP32 VIN-Pin (5V von USB) versorgt und über GPIO 4 ausgelöst.

Anschlussplan: Relais Modul 5v für Arduino an einem ESP32 DevKit V1
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Relais Modul 5v für Arduino an einem ESP32 DevKit V1
Anschlusstabelle · Zum Vergrößern klicken
5V_Relay_Control_with_ESP32.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : 5V Relay Control with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Relay Module 5V
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// 5V Relay Control Example for ESP32
const int RELAY_PIN = 4;

void setup() {
  Serial.begin(115200);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  Serial.println("Relay control initialized.");
}

void loop() {
  // Turn relay ON (Active HIGH for standard modules)
  Serial.println("Relay: ON");
  digitalWrite(RELAY_PIN, HIGH);
  delay(2000);

  // Turn relay OFF
  Serial.println("Relay: OFF");
  digitalWrite(RELAY_PIN, LOW);
  delay(2000);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online