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

Arduino Mega 2560-Based Relay Control System with LCD Display and MP3 Player

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560-Based Relay Control System with LCD Display and MP3 Player

Circuit Documentation

Summary

This circuit is designed using an Arduino Mega 2560 microcontroller, multiple KY-004 Key Switch Modules, LCD displays with I2C interface, an 8-channel relay module, a serial MP3 player, and a toggle switch. The circuit is programmed to control relays based on button inputs and display information on the LCDs. The MP3 player is used to play audio sequences.

Component List

  1. Arduino Mega 2560

    • Description: A microcontroller board based on the ATmega2560.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, AREF, SDA, SCL.
  2. KY-004 Key Switch Module

    • Description: A simple key switch module.
    • Pins: S, Middle, -.
  3. LCD Display with I2C Interface (lcdi2c)

    • Description: A 16x2 character LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL.
  4. 8 Channel Relay JD-VCC

    • Description: A relay module with 8 channels.
    • Pins: JD-VCC, VCC, GND, In1-In8, IN1_NC, IN1_COM, IN1_NO, IN2_NC, IN2_COM, IN2_NO, IN3_NC, IN3_COM, IN3_NO, IN4_NC, IN4_COM, IN4_NO, IN5_NC, IN5_COM, IN5_NO, IN6_NC, IN6_COM, IN6_NO, IN7_NC, IN7_COM, IN7_NO, IN8_NC, IN8_COM, IN8_NO.
  5. Serial MP3 Player

    • Description: A module for playing MP3 files.
    • Pins: RX, TX, VCC, GND.
  6. Toggle Switch SPST

    • Description: A single-pole single-throw toggle switch.
    • Pins: L1, COM.

Wiring Details

Arduino Mega 2560

KY-004 Key Switch Module

LCD Display with I2C Interface (lcdi2c)

8 Channel Relay JD-VCC

Serial MP3 Player

Toggle Switch SPST

Documented Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "SerialMP3Player.h"
#include <Chrono.h>
#define TX 19
#define RX 18

Chrono stopwatch;  // Create a Chrono object

float z = 0.0;

SerialMP3Player mp3(RX,TX);

const int switchPin = 5;  // Pin connected to the flick switch
int switchState = 0;
int lastSwitchState = HIGH;
bool mode = false;  // false = OFF mode, true = ON mode

// Variables for managing time-based tasks in ON mode
unsigned long previousMillis = 0;  // Store the last time the function was called
const long interval = 100;  // Increment every 1 seconds (100ms)

const long debounceDelay = 250; // debounce time; increase if necessary

const int relay1 = 6;  
const int relay2 = 7;  
const int relay3 = 8;  
const int relay4 = 9;  
const int relay5 = 10;
const int relay6 = 11;
const int relay7 = 12;
const int relay8 = 13;

LiquidCrystal_I2C lcd1(0x27, 16, 2);
LiquidCrystal_I2C lcd2(0x26, 16, 2);
LiquidCrystal_I2C lcd3(0x25, 16, 2);
LiquidCrystal_I2C lcd4(0x23, 16, 2);

// Pin definitions for buttons
const int button1_inc = 23;  // Button for increasing a
const int button2_dec = 22;  // Button for decreasing a
const int button3_inc = 25;  // Button for increasing b
const int button4_dec = 24;  // Button for decreasing b
const int button5_inc = 27;  // Button for increasing c
const int button6_dec = 26;  // Button for decreasing c
const int button7_inc = 29;  // Button for increasing d
const int button8_dec = 28;  // Button for decreasing d
const int button9_inc = 31;  // Button for increasing e
const int button10_dec = 30;  // Button for decreasing e
const int button11_inc = 33;  // Button for increasing f
const int button12_dec = 32;  // Button for decreasing f
const int button13_inc = 35;  // Button for increasing g
const int button14_dec = 34;  // Button for decreasing g
const int button15_inc = 37;  // Button for increasing h
const int button16_dec = 36;  // Button for decreasing h
const int button17_inc = 39;  // Button for increasing i
const int button18_dec = 38;  // Button for decreasing i
const int button19_inc = 41;  // Button for increasing j
const int button20_dec = 40;  // Button for decreasing j
const int button21_inc = 43;  // Button for increasing k
const int button22_dec = 42;  // Button for decreasing k
const int button23_inc = 45;  // Button for increasing l
const int button24_dec = 44;  // Button for decreasing l
const int button25_inc = 47;  // Button for increasing m
const int button26_dec = 46;  // Button for decreasing m
const int button27_inc = 49;  // Button for increasing n
const int button28_dec = 48;  // Button for decreasing n
const int button29_inc = 51;  // Button for increasing o
const int button30_dec = 50;  // Button for decreasing o
const int button31_inc = 53;  // Button for increasing p
const int button32_dec = 52;  // Button for decreasing p

const int button33