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 Relaismodul 12v an einen Arduino UNO oder ESP32 an, mit einem Beispiel-Sketch, den du direkt hochladen kannst.

Steuerung eines 12V-Relaismoduls

Dieses Projekt zeigt, wie man ein 12V-Relaismodul mit einem Arduino Uno steuert. Der Sketch schaltet das Relais alle 2 Sekunden abwechselnd EIN und AUS und zeigt den aktuellen Zustand im Serial Monitor an. Eine integrierte LED-Anzeige auf dem Modul leuchtet, wenn das Relais aktiviert ist.

Anschlussplan: Relaismodul 12v an einem Arduino UNO
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Relaismodul 12v an einem Arduino UNO
Anschlusstabelle · Zum Vergrößern klicken
12V_Relay_Module_Control.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : 12V Relay Module Control
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Relais Module 12v AC250V 10A Relais 12v 1 relais LED indicator
 *  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.
 * ==================================================================
 */

// Pin configuration
const int RELAY_PIN = 7;

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }
  
  // Configure relay control pin
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH); // Default off (active-low module)

  Serial.println(F("12V Relay Module Demo Initialized"));
}

void loop() {
  // Activate relay (Low-level trigger)
  Serial.println(F("Relay: ON"));
  digitalWrite(RELAY_PIN, LOW);
  delay(2000);

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

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

12V-Relaissteuerung mit ESP32

Dieses Projekt zeigt, wie ein 12V-Einkanal-Relaismodul mit einem ESP32 gesteuert wird. Die Relaisspule wird über ein externes 12V-DC-Netzteil mit gemeinsamem Masseanschluss zum ESP32 versorgt, und GPIO 4 schaltet das Relais alle zwei Sekunden ein und aus.

Anschlussplan: Relaismodul 12v an einem ESP32 DevKit V1
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Relaismodul 12v an einem ESP32 DevKit V1
Anschlusstabelle · Zum Vergrößern klicken
12V_Relay_Control_with_ESP32.ino · kompiliert und getestet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : 12V Relay Control with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Relais Module 12v AC250V 10A Relais 12v 1 relais LED indicator
 *  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.
 * ==================================================================
 */

// Pin connected to relay control input
const int RELAY_PIN = 4;

void setup() {
  Serial.begin(115200);
  
  // Configure relay pin as output
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  
  Serial.println("ESP32 12V Relay Demo Started");
}

void loop() {
  // Turn relay ON
  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

Zuletzt angesehen

DS1302 Real Time Clock Modul

DS1302 Real Time Clock Modul

€ 1,60