OC
OceanRemote
Low-code IoT platform
โ† Back to Tutorials
โ† Previous Next โ†’

Tutorial 24: Using Multiple Relays - Best Practices

๐Ÿ“– What You'll Learn in This Tutorial:
  • โœ“ Power supply considerations for multiple relays
  • โœ“ Daisy-chaining relay modules
  • โœ“ Managing heat dissipation
  • โœ“ Best practices for high-voltage wiring
  • โœ“ Troubleshooting multiple relay setups

Introduction

OceanRemote supports up to 5 relays per device. Using multiple relays allows you to control several devices from a single microcontroller, saving cost and space.

โš ๏ธ Safety First!

This tutorial covers high-voltage wiring (110V/230V AC). Always disconnect power before wiring. If you're not comfortable with high voltage, use low-voltage DC devices (12V, 24V) instead.

Power Supply Requirements

The most common issue with multiple relays is insufficient power. Each relay module draws current when activated.

Current Draw Per Relay

Relay Type Current per Relay 5 Relays Total
5V Mechanical Relay (standard) ~70mA ~350mA
5V Mechanical Relay (high-quality) ~50mA ~250mA
3.3V Relay ~30mA ~150mA
Solid State Relay (SSR) ~15mA ~75mA

Power Supply Recommendations

Number of Relays Recommended Power Supply Notes
1-2 relays USB port (500mA) OK for testing
3-5 relays 5V 2A power supply Recommended
5+ relays (external module) External 5V 5A supply For multiple modules
๐Ÿ’ก Power Tip:

Always use a separate power supply for relays when using 3 or more. The microcontroller's USB port may not provide enough current, causing resets or erratic behavior.

Wiring Multiple Relay Modules

Option 1: Single Multi-Channel Relay Module (Recommended)

The easiest solution is to buy a pre-made multi-channel relay module (4-channel, 8-channel, etc.). These have common VCC and GND, making wiring simple.

4-Channel Relay Module Wiring:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚ ESP8266 โ”‚                    โ”‚  4-Channel Relay    โ”‚     โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค                    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค     โ”‚
โ”‚  โ”‚   5V    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค VCC                 โ”‚     โ”‚
โ”‚  โ”‚   GND   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค GND                 โ”‚     โ”‚
โ”‚  โ”‚   D1    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค IN1                 โ”‚     โ”‚
โ”‚  โ”‚   D2    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค IN2                 โ”‚     โ”‚
โ”‚  โ”‚   D3    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค IN3                 โ”‚     โ”‚
โ”‚  โ”‚   D4    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค IN4                 โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ”‚                                                             โ”‚
โ”‚  Note: Some modules have JD-VCC (jumper) for separate       โ”‚
โ”‚        power supply. Remove jumper for external power.      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Option 2: Daisy-Chaining Single Relay Modules

If you have multiple single-relay modules, you can connect their VCC and GND in parallel:

Daisy-Chaining Single Relay Modules:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  5V     โ”œโ”€โ”€โ”€โ”€โ”ค VCC      โ”œโ”€โ”€โ”€โ”€โ”ค VCC      โ”œโ”€โ”€โ”€โ”€โ”ค VCC    โ”‚  โ”‚
โ”‚  โ”‚  GND    โ”œโ”€โ”€โ”€โ”€โ”ค GND      โ”œโ”€โ”€โ”€โ”€โ”ค GND      โ”œโ”€โ”€โ”€โ”€โ”ค GND    โ”‚  โ”‚
โ”‚  โ”‚  D1     โ”œโ”€โ”€โ”€โ”€โ”ค IN (R1)  โ”‚    โ”‚          โ”‚    โ”‚        โ”‚  โ”‚
โ”‚  โ”‚  D2     โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค IN (R2)  โ”‚    โ”‚        โ”‚  โ”‚
โ”‚  โ”‚  D3     โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค IN (R3)โ”‚  โ”‚
โ”‚  โ”‚  D4     โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค        โ”‚  โ”‚
โ”‚  โ”‚  D5     โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค          โ”œโ”€โ”€โ”€โ”€โ”ค        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                             โ”‚
โ”‚  Relay 1 Module    Relay 2 Module    Relay 3 Module         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โš ๏ธ Daisy-Chain Warning:

