Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
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:
Wiring the Relay Module:
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:
relayPin
is set as an output in the setup()
function.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.