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

Arduino UNO Controlled 4-Channel Relay System with I2C LCD Display and IR Sensors

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled 4-Channel Relay System with I2C LCD Display and IR Sensors

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller that controls a 4-channel relay module, an I2C LCD display, two IR sensors, a micro servo, a PAM8403 amplifier, an XR2206 function generator, and a speaker. The Arduino UNO is programmed to display messages on the LCD, control the relays, and generate a square wave. The IR sensors are used for input detection, and the micro servo is controlled via PWM. The PAM8403 amplifier drives the speaker.

Component List

Relay 4 Channel 5V

IR Sensor

PAM8403

Arduino UNO

LCD I2C Display

Micro Servo 9G

XR2206 HLF 224A8

Speaker

Resistor

Wiring Details

Relay 4 Channel 5V

IR Sensor (Instance 1)

IR Sensor (Instance 2)

PAM8403

Arduino UNO

LCD I2C Display

Micro Servo 9G

XR2206 HLF 224A8

Speaker

Resistor

Code Documentation

/*
 * This Arduino Sketch initializes an I2C LCD display and controls a 4-channel
 * relay module. The LCD displays a welcome message and then continuously
 * updates to show the frequency of a square wave generated on one of the
 * relay control pins. The relays can be controlled via digital pins D3, D4,
 * D5, and D6.
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the LCD with I2C address 0x27 and 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Relay control pins
const int relay1 = 6;
const int relay2 = 5;
const int relay3 = 4;
const int relay4 = 3;

// Frequency measurement variables
unsigned long previousMillis = 0;
const long interval = 1000; // Interval for frequency calculation (1 second)
int frequency = 0;

void setup() {
  // Initialize the LCD
  lcd.begin(16, 2); // Corrected to include the number of columns and rows
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Welcome!");
  lcd.setCursor(0, 1);
  lcd.print("Relay Control");
  delay(2000); // Display welcome message for 2 seconds

  // Set relay pins as outputs
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);

  // Initialize relays to off
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay4, LOW);
}

void loop() {
  unsigned long currentMillis = millis();

  // Turn on relay1
  digitalWrite(relay1, HIGH);
  delay(1000); // Wait for 1 second
  // Turn off relay1
  digitalWrite(relay1, LOW);
  delay(1000); // Wait for 1 second

  // Turn on relay2
  digitalWrite(relay2, HIGH);
  delay(1000); // Wait for 1 second
  // Turn off relay2
  digitalWrite(relay2, LOW);
  delay(1000); // Wait for 1 second

  // Turn on relay3
  digitalWrite(relay3, HIGH);
  delay(1000); // Wait for 1 second
  // Turn off relay3
  digitalWrite(relay3, LOW);
  delay(1000); // Wait for 1 second

  // Turn on relay4
  digitalWrite(relay4, HIGH);
  delay(1000); // Wait for 1 second
  // Turn off relay4
  digitalWrite(relay4, LOW);
  delay(1000); // Wait for 1 second
  
  // Generate square wave on relay1 pin
  digitalWrite(6, HIGH);
  delay(500); // 500ms HIGH
  digitalWrite(6, LOW);
  delay(500); // 500ms LOW

  // Calculate frequency every second
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    frequency = 1000; // Frequency is 1 Hz (1 cycle per second)

    // Update LCD with frequency
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Frequency:");
    lcd.setCursor(0, 1);
    lcd.print(frequency);
    lcd.print(" Hz");
  }
}

This code initializes the I2C LCD display and sets up the relay control pins. It displays a welcome message on the LCD and then enters a loop where it sequentially turns on and off each relay. Additionally, it generates a square wave on one of the relay control pins and updates the LCD with the frequency of the square wave.