When daisy-chaining, ensure your power supply can handle the total current draw. A 5V 2A supply is recommended for up to 5 single relay modules.

Heat Dissipation

Multiple relays generate heat, especially when activated for long periods.

Heat Management Tips:

  • Ventilation - Ensure airflow around relay modules
  • Spacing - Leave space between relay modules
  • Heat sinks - Some relay modules include heat sinks
  • Enclosure - Use a ventilated enclosure with fans
  • Duty cycle - Avoid leaving all relays ON continuously
๐ŸŒก๏ธ Temperature Limits:

Most relay modules are rated for 0-70ยฐC ambient temperature. If your enclosure feels hot (>50ยฐC), add ventilation or a small fan.

High-Voltage Wiring Best Practices

Wire Gauge Recommendations

Load Current Recommended Wire Gauge Typical Use
Up to 2A 22 AWG LED lights, small fans
2-5A 18 AWG Lamps, pumps
5-10A 16 AWG Heaters, motors
10-15A 14 AWG High-power devices

Wiring Safety Rules:

  • โœ… Use stranded wire for flexibility (not solid core)
  • โœ… Use different colors for LINE (hot), NEUTRAL, and GROUND
  • โœ… Use wire ferrules for screw terminals (prevents stray strands)
  • โœ… Use cable ties to organize wires
  • โœ… Keep low-voltage (3.3V/5V) and high-voltage wires separated
  • โŒ Never work on live circuits - always disconnect power
  • โŒ Don't exceed relay contact ratings (usually 10A for small relays)
Color Coding for AC Wiring (US Standard):
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  BLACK (or RED)  โ†’ LINE (Hot / L)           โ”‚
โ”‚  WHITE           โ†’ NEUTRAL (N)              โ”‚
โ”‚  GREEN (or BARE) โ†’ GROUND (Earth / GND)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Color Coding for AC Wiring (EU/International):
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  BROWN           โ†’ LINE (Hot / L)           โ”‚
โ”‚  BLUE            โ†’ NEUTRAL (N)              โ”‚
โ”‚  GREEN/YELLOW    โ†’ GROUND (Earth / GND)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Common Wiring Configurations

Configuration 1: Lights (Multiple Rooms)

Relay 1 โ†’ Living Room Light (150W)
Relay 2 โ†’ Kitchen Light (100W)
Relay 3 โ†’ Bedroom Light (60W)
Relay 4 โ†’ Bathroom Light (40W)
Relay 5 โ†’ Hallway Light (30W)

Total load: ~380W (3.5A at 110V) - Safe

Configuration 2: Garden Automation

Relay 1 โ†’ Water Pump (50W)
Relay 2 โ†’ Grow Lights (200W)
Relay 3 โ†’ Air Pump (20W)
Relay 4 โ†’ Heater (500W) โ† Use external contactor if >10A
Relay 5 โ†’ UV Sterilizer (30W)

Total load: ~800W (7.3A at 110V) - Near limit

Configuration 3: Workshop Tools

Relay 1 โ†’ Dust Collector (1200W) โ† Requires larger relay or contactor
Relay 2 โ†’ Air Compressor (1000W) โ† Requires larger relay or contactor
Relay 3 โ†’ Shop Lights (100W)
Relay 4 โ†’ Fan (50W)
Relay 5 โ†’ Charger (100W)

Note: High-power tools need external contactors or heavy-duty relays!
โš ๏ธ High-Power Warning:

Standard 5V relay modules are typically rated for 10A at 250V AC (2500W). For loads above 1500W, use an external contactor or solid-state relay (SSR) for safety.

Using External Contactors for High Power

For loads above 1500W (e.g., heaters, motors, air conditioners), use the 5V relay to control a contactor:

