Op werkdagen vóór 14:00 uur besteld = dezelfde dag verzonden en in 98% van de gevallen de volgende dag in huis. Gratis retourneren 30 dagen bedenktijd 1 jaar garantie
← Tillbaka till översikten

Kopplingsschema och kodexempel

Så här kopplar du Relämodul 5v för Arduino till en Arduino UNO eller ESP32, med ett exempel­sketch som du kan ladda upp direkt.

Control a 5V Relay with Arduino UNO

This project demonstrates how to control a 5V relay module with an Arduino UNO. The sketch toggles the relay ON and OFF every two seconds while printing the status to the Serial Monitor. You will hear an audible click from the relay each time it switches state.

Kopplingsschema: Relämodul 5v för Arduino på en Arduino UNO
Kopplingsschema · Klicka för att förstora
Kopplingstabell: Relämodul 5v för Arduino på en Arduino UNO
Kopplingstabell · Klicka för att förstora
Control_a_5V_Relay_with_Arduino_UNO.ino · kompilerad och testad
/*
 * ==================================================================
 *  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 Relay Control with ESP32

This project demonstrates how to control a 5V relay module using an ESP32. The relay switches ON and OFF every two seconds while printing its status to the Serial Monitor. The relay is powered directly from the ESP32 VIN pin (5V from USB) and triggered via GPIO 4.

Kopplingsschema: Relämodul 5v för Arduino på en ESP32 DevKit V1
Kopplingsschema · Klicka för att förstora
Kopplingstabell: Relämodul 5v för Arduino på en ESP32 DevKit V1
Kopplingstabell · Klicka för att förstora
5V_Relay_Control_with_ESP32.ino · kompilerad och testad
/*
 * ==================================================================
 *  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

Tidigare visade

18650 batterihållare dubbel

18650 batterihållare dubbel

€ 1,00