AI

In the context of single-board computers (like Raspberry Pi), a **HAT** (Hardware Attached on Top) is an add-on board that expands functionality. The **HAT-R** specifically refers to a **Relay HAT**, designed to allow low-power microcontrollers to control high-power electrical devices.
---
### Core Electronic Components of a HAT-R
A standard Relay HAT contains several critical electronic stages to ensure safety and functionality:
| Component | Function | Description |
| :--- | :--- | :--- |
| **Relays** | Switching Mechanism | Electromagnetic switches that physically open/close a high-voltage circuit using a low-voltage signal. |
| **Optocouplers** | Isolation | Provides optical isolation between the Raspberry Pi and the high-power circuit to prevent electrical damage. |
| **Flyback Diodes** | Protection | Dissipates the voltage spike created when the relay coil is de-energized (Inductive kickback). |
| **Transistors** | Switching Logic | Acts as a driver because the GPIO pins cannot provide enough current to trigger the relay coil directly. |
| **Terminal Blocks** | Connection | Screw-down connectors (Common, NO, NC) for attaching external AC/DC loads. |
| **LED Indicators** | Status Visuals | Visual confirmation showing whether a specific relay channel is currently active. |
---
### Technical Specifications (Typical)
Most HAT-R boards adhere to these electronic standards:
* **Logic Voltage:** 3.3V or 5V (depending on the host board).
* **Switching Capacity:** Usually up to **10A at 250VAC** or **10A at 30VDC**.
* **Channels:** Commonly available in 2, 4, or 8-channel configurations.
* **Interface:** Controlled via standard **GPIO pins**.
---
### Wiring Logic: NO vs. NC
When connecting parts to the Relay HAT, you will encounter three ports per relay:
1. **COM (Common):** The "hot" or supply wire goes here.
2. **NO (Normally Open):** The circuit is broken by default; it closes when the GPIO is set to HIGH.
3. **NC (Normally Closed):** The circuit is connected by default; it opens when the GPIO is set to HIGH.
---
### Example Control Code (Python)
To toggle a relay on a HAT-R, you typically interact with the GPIO pins as follows:
```python
import RPi.GPIO as GPIO
import time
RELAY_PIN = 21 # Example GPIO pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(RELAY_PIN, GPIO.OUT)
try:
while True:
GPIO.output(RELAY_PIN, GPIO.HIGH) # Relay ON
time.sleep(1)
GPIO.output(RELAY_PIN, GPIO.LOW) # Relay OFF
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
```
- ⤷
What is the difference between an electromagnetic relay and a Solid State Relay (SSR) HAT?
- ⤷ How do I safely calculate the power load for a HAT-R?
- ⤷ Can a HAT-R be used with an Arduino instead of a Raspberry Pi?