High-Power Contactor Wiring:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚ ESP8266 โ”‚         โ”‚  5V Relay    โ”‚    โ”‚  Contactor   โ”‚   โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค         โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค   โ”‚
โ”‚  โ”‚   5V    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค VCC          โ”‚    โ”‚   Coil A1    โ”‚   โ”‚
โ”‚  โ”‚   GND   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค GND          โ”‚    โ”‚   Coil A2    โ”‚   โ”‚
โ”‚  โ”‚   D1    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค IN           โ”‚    โ”‚              โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚              โ”‚   โ”‚
โ”‚                             โ”‚            โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚   โ”‚
โ”‚                    NO โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚  LINE   โ”‚ โ”‚   โ”‚
โ”‚                    COM โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚  LOAD   โ”‚ โ”‚   โ”‚
โ”‚                             โ”‚            โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚   โ”‚
โ”‚                             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                             โ”‚
โ”‚  The 5V relay switches the contactor coil (low current).    โ”‚
โ”‚  The contactor switches the high-power load.                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Programming Multiple Relays

Sequential Control (Avoid Inrush Current)

When turning on multiple relays, especially with motors or pumps, turn them on sequentially with delays to avoid power spikes:

// In OceanRemote firmware, this is handled automatically
// But for custom scripts, use delays:

digitalWrite(relay1, HIGH);
delay(500);  // Wait 500ms
digitalWrite(relay2, HIGH);
delay(500);
digitalWrite(relay3, HIGH);

Group Control (Turn All Relays On/Off)

OceanRemote doesn't have native group control, but you can use the API or create automation scripts:

// Example: Turn all relays OFF
// Send individual commands or use packed format "s=00"

https://www.oceanremote.net/api/device/state/?token=YOUR_TOKEN&s=00
๐Ÿ”ง Packed Relay Format:

The packed format "s=00" means all relays OFF. "s=1F" means all relays ON. Each bit represents a relay (bit 0 = relay1, bit 1 = relay2, etc.).

Troubleshooting Multiple Relays

Problem: Microcontroller resets when turning on multiple relays

  • Cause: Power supply insufficient
  • Fix: Use external 5V 2A+ power supply for relays

Problem: Relays don't activate in sequence

  • Cause: WiFi interference or network delay
  • Fix: Use packed format "s=XX" for simultaneous control

Problem: One relay works, others don't

  • Check individual GPIO wiring
  • Test each relay with a simple blink sketch
  • Verify relay logic setting for each channel

Problem: Relays buzz or chatter

  • Cause: Insufficient power or electrical noise
  • Fix: Add a 100ยตF capacitor across VCC and GND of relay module
๐Ÿ’ก Pro Tip:

Add a 1000ยตF capacitor across the power supply near the relay module. This smooths voltage spikes when multiple relays activate simultaneously.

Best Practices Summary

  • Power: Use external 5V 2A+ supply for 3+ relays
  • Wiring: Daisy-chain VCC and GND, use separate GPIO for each IN
  • Heat: Ensure ventilation, avoid running all relays continuously
  • High Voltage: Use proper wire gauges, color coding, and safety procedures
  • High Power: Use external contactors for loads >1500W
  • Testing: Test each relay individually before testing multiple
  • Documentation: Label your relays and wires for future reference
๐Ÿ“Š Quick Reference Card:
Scenario Power Supply Notes
1-2 relays USB 500mA OK for testing
3-5 relays 5V 2A Recommended
5+ relays 5V 5A external Use separate supply
High power (>1500W) External contactor Safety required

Next Steps

Now that you understand multiple relay best practices, continue with:

  • Tutorial 25: Common Connection Issues and Fixes
  • Tutorial 21: Connecting Relays to Your Board (wiring guide)
  • Tutorial 22: Understanding Positive vs Negative Logic
  • Return to Tutorial 02: Generate firmware for your multi-relay setup!
๐ŸŽฏ You're Ready!

You can now confidently wire and power multiple relays. Remember: proper power supply is the key to reliable multi-relay operation!