Relay Module 5V high trigger
| Pin | Signal | Description |
|---|---|---|
- |
ground | GND pin 5V |
+ |
power 5V | VCC pin 5v |
S |
digital | Signal 3V - 5V |
NO |
Normally open | |
COM |
Common | |
NC |
Normally Closed |
| From | To | Wire |
|---|---|---|
board:GND |
x1:- |
black |
board:5V |
x1:+ |
red |
board:D7 |
x1:S |
green |
This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.
// Relay Module 5V - Canonical Beginner Example
// This sketch switches the relay ON and OFF every 2 seconds.
// Wiring:
// Arduino GND -> relay -
// Arduino 5V -> relay +
// Arduino D7 -> relay S
const int RELAY_PIN = 7;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Relay module demo starting...");
}
void loop() {
digitalWrite(RELAY_PIN, HIGH); // Many 5V relay modules are active HIGH
Serial.println("Relay ON");
delay(2000);
digitalWrite(RELAY_PIN, LOW);
Serial.println("Relay OFF");
delay(2000);
}
Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.
Start for free