RELAY WITH ARDUINO UNO LED INDICATION

 Circuit Diagram:



Non-Blocking Time-Controlled Relay Automation with Arduino

Hardware Wire Bus Distribution Index

Configure the physical wiring hookups as detailed in this map to interface your signal lines and isolation hardware safely:

Component Interface Target Controller Location Signal System Purpose
Relay VCC Wire 5V Power Rail Pin Main Logic Module Power Supply
Relay GND Wire GND Pin Terminal Common Circuit Ground Reference
Relay IN (Signal) Wire Digital Pin 8 Logic State Command Interface
Status LED Anode (+) Wire Digital Pin 8 (Shared or Bridged) Visual Status Indicator Track
Status LED Cathode (-) Wire GND Pin via Current Limiting Resistor Isolated Safety Return Current Path
⚠️ HARDWARE ISOLATION PARAMETER: When controlling inductive mains-voltage loads (AC appliances), ensure your relay board features optocoupler isolation. Never connect high-voltage alternating current tracks directly back into processing rails without an isolated air gap.

System Operational Verification Checks

  • Non-Blocking Execution Loop: This layout uses the millis() clock engine to calculate structural time gaps instead of the standard delay() function. This ensures that background code blocks run continuously without causing processing lag or hanging the main controller logic.
  • Asymmetric Timing Slots: You can tune the independent parameters TIME_ON and TIME_OFF inside the initialization header to create unique operational intervals tailored to specific automation requirements.

Signal Bus Flow & Step Mechanics

The control loop constantly evaluates elapsed time loops against threshold constraints, altering active outputs programmatically without halting memory passes:

[ Loop Read: currentMillis ] ──► Compares (currentMillis - previousMillis) │ ▼ (Threshold Exceeded?) [ State Switch Engine ] ──────────────► Flips Pin 8 Output State (HIGH / LOW) │ ▼ (Telemetric Sync Update) [ Serial Log Push ] ──────────────────► Transmits State Flag to Console Bus

Project Video Demonstration

Watch the complete real-time execution loop, hardware transitions, and serial diagnostics output stream below:

Source Firmware Application

Review or duplicate the full processing deployment routine structured inside this syntax highlighting panel:

πŸ“ relay_timer.ino
Arduino C++
// Define Relay Control Pin
const int relayPin = 8;

// Time configurations (Adjust these variables as needed)
const unsigned long TIME_ON  = 5000;  // How long the appliance stays ON (5 seconds)
const unsigned long TIME_OFF = 7000;  // How long the appliance stays OFF (7 seconds)

// Tracking variables
unsigned long previousMillis = 0;
bool isRelayActive = false;

void setup() {
  // Configure the relay control pin as an output
  pinMode(relayPin, OUTPUT);
  
  // Set initial state to OFF
  digitalWrite(relayPin, LOW);
  
  // Initialize the Serial Monitor
  Serial.begin(9600);
  Serial.println("--- Time-Controlled Relay System Online ---");
  Serial.print("Cycle Configured: OFF for ");
  Serial.print(TIME_OFF / 1000);
  Serial.print("s, then ON for ");
  Serial.print(TIME_ON / 1000);
  Serial.println("s.");
}

void loop() {
  // Get the current running runtime of the microcontroller
  unsigned long currentMillis = millis();
  
  // Check the current state of our timer track
  if (isRelayActive) {
    // If the relay is currently ON, check if it's time to turn it OFF
    if (currentMillis - previousMillis >= TIME_ON) {
      digitalWrite(relayPin, LOW);     // Turn off physical relay
      isRelayActive = false;           // Update software state tracker
      previousMillis = currentMillis;  // Reset time marker
      Serial.println("[TIMER EVENT] Relay turned OFF. Safe cycle resting...");
    }
  } 
   Ontario else {
    // If the relay is currently OFF, check if it's time to turn it ON
    if (currentMillis - previousMillis >= TIME_OFF) {
      digitalWrite(relayPin, HIGH);    // Turn on physical relay
      isRelayActive = true;            // Update software state tracker
      previousMillis = currentMillis;  // Reset time marker
      Serial.println("[TIMER EVENT] Relay activated! Load is powered ON.");
    }
  }
}
🌐 Open Wokwi Workspace

Comments