Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled GSM Relay Switch with Audio Playback

Image of Arduino-Controlled GSM Relay Switch with Audio Playback

Circuit Documentation

Summary

The circuit in question is designed to control a 220V fan using an Arduino UNO as the central processing unit. It includes a DFPlayer MINI for audio playback, a SIM800L module for GSM communication, and a 4-channel relay module to control AC loads. The circuit is powered by a 5V adapter and can interface with an AC supply. A PCB antenna is included for enhanced signal reception for the SIM800L module. The circuit also features resistors and a ceramic capacitor for signal conditioning and noise suppression.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P.
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

DFPlayer MINI

  • A small and low-cost MP3 module that can directly play MP3 files from a microSD card.
  • It has a variety of outputs and control interfaces including RX, TX for serial communication.

SIM800L

  • A GSM/GPRS module that allows for GSM communications such as SMS and voice calls.
  • It includes interfaces for a microphone, speaker, and a PCB antenna connection.

PCB Antenna

  • An antenna designed for PCB mounting, used to enhance the signal reception of wireless modules like the SIM800L.

4 Channel Relay Module

  • A module with 4 relays that can control up to 4 different AC loads.
  • Each relay has a normally open (N.O.) and normally closed (N.C.) contact along with a common (COM) terminal.

220V Fan

  • An AC fan designed to operate at 220V.

5V Adapter

  • A power adapter that converts AC supply to 5V DC output.

AC Supply

  • An AC power source that provides electrical energy to the circuit.

Resistors

  • Passive components used to limit current and divide voltages in the circuit.
  • Values: 100 Ohms, 1000 Ohms.

Ceramic Capacitor

  • A passive component used to filter noise from the power supply and signals.
  • Value: 0.02 microfarads (20 nF).

Wiring Details

Arduino UNO

  • Digital Pin D0 connected to Resistor (1000 Ohms).
  • Digital Pin D1 connected to Resistor (1000 Ohms).
  • Digital Pin D9 connected to SIM800L RXD.
  • Digital Pin D8 connected to SIM800L TXD.
  • Digital Pins D5, D4, D3, D2 connected to Relay Module IN 1, IN 2, IN 3, IN 4 respectively.
  • 5V and GND pins provide power to the DFPlayer MINI, SIM800L, Relay Module, and 5V Adapter.

DFPlayer MINI

  • VCC connected to 5V power line.
  • RX connected to Resistor (1000 Ohms).
  • TX connected to Resistor (1000 Ohms).
  • GND connected to common ground line.
  • SPK2 connected to Resistor (100 Ohms).

SIM800L

  • VCC connected to 5V power line.
  • GND connected to common ground line.
  • MIC+ connected to Ceramic Capacitor (20 nF) and Resistor (100 Ohms).
  • MIC- connected to Ceramic Capacitor (20 nF).
  • RXD connected to Arduino UNO D9.
  • TXD connected to Arduino UNO D8.
  • NFT connected to PCB Antenna.

PCB Antenna

  • Wire connected to SIM800L NFT.

4 Channel Relay Module

  • VCC+ connected to 5V power line.
  • IN 1, IN 2, IN 3, IN 4 connected to Arduino UNO D5, D4, D3, D2.
  • COM terminals interconnected and connected to AC source +.
  • N.O. 1 connected to 220V Fan L.

220V Fan

  • L connected to Relay Module N.O. 1.
  • N connected to AC source -.

5V Adapter

  • AC In 1, AC In 2 connected to AC Supply +ve, -ve.
  • 5V output connected to 5V power line.
  • GND connected to common ground line.

AC Supply

  • +ve connected to 5V Adapter AC In 1.
  • -ve connected to 5V Adapter AC In 2.

Resistors

  • 1000 Ohms resistors connected between Arduino UNO D0, D1 and DFPlayer MINI RX, TX.
  • 100 Ohms resistor connected between DFPlayer MINI SPK2 and Ceramic Capacitor.

Ceramic Capacitor

  • 20 nF capacitor connected between SIM800L MIC+ and MIC-.

Documented Code

The code provided is for the Arduino UNO microcontroller. It is designed to control the 4-channel relay module based on DTMF tones received from a GSM call through the SIM800L module. The code includes functions for initializing the SIM800L module, handling incoming calls, decoding DTMF tones, and controlling the state of the relays. The relay states are stored in EEPROM to retain the last state after a power cycle.

#include <EEPROM.h>
#include <SoftwareSerial.h> //Create software serial object to communicate with SIM800L
SoftwareSerial GSM(8, 9);   //SIM800L Tx & Rx is connected to Arduino #8 & #9

char *phone_no = "+917760460758"; //change +92 with country code and 3378655465 with phone number to sms

unsigned long currentTime;
unsigned long loopTime1;
unsigned long loopTime2;

#define Relay1 2 // Load1 Pin Out
#define Relay2 3 // Load2 Pin Out
#define Relay3 4 // Load3 Pin Out
#define Relay4 5 // Load4 Pin Out

int load1, load2, load3, load4;

void setup() {// put your setup code here, to run once

pinMode(Relay1, OUTPUT); digitalWrite(Relay1, 1); 
pinMode(Relay2, OUTPUT); digitalWrite(Relay2, 1); 
pinMode(Relay3, OUTPUT); digitalWrite(Relay3, 1); 
pinMode(Relay4, OUTPUT); digitalWrite(Relay4, 1); 

Serial.begin(9600);//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)  
GSM.begin(9600);   //Begin serial communication with Arduino and SIM800L

Serial.println("Initializing....");
initModule("AT","OK",300);          //Scan for GSM Module
initModule("ATE0","OK",300);
initModule("AT+CPIN?","READY",300);
initModule("AT+CLIP=1","OK",300);  
initModule("AT+DDET=1","OK",300);
Serial.println("Initialized Successfully"); 

load1 = EEPROM.read(1);
load2 = EEPROM.read(2);
load3 = EEPROM.read(3);
load4 = EEPROM.read(4);

relays();
}

void loop(){

currentTime = millis(); 
if(currentTime >= (loopTime1 + 2000)){
initModule("AT","OK",300); 
loopTime1 = currentTime;   
}

if(GSM.find("CLIP:")) {
 Serial.println("RING!");
 delay(200);
    
while(1){     
if(GSM.find(phone_no)){ 
initModule("ATA","OK",300);      
delay(1500);
loopTime2 = currentTime; 
while (1){   
   currentTime = millis();  
if(currentTime >= (loopTime2 + 20000)){
  Serial.println("Call End");
  loopTime2 = currentTime; 
  break;
} 
      
if(GSM.find("+DTMF:")){
  int Data = GSM.parseInt();
  switch(Data){                                

case 1: {
   load1=0;
   eeprom_write();
   relays();  
loopTime2 = currentTime;
   break;}

case 2: { 
   load2=0;
   eeprom_write();
   relays();  
loopTime2 = currentTime;   
   break;}

case 3: {
   load3=0;
   eeprom_write();
   relays();    
loopTime2 = currentTime;   
   break;}

case 4: {
   load4=0;
   eeprom_write();
   relays();    
loopTime2 = currentTime;   
   break;}

case 5: {
   load1=1;
   eeprom_write();
   relays();  
loopTime2 = currentTime;   
   break;}

case 6: {
   load2=1;
   eeprom_write();
   relays();   
loopTime2 = currentTime;   
   break;}

case 7: {
   load3=1;
   eeprom_write();
   relays();  
loopTime2 = currentTime;   
   break;}

case 8: { 
   load4=1;
   eeprom_write();
   relays();  
loopTime2 = currentTime;  
   break;}

case 9: { 
   load1=0,load2=0,load3=0,load4=0;
   eeprom_write();
   relays();  
loopTime2 = currentTime;   
   break;}

case 0: {
   load1=1,load2=1,load3=1,load4=1;
   eeprom_write();
   relays();