Bestilt før kl. 14.00 på hverdage = afsendt samme dag 30 dages fortrydelsesret 1 års garanti
← Terug til oversigten

Tilslutningsdiagram og kodeeksempel

Sådan tilslutter du Relais Module 5v til Arduino til en Arduino UNO eller ESP32, med en eksempelsketch, du kan uploade med det samme.

Styr et 5V-relæ med Arduino UNO

Dette projekt viser, hvordan man styrer et 5V-relæmodul med en Arduino UNO. Sketchet skifter relæet ON og OFF hver anden sekund, mens status udskrives til Serial Monitor. Du vil høre et hørbart klik fra relæet hver gang, det skifter tilstand.

Tilslutningsdiagram: Relais Module 5v til Arduino på en Arduino UNO
Tilslutningsdiagram · Klik for at forstørre
Tilslutningstabel: Relais Module 5v til Arduino på en Arduino UNO
Tilslutningstabel · Klik for at forstørre
Control_a_5V_Relay_with_Arduino_UNO.ino · kompileret og testet
/*
 * ==================================================================
 *  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

Styring af 5V-relæ med ESP32

Dette projekt viser, hvordan man styrer et 5V-relæmodul med en ESP32. Relæet slår TIL og FRA hvert andet sekund, mens dets status udskrives til Serial Monitor. Relæet forsynes direkte fra ESP32 VIN-pin (5V fra USB) og aktiveres via GPIO 4.

Tilslutningsdiagram: Relais Module 5v til Arduino på en ESP32 DevKit V1
Tilslutningsdiagram · Klik for at forstørre
Tilslutningstabel: Relais Module 5v til Arduino på en ESP32 DevKit V1
Tilslutningstabel · Klik for at forstørre
5V_Relay_Control_with_ESP32.ino · kompileret og testet
/*
 * ==================================================================
 *  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