Circuit Documentation
Summary
The circuit in question is designed to control a 4-channel relay module via an Arduino Nano, which is interfaced with a SIM800L GSM module. The SIM800L module allows the Arduino to send and receive SMS messages, enabling remote control of the relay states. An electrolytic capacitor is included in the circuit for power supply stabilization.
Component List
Arduino Nano
- Microcontroller board based on the ATmega328P
- It has digital I/O pins (D0-D13), analog input pins (A0-A7), and several power pins (3V3, 5V, GND, VIN).
- Used as the main controller for processing and executing embedded code to control other components in the circuit.
SIM800L GSM Module
- A compact GSM/GPRS module for communication
- Pins include power supply (VCC, GND), serial communication (TXD, RXD), and others for module control.
- Enables the Arduino Nano to send and receive SMS messages for remote control.
Relay 4 Channel 5V
- A relay module with four channels, each with a normally open (NO) and normally closed (NC) contact.
- Controlled by digital input signals (IN1-IN4) from the Arduino Nano.
- Allows for switching of higher power loads than the Arduino can handle directly.
Electrolytic Capacitor
- A passive electronic component with a specific capacitance value.
- Has two pins: positive (+) and negative (-).
- Used for power supply filtering to reduce voltage spikes and noise.
Wiring Details
Arduino Nano
5Vconnected to the VCC of SIM800L, Relay Module, and the positive pin of the Electrolytic Capacitor.GNDconnected to the GND of SIM800L, Relay Module, and the negative pin of the Electrolytic Capacitor.D2connected to the TXD of SIM800L.D3connected to the RXD of SIM800L.D4connected to IN1 of Relay Module.D5connected to IN2 of Relay Module.D6connected to IN3 of Relay Module.D7connected to IN4 of Relay Module.
SIM800L GSM Module
VCCconnected to the 5V supply through the Electrolytic Capacitor.GNDconnected to the common ground.TXDconnected toD2on the Arduino Nano.RXDconnected toD3on the Arduino Nano.
Relay 4 Channel 5V
VCCconnected to the 5V supply through the Electrolytic Capacitor.GNDconnected to the common ground.IN1connected toD4on the Arduino Nano.IN2connected toD5on the Arduino Nano.IN3connected toD6on the Arduino Nano.IN4connected toD7on the Arduino Nano.
Electrolytic Capacitor
+connected to the 5V supply.-connected to the common ground.
Documented Code
#include <EEPROM.h>
#include <SoftwareSerial.h> // Create software serial object to communicate with SIM800L
SoftwareSerial GSM(2, 3); // SIM800L Tx & Rx is connected to Arduino D2 & D3
String phone_no1 = "+919946206378"; // Change this to your first phone number
String phone_no2 = "+918606206385"; // Change this to your second phone number
String RxString = ""; // Will hold the incoming string from the GSM module
char RxChar = ' ';
int Counter = 0;
String GSM_Nr = "";
String GSM_Msg = "";
#define Relay1 4 // Load1 Pin Out (D4)
#define Relay2 5 // Load2 Pin Out (D5)
#define Relay3 6 // Load3 Pin Out (D6)
#define Relay4 7 // Load4 Pin Out (D7)
int load1, load2, load3, load4;
void setup() {
// Set relay pins as outputs and turn them off initially
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 IDE
GSM.begin(9600); // Begin communication with SIM800L
Serial.println("Initializing....");
initModule("AT", "OK", 1000); // Check for GSM module
initModule("AT+CPIN?", "READY", 1000); // Check SIM card status
initModule("AT+CMGF=1", "OK", 1000); // Set SMS mode to ASCII
initModule("AT+CNMI=2,2,0,0,0", "OK", 1000); // Set to read incoming SMS
Serial.println("Initialized Successfully");
// Load the relay states from EEPROM
load1 = EEPROM.read(1);
load2 = EEPROM.read(2);
load3 = EEPROM.read(3);
load4 = EEPROM.read(4);
relays(); // Set relay states based on EEPROM
delay(100);
}
void loop() {
RxString = "";
Counter = 0;
// Read incoming data from the GSM module
while (GSM.available()) {
delay(1);
RxChar = char(GSM.read());
if (Counter < 200) {
RxString.concat(RxChar);
Counter = Counter + 1;
}
}
if (Received(F("CMT:"))) GetSMS();
// Verify the message sender and act accordingly
if (GSM_Nr == phone_no1 || GSM_Nr == phone_no2) {
if (GSM_Msg == "load1on") { load1 = 0; sendSMS(GSM_Nr, "Ok Load 1 is On"); }
if (GSM_Msg == "load1off") { load1 = 1; sendSMS(GSM_Nr, "Ok Load 1 is Off"); }
if (GSM_Msg == "load2on") { load2 = 0; sendSMS(GSM_Nr, "Ok Load 2 is On"); }
if (GSM_Msg == "load2off") { load2 = 1; sendSMS(GSM_Nr, "Ok Load 2 is Off"); }
if (GSM_Msg == "load3on") { load3 = 0; sendSMS(GSM_Nr, "Ok Load 3 is On"); }
if (GSM_Msg == "load3off") { load3 = 1; sendSMS(GSM_Nr, "Ok Load 3 is Off"); }
if (GSM_Msg == "load4on") { load4 = 0; sendSMS(GSM_Nr, "Ok Load 4 is On"); }
if (GSM_Msg == "load4off") { load4 = 1; sendSMS(GSM_Nr, "Ok Load 4 is Off"); }
if (GSM_Msg == "allon") { load1 = 0; load2 = 0; load3 = 0; load4 = 0; sendSMS(GSM_Nr, "Ok All Load is On"); }
if (GSM_Msg == "alloff") { load1 = 1; load2 = 1; load3 = 1; load4 = 1; sendSMS(GSM_Nr, "Ok All Load is Off"); }
if (GSM_Msg == "loadstatus") {
String loadst = "";
loadst += (load1 == 0) ? "Load1 On\r\n" : "Load1 Off\r\n";
loadst += (load2 == 0) ? "Load2 On\r\n" : "Load2 Off\r\n";
loadst += (load3 == 0) ? "Load3 On\r\n" : "Load3 Off\r\n";
loadst += (load4 == 0) ? "Load4 On" : "Load4 Off";
sendSMS(GSM_Nr, loadst);
}
eeprom_write(); // Save the relay states to EEPROM
relays(); // Apply relay states
}
GSM_Nr = "";
GSM_Msg = "";
}
void eeprom_write() {
EEPROM.write(1, load1);
EEPROM.write(2, load2);
EEPROM.write(3, load3);
EEPROM.write(4, load4);
}
void relays() {
digitalWrite(Relay1, load1);
digitalWrite(Relay2, load2);
digitalWrite(Relay3, load3);
digitalWrite(Relay4, load4);
}
// Send SMS
void sendSMS(String number, String msg) {
GSM.print("AT+CMGS=\"");
GSM.print(number);
GSM.println("\"\\r\\n");
delay(500);
GSM.println(msg);
delay(500);
