Arduino Relay Module Control

Arduino Relay Module Control Experiment

Introduction

This experiment demonstrates how to control a relay module with an Arduino. The relay module can act as a switch to control high-power devices such as lights or fans.

Components Needed

Circuit Setup

  1. Connect the GND pin of the relay module to the GND of the Arduino.
  2. Connect the VCC pin of the relay module to the 5V pin of the Arduino.
  3. Connect the IN pin of the relay module to digital pin 7 on the Arduino through a 1kΩ resistor.
  4. Connect the common (COM) terminal of the relay to one terminal of the external device (e.g., light bulb or fan).
  5. Connect the Normally Open (NO) terminal of the relay to the positive side of the external power supply (e.g., 220V AC for a light bulb).
  6. Connect the other terminal of the external device to the negative side of the power supply.

Warning: Be cautious when working with high-voltage devices. Ensure power is disconnected during setup.

Code for Relay Control

Upload the following code to your Arduino to control the relay:


// Define relay control pin
const int relayPin = 7;

void setup() {
    // Set the relay control pin as output
    pinMode(relayPin, OUTPUT);
}

void loop() {
    // Turn the relay on (activates the external device)
    digitalWrite(relayPin, HIGH);
    delay(3000); // Relay on for 3 seconds

    // Turn the relay off (deactivates the external device)
    digitalWrite(relayPin, LOW);
    delay(3000); // Relay off for 3 seconds
}
            

Explanation

This code controls the relay as follows:

Troubleshooting