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

Arduino UNO Controlled LCD Display and 4-Channel Relay Module

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled LCD Display and 4-Channel Relay Module

Circuit Documentation

Summary of the Circuit

This circuit consists of an Arduino UNO microcontroller, an LCD I2C Display, and a 4-channel 5V Relay module. The Arduino UNO is used as the central processing unit to control the LCD display via the I2C communication protocol and to operate the relay module through its digital output pins. The LCD display shows a welcome message and the frequency of a square wave generated by the Arduino, which is also used to control the state of the relays. The relay module allows for controlling high-power devices that the Arduino cannot drive directly.

Component List

Arduino UNO

LCD I2C Display

Relay 4 Channel 5v

Wiring Details

Arduino UNO

LCD I2C Display

Relay 4 Channel 5v

Documented Code

/*
 * 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();

  // Generate square wave on relay1 pin
  digitalWrite(relay1, HIGH);
  delay(500); // 500ms HIGH
  digitalWrite(relay1, LOW);
  delay(500); // 500ms LOW

  // Calculate frequency every second
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    frequency = 1; // 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 is designed to run on the Arduino UNO microcontroller. It initializes the LCD display, prints a welcome message, and then enters a loop where it generates a square wave on one of the relay control pins. The frequency of the square wave is displayed on the LCD. The relays are controlled by the digital pins D3 to D6.