Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Wi-Fi Controlled Relay Module with ESP8266 and MCP23017

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled Relay Module with ESP8266 and MCP23017

Circuit Documentation

Summary

This circuit is designed to control an 8-channel relay module using a WiFi module (ESP8266-01) and an I/O expansion board (MCP23017). The circuit includes multiple rocker switches for manual control of the relays. The power supply is provided by a 5V 5A power supply, and a 3.3V converter is used to power the ESP8266-01 and MCP23017.

Component List

  1. Wifi module ESP8266-01

    • Description: A WiFi module used for wireless communication.
    • Pins: RX, GPIO0, GPIO2, GND, +3V3, Reset, CH-PD Chip power down, TX
  2. MCP23017 I/O Expansion Board

    • Description: An I/O expansion board used to control multiple I/O pins via I2C.
    • Pins: VCC, GND, SDA, SCL, INTA, INTB, PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7
  3. 5V 8 Channel Relay Module

    • Description: A relay module used to control high-power devices.
    • Pins: NC, COM, NO, GND, VCC, JD-VCC, IN8, IN7, IN6, IN5, IN4, IN3, IN2, IN1
  4. Rocker Switch (SPST)

    • Description: A single-pole single-throw switch used for manual control.
    • Pins: 1, 2
  5. 3.3V Converter

    • Description: A voltage converter used to step down 5V to 3.3V.
    • Pins: GND, Vout, Vin
  6. Power Supply 5V 5A

    • Description: A power supply providing 5V at 5A.
    • Pins: 220V Positive Pole (AC), 220V Negative Pole (AC), GND, GND (DC), 12V-24V Output (DC)
  7. AC Source

    • Description: An AC power source.
    • Pins: +, -

Wiring Details

Wifi module ESP8266-01

MCP23017 I/O Expansion Board

5V 8 Channel Relay Module

Rocker Switch (SPST)

3.3V Converter

Power Supply 5V 5A

AC Source

Code Documentation

#include <Wire.h>
#include <Adafruit_MCP23X17.h>

Adafruit_MCP23X17 mcp;

const int relayPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // MCP23017 pins for relays
const int switchPins[] = {8, 9, 10, 11, 12, 13, 14, 15}; // MCP23017 pins for switches

bool relayStates[8] = {false, false, false, false, false, false, false, false}; // Store relay states

void setup() {
  Serial.begin(115200);
  mcp.begin_I2C(); // Initialize MCP23017 with I2C

  // Initialize relay and switch pins
  for (int i = 0; i < 8; i++) {
    mcp.pinMode(relayPins[i], OUTPUT);
    mcp.digitalWrite(relayPins[i], LOW); // Relay off
    mcp.pinMode(switchPins[i], INPUT);
    mcp.digitalWrite(switchPins[i], HIGH); // Enable internal pull-up resistor
  }
}

void loop() {
  // Check switches for manual control
  for (int i = 0; i < 8; i++) {
    if (mcp.digitalRead(switchPins[i]) == LOW) {
      delay(50); // Debounce delay
      if (mcp.digitalRead(switchPins[i]) == LOW) {
        relayStates[i] = !relayStates[i];
        mcp.digitalWrite(relayPins[i], relayStates