Arduino Relay to Control Household Appliances with Code

This is an electronics circuit note on how to control household appliances with Arduino and relay. A note on how to connect household appliance (like AC bulb, Soldering Iron, Workbench Power, AC motors etc.) using an Arduino Nano, a 5V relay module, and an SPDT toggle switch. The switch is connected to digital pin D9 using Arduino's internal pull-up resistor, while pin D5 drives the signal input of our relay module. This basic setup isolates low-voltage microcontroller logic from high-voltage AC current, letting you safely control household appliances with a simple digital signal! 

To demonstrates how the circuit works, the circuit is simulated in Proteus. The simulation shows animation of how the AC signal flows, how the Arduino sends signal when the switch is used and how the bulb lights up.

Circuit Diagram

Below is Arduino 5V Relay AC bulb circuit diagram.

Arduino 5V Relay AC bulb circuit diagram

In this circuit, we're controlling a 220V AC bulb using an Arduino Nano, a 5V relay module, and an SPDT toggle switch. The switch is connected to digital pin D9 using Arduino's internal pull-up resistor, while pin D5 drives the signal input of our relay module.

When the SPDT switch is in the open position, pin D9 is held HIGH by the internal pull-up. In our code, this sends a LOW output to pin D5. Because the relay remains deactivated, the high-voltage AC circuit stays open at the Normally Open terminal, and the light bulb remains completely OFF.

Now, when we flip the switch to close pin D9 to Ground. The Arduino detects a LOW signal on D9 and immediately sets pin D5 to HIGH. This energizes the relay coil, closing the contact between COM and NO. Current flows from the AC wall outlet, through the relay, and lights up the bulb!

Flipping the switch back opens the connection between D9 and Ground. Pin D9 returns to HIGH, causing the Arduino to send a LOW signal to pin D5. The relay de-energizes, breaks the AC circuit connection, and turns the bulb off safely.

5V Relay Proteus Model | Free Download 

Video demonstration

Arduino code

The following is arduine code for controlling home appliances with Arduino and 5V relay.


// Pin definitions
const int RELAY_PIN = 5;
const int SWITCH_PIN = 9;

void setup() {
  // Set D5 as relay output
  pinMode(RELAY_PIN, OUTPUT);
  
  // Enable internal pull-up resistor for SPDT switch on D9
  pinMode(SWITCH_PIN, INPUT_PULLUP);
  
  // Start with relay OFF
  digitalWrite(RELAY_PIN, LOW);
}

void loop() {
  // Read the current position of the SPDT switch
  int switchState = digitalRead(SWITCH_PIN);

  // If switch is closed to GND (LOW), turn ON active-low relay
  if (switchState == LOW) {
    digitalWrite(RELAY_PIN, HIGH);
  } 
  // If switch is open (HIGH due to pull-up), turn OFF relay
  else {
    digitalWrite(RELAY_PIN, LOW);
  }
}

See other related arduino relay tutorials:

Post a Comment

Previous Post Next Post