1 Channel 12V Relay Module with Optocoupler Documentation
The 1 Channel 12V Relay Module with Optocoupler is a popular IoT component used to control high-voltage devices (up to 12V) using a microcontroller or other low-voltage devices. The optocoupler provides electrical isolation between the input signal and the relay, ensuring safe and reliable operation.
VCC: 5V power supply
GND: Ground
IN: Signal input (active low)
Relay Output: Normally Open (NO), Normally Closed (NC), and Common (COM)
Relay type: SPST (Single Pole Single Throw)
Rated voltage: 12V
Rated current: 10A
Operating frequency: 50/60Hz
Optocoupler isolation voltage: 5KV
### Example 1: Controlling a Light Bulb using Arduino
In this example, we'll use an Arduino Uno board to control a light bulb connected to the relay module.
```cpp
const int relayPin = 2; // Choose a digital pin on your Arduino board
void setup() {
pinMode(relayPin, OUTPUT);
}
void loop() {
digitalWrite(relayPin, LOW); // Turn the relay ON (light bulb turns ON)
delay(1000);
digitalWrite(relayPin, HIGH); // Turn the relay OFF (light bulb turns OFF)
delay(1000);
}
```
### Example 2: Controlling a DC Motor using Raspberry Pi (Python)
In this example, we'll use a Raspberry Pi to control a DC motor connected to the relay module.
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Set the relay pin as output
relay_pin = 17
GPIO.setup(relay_pin, GPIO.OUT)
try:
while True:
GPIO.output(relay_pin, GPIO.LOW) # Turn the relay ON (motor turns ON)
time.sleep(1)
GPIO.output(relay_pin, GPIO.HIGH) # Turn the relay OFF (motor turns OFF)
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
```
Make sure to connect the relay module to a suitable power supply and ensure the voltage rating is not exceeded.
Use proper electrical isolation and safety precautions when working with high-voltage devices.
The relay module can be used with other microcontrollers or development boards, such as ESP32, ESP8266, or STM32, with minor modifications to the code.