Arduino with Relay Module

Control Devices with a Relay Module

Learn how to safely control high-voltage devices like lamps or fans using an Arduino and a relay module. A perfect starter guide for home automation projects.

Required Components

Wiring Instructions

Follow these steps to connect the relay module to the Arduino and the high-voltage device:

Code Explanation

The Arduino code controls the relay using digital signals:

Arduino Code


const int relayPin = 7; // Pin connected to the relay module

void setup() {
    pinMode(relayPin, OUTPUT); // Set relay pin as an output
    digitalWrite(relayPin, LOW); // Initialize relay as OFF
}

void loop() {
    digitalWrite(relayPin, HIGH); // Turn the relay ON (device ON)
    delay(5000); // Keep it ON for 5 seconds
    digitalWrite(relayPin, LOW); // Turn the relay OFF (device OFF)
    delay(5000); // Keep it OFF for 5 seconds
}
        

Upload and Test

  1. Assemble the circuit according to the wiring instructions.
  2. Connect your Arduino to your computer via USB.
  3. Upload the provided code using the Arduino IDE.
  4. Observe the high-voltage device turning ON and OFF in 5-second intervals.

How It Works

The relay acts as an electrically operated switch:

Safety Precautions

Working with high-voltage devices requires caution:

Applications

Here are some practical uses for this project:

Troubleshooting

If the project doesn't work as expected, check the following:

Conclusion

This project demonstrates how to safely control high-voltage devices using an Arduino and a relay module. By expanding the code and setup, you can create automated and remotely controlled systems for various applications.