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

ESP32-Controlled Multiplexed AC Lighting System

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Multiplexed AC Lighting System

Circuit Documentation

Summary

This circuit is designed to control three AC-powered LED bulbs using an ESP32 microcontroller and a 1-channel relay module. The ESP32 is also interfaced with a SparkFun 74HC4051 8-Channel Multiplexer (Mux) to select which LED bulb to power. The relay module acts as an electronic switch that is controlled by the ESP32 to turn the bulbs on or off. The power for the bulbs is supplied by a 220V AC power source.

Component List

ESP32 (30 pin)

1-Channel Relay (5V 10A)

Power 220V

LED bulb AC / Bombillo AC

SparkFun 74HC4051 8-Channel Mux Breakout

Wiring Details

ESP32 (30 pin)

1-Channel Relay (5V 10A)

Power 220V

LED bulb AC / Bombillo AC

SparkFun 74HC4051 8-Channel Mux Breakout

Documented Code

// sketch.ino
const int relayPin = 22; // Relay control pin
const int muxS0 = 23; // Multiplexer control pin S0
const int muxS1 = 25; // Multiplexer control pin S1
const int muxS2 = 26; // Multiplexer control pin S2

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(muxS0, OUTPUT);
  pinMode(muxS1, OUTPUT);
  pinMode(muxS2, OUTPUT);
  digitalWrite(relayPin, LOW); // Ensure relay is off initially
}

void loop() {
  // Control the first bulb
  selectMuxChannel(0);
  digitalWrite(relayPin, HIGH);
  delay(1000); // Keep the relay on for 1 second
  digitalWrite(relayPin, LOW);
  delay(1000); // Wait before switching to the next bulb

  // Control the second bulb
  selectMuxChannel(1);
  digitalWrite(relayPin, HIGH);
  delay(1000);
  digitalWrite(relayPin, LOW);
  delay(1000);

  // Control the third bulb
  selectMuxChannel(2);
  digitalWrite(relayPin, HIGH);
  delay(1000);
  digitalWrite(relayPin, LOW);
  delay(1000);
}

void selectMuxChannel(int channel) {
  digitalWrite(muxS0, channel & 0x01);
  digitalWrite(muxS1, (channel >> 1) & 0x01);
  digitalWrite(muxS2, (channel >> 2) & 0x01);
}

This code configures the ESP32 to control a relay and select channels on a multiplexer. The relay is used to switch the power to the LED bulbs, and the multiplexer selects which bulb to power. The selectMuxChannel function sets the appropriate control pins to select the desired channel on the multiplexer. The loop function cycles through the bulbs, turning each on for one second before moving to the next.