Relay Interfacing

Interfacing Relay Module with Arduino

  In this project, we will demonstrate how to interface a relay module with an Arduino board. A relay module is an electrical switch that allows low-power microcontrollers like Arduino to control high-power devices such as motors, lights, or appliances. We will control the relay module using Arduino and switch an external device on and off.

Hardware Required:

  1. Arduino board (e.g., Arduino Uno)
  2. Relay module
  3. External device (e.g., motor, light bulb, or fan)
  4. Jumper wires

Circuit Diagram: Connect the components as follows:

Connections Table:

Arduino BoardRelay module
5v (vcc)    => GND         => PIN 2        =>Vcc GND RLY

Below is the Arduino code to control the relay module:

// www.projectkitsandparts.com

// Define the pin connected to the relay module

const int relayPin = 2;

void setup() {

  // Set the relay pin as an output

  pinMode(relayPin, OUTPUT);

}

void loop() {

  // Turn on the relay

  digitalWrite(relayPin, HIGH);

  // Wait for 2 seconds

  delay(2000);

  // Turn off the relay

  digitalWrite(relayPin, LOW);

  // Wait for 2 seconds

  delay(2000);

}

Code Explanation:

  1. The relayPin variable is declared and set to the pin number connected to the relay module.
  2. In the setup() function, the relayPin is set as an output using the pinMode() function.
  3. The loop() function is where the relay control happens.
  4. The relay is turned on by setting the relayPin to HIGH using digitalWrite().
  5. The program waits for 2 seconds using delay(2000).
  6. The relay is turned off by setting the relay Pin to LOW.
  7. Another 2-second delay is added.
  8. The loop repeats, toggling the relay on and off continuously.

Code Manual:

  • Connect the Arduino board to your computer via USB.
  • Open the Arduino IDE (Integrated Development Environment) on your computer.
  • Create a new sketch and copy-paste the code provided into the IDE.
  • Make sure the correct Arduino board and port are selected under the “Tools” menu.
  • Connect the relay module to the Arduino board using jumper wires. Ensure that the input pins of the relay module are connected to the appropriate digital pins of the Arduino, as specified in the circuit diagram.
  • Connect the external device (motor, light bulb, etc.) to the relay module’s load terminals.
  • Connect a separate power supply to the external device, if required.
  • Double-check all connections to ensure they are secure and correct.
  • Click the “Upload” button in the Arduino IDE to

Leave a Reply

Your email address will not be published. Required fields are marked *

Shop
Sidebar
0 Wishlist
0 Cart