A relay is an electromechanical switch that allows you to control a high-power or high-voltage circuit using a low-power signal. It is commonly used in applications where it is necessary to control a large power load with a smaller control signal, such as home automation systems, automotive electronics, and industrial machinery.
Pin Number | Description | Type |
---|---|---|
1 | Coil Voltage (VCC) | Input |
2 | Control Signal (IN) | Input |
3 | Ground (GND) | Ground |
4 | Normally Open (NO) | Output |
5 | Common (COM) | Output |
6 | Normally Closed (NC) | Output |
// Define relay control pin
const int relayPin = 2;
void setup() {
// Set the relay control pin as an output
pinMode(relayPin, OUTPUT);
}
void loop() {
// Turn on the relay by setting the control pin LOW
digitalWrite(relayPin, LOW);
delay(1000); // Wait for 1 second
// Turn off the relay by setting the control pin HIGH
digitalWrite(relayPin, HIGH);
delay(1000); // Wait for 1 second
}
Q: Can I use a relay with a higher voltage rating than my load? A: Yes, it is safe to use a relay with a higher voltage rating than your load.
Q: How do I know if my relay is working? A: You can listen for a click when the relay is energized or use a multimeter to check for continuity across the contacts.
Q: Can I control a relay directly with a microcontroller? A: Yes, but ensure the coil current is within the microcontroller's drive capability, or use a transistor to amplify the signal.