Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Control a Relay Module with Arduino

Relay modules are essential components when it comes to controlling high voltage devices with low voltage microcontrollers like Arduino. They act as electrically operated switches, allowing you to control a larger power load with a smaller control signal. In this article, you'll learn how to connect and control a relay module using an Arduino board.

Examples:

Components Required:

  1. Arduino Uno (or any compatible board)
  2. Relay Module (single-channel for simplicity)
  3. Jumper wires
  4. Breadboard (optional)
  5. A load to control (e.g., a light bulb with a socket and power source)

Wiring the Relay Module:

  1. Connect the VCC pin of the relay module to the 5V pin on the Arduino.
  2. Connect the GND pin of the relay module to the GND pin on the Arduino.
  3. Connect the IN pin of the relay module to digital pin 7 on the Arduino (you can choose any other digital pin if needed).

Arduino Code Example:

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

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

void loop() {
  // Turn the relay on (close the circuit)
  digitalWrite(relayPin, HIGH);
  delay(1000); // Wait for a second

  // Turn the relay off (open the circuit)
  digitalWrite(relayPin, LOW);
  delay(1000); // Wait for a second
}

Explanation:

  • The relay module is connected to the Arduino using three pins: VCC, GND, and IN.
  • The relayPin is set as an output in the setup() function.
  • In the loop() function, the relay is turned on and off every second by writing HIGH and LOW to the relayPin, respectively. This will toggle the connected load (e.g., a light bulb) on and off.

Safety Note: When working with high voltage devices, always ensure safety precautions are followed to prevent electric shock or damage to components.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.