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

Arduino-Controlled GSM Relay Switch with Audio Playback

View and Edit Project In Cirkit DesignerImage 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

DFPlayer MINI

SIM800L

PCB Antenna

4 Channel Relay Module

220V Fan

5V Adapter

AC Supply

Resistors

Ceramic Capacitor

Wiring Details

Arduino UNO

DFPlayer MINI

SIM800L

PCB Antenna

4 Channel Relay Module

220V Fan

5V Adapter

AC Supply

Resistors

Ceramic Capacitor

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