กลับหน้าหลัก
views
How to Use ESP8266 with 2-Channel Solid State Relay Active Low for 220V Control
Last updated on

How to Use ESP8266 with 2-Channel Solid State Relay Active Low for 220V Control


How to Use ESP8266 with 2-Channel Solid State Relay Active Low for 220V Control

This tutorial shows how to connect ESP8266 with a Solid State Relay (SSR) Active Low 5V 2A 2-Channel board to control AC 220V devices. SSR uses an optocoupler to switch AC power without physical contacts, making it silent and reliable for frequent switching.

Wiring diagram showing ESP8266 connected to SSR 2 Channel with Vin to DC+, GND to DC-, D2 to CH1, D1 to CH2

Required Components

  • NodeMCU ESP8266 V2 (CP2102)
  • Solid State Relay Active Low 5V 2A 2-Channel board
  • Micro USB cable for uploading code
  • Power Adapter Micro USB 5V 2A
  • MB-102 Breadboard 830 points
  • Jumper wires: Male-to-Male, Male-to-Female, Female-to-Female, 20cm each
  • 220V light bulbs with E27 socket for testing (2 units)
  • AC 220V power cable with L and N lines

SSR vs Electromechanical Relay

SSR uses an optocoupler instead of physical contacts, so there is no clicking sound, no spark during switching, and higher durability for frequent ON/OFF cycles. It is suitable for applications requiring silent operation and long-term reliability.

Wiring ESP8266 to SSR

Pin mapping table showing connections between ESP8266 and SSR board

ESP8266 to SSR Board

ESP8266SSR Board
Vin (5V)DC+
GNDDC-
D2CH1
D1CH2

SSR to Load and AC 220V

Load 1 (must support 220V AC):

  • SSR A1 → Load 1
  • AC Line L → Load 1
  • AC Line N → SSR B1

Load 2 (must support 220V AC):

  • SSR A2 → Load 2
  • AC Line L → Load 2
  • AC Line N → SSR B2
Complete circuit diagram showing AC 220V flowing through both SSR channels to their respective loads

Warning: Working with AC 220V requires caution. If unsure, seek help from someone experienced with mains electricity.

Arduino Code for ESP8266 SSR Control

This code controls the SSR through Serial Monitor using commands 0-3 to toggle each channel.

// Define pins connected to SSR
const int SSR_CH1 = D2;  // D2 controls channel 1
const int SSR_CH2 = D1;  // D1 controls channel 2

void setup() {
  // Initialize Serial for computer communication
  Serial.begin(9600);
  
  // Set SSR pins as OUTPUT
  pinMode(SSR_CH1, OUTPUT);
  pinMode(SSR_CH2, OUTPUT);
  
  // Initial state: Active Low means SSR is OFF when signal is HIGH
  digitalWrite(SSR_CH1, HIGH);
  digitalWrite(SSR_CH2, HIGH);
  
  // Display usage instructions
  Serial.println("==========================");
  Serial.println("ESP8266 SSR 2 Channel Control");
  Serial.println("==========================");
  Serial.println("Send 0 = Turn OFF all SSR");
  Serial.println("Send 1 = Turn ON SSR Channel 1");
  Serial.println("Send 2 = Turn ON SSR Channel 2");
  Serial.println("Send 3 = Turn ON all SSR");
  Serial.println("==========================");
}

void loop() {
  // Wait for Serial input
  if (Serial.available() > 0) {
    char command = Serial.read();
    
    // Check command and control SSR
    switch (command) {
      case '0':
        // Turn OFF all SSR
        digitalWrite(SSR_CH1, HIGH);
        digitalWrite(SSR_CH2, HIGH);
        Serial.println("- Stopped all SSR");
        break;
        
      case '1':
        // Turn ON SSR Channel 1
        digitalWrite(SSR_CH1, LOW);
        digitalWrite(SSR_CH2, HIGH);
        Serial.println("- SSR Channel 1 ON");
        break;
        
      case '2':
        // Turn ON SSR Channel 2
        digitalWrite(SSR_CH1, HIGH);
        digitalWrite(SSR_CH2, LOW);
        Serial.println("- SSR Channel 2 ON");
        break;
        
      case '3':
        // Turn ON all SSR
        digitalWrite(SSR_CH1, LOW);
        digitalWrite(SSR_CH2, LOW);
        Serial.println("- All SSR ON");
        break;
        
      default:
        Serial.println("Invalid command. Send 0-3");
        break;
    }
  }
}

Upload and Test Procedure

  1. Open Arduino IDE and paste the code above
  2. Go to Tools → Port and select the COM port connected to ESP8266
  3. Go to Tools → Board and select NodeMCU 1.0 (ESP-12E Module)
  4. Click the Upload button in the Sketch menu
  5. Wait for “Done uploading” message
  6. Open Serial Monitor and set Baud Rate to 9600
  7. Send commands as shown:
    • Send 1 → First light turns ON
    • Send 2 → Second light turns ON (first turns OFF)
    • Send 3 → Both lights turn ON together
    • Send 0 → Both lights turn OFF

Points to Adjust

  • Relay clicks but load does not turn on: Check AC 220V wiring connections for L and N lines
  • Lights flicker randomly: May be caused by unstable power or loose wires - inspect all connections
  • Add WiFi control: You can integrate WiFi code and accept commands via a web server by modifying the loop() section to handle HTTP requests

Summary

Using ESP8266 with SSR Active Low 2-Channel is a reliable way to control AC 220V devices silently without sparks and with better durability than mechanical relays. The key point to remember is that Active Low means LOW signal turns the SSR ON, and HIGH signal turns it OFF - this is inverted logic compared to normal LED control.

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ความคิดเห็น

Verified user reviews

รีวิวและความคิดเห็นจากผู้ใช้จริง

ล็อกอินด้วยบัญชีบนเว็บนี้แล้วให้คะแนนหรือคอมเมนต์ได้เลย ระบบเก็บผ่าน Supabase ไม่ต้องใช้ GitHub แล้ว

กำลังโหลดรีวิว...