top of page
Writer's pictureSanskruti Ashtikar

GSM-based Remote Control System using PIC Microcontroller

Updated: 7 days ago

Introduction


With the increasing need for automation and remote control in modern technology, GSM (Global System for Mobile Communications) modules have become a popular choice for implementing remote control systems. Using a GSM module with a microcontroller like the PIC, you can control appliances, devices, or even entire systems remotely via SMS. This article details how to design and implement a GSM-based remote control system using a PIC microcontroller.





System Overview


The GSM-based remote control system allows users to control various devices by sending SMS commands to a GSM module interfaced with a PIC microcontroller. The microcontroller interprets these commands and takes appropriate actions, such as turning devices on or off, or triggering other control mechanisms.


Components Required


  1. PIC Microcontroller (e.g., PIC16F877A)

  2. GSM Module (e.g., SIM800, SIM900)

  3. Relay Module (for controlling devices)

  4. LCD Display (16x2)

  5. Voltage Regulator (e.g., LM7805)

  6. Resistors, Capacitors, Diodes

  7. Power Supply (5V for PIC and 12V for GSM Module)

  8. Connecting Wires and Breadboard/PCB


Block Diagram


The system consists of the following blocks:

  1. GSM Module: Receives SMS commands from the user’s mobile phone and sends the data to the PIC microcontroller.

  2. PIC Microcontroller: Processes the received commands and controls the connected devices accordingly.

  3. Relay Module: Acts as an interface between the microcontroller and the electrical devices. It allows the microcontroller to control high-voltage devices safely.

  4. LCD Display: Provides feedback to the user by displaying the status of the system and the devices.


Circuit Diagram


Connections:


  1. GSM Module: Connect the TX pin of the GSM module to the RX pin of the PIC microcontroller (e.g., RC7 on PIC16F877A) and the RX pin of the GSM module to the TX pin of the PIC (e.g., RC6 on PIC16F877A).

  2. Relay Module: Connect the relay input pins to the output pins of the PIC microcontroller. The relays can control devices like lights, fans, or other appliances.

  3. LCD Display: Connect the LCD display to the microcontroller using a standard 4-bit mode interface (D4-D7 for data, RS, and EN pins connected to appropriate GPIO pins of the PIC).

  4. Power Supply: The PIC microcontroller and the GSM module operate at different voltages (5V for PIC and 12V for GSM), so ensure to use appropriate voltage regulators.


Working Principle


Step 1: Initialization


When the system powers up, the PIC microcontroller initializes the GSM module, the relay module, and the LCD display. The GSM module is set to receive SMS messages, and the LCD displays a welcome message or system status.


Step 2: Receiving SMS


The GSM module waits for incoming SMS messages. When an SMS is received, it is forwarded to the PIC microcontroller via UART communication. The microcontroller reads the SMS and extracts the command.


Step 3: Command Processing


The PIC microcontroller processes the SMS command. Typical commands could be "ON1", "OFF1" to control the first device, "ON2", "OFF2" for the second device, and so on. The microcontroller then sends a signal to the appropriate relay to switch the connected device on or off.


Step 4: Status Feedback


The system can send a status message back to the user's mobile phone, confirming the action taken. The LCD also displays the current status of the devices, providing visual feedback.





PIC Microcontroller Programming


Here’s a simplified example code to demonstrate how the PIC microcontroller can handle SMS commands to control devices.


#include <xc.h>
#include <string.h>
#define _XTAL_FREQ 20000000  // Define the oscillator frequency for delay
// Configuration bits for PIC16F877A
#pragma config FOSC = HS        // High-speed oscillator
#pragma config WDTE = OFF       // Watchdog Timer disabled
#pragma config PWRTE = OFF      // Power-up Timer disabled
#pragma config BOREN = ON       // Brown-out Reset enabled
#pragma config LVP = OFF        // Low-Voltage ICSP disabled
#pragma config CPD = OFF        // Data EEPROM code protection off
#pragma config WRT = OFF        // Flash program memory write protection off
#pragma config CP = OFF         // Flash program memory code protection off
// Define UART pins
#define TX RC6
#define RX RC7
// Define control pins for relay
#define RELAY1 RB0
#define RELAY2 RB1
// Function Prototypes
void initialize();
void send_string(char* str);
void read_sms();
void process_command(char* cmd);
void main() {
    initialize();
    
    while(1) {
        read_sms();  // Check for any new SMS
    }
}
void initialize() {
    // Set up UART, LCD, and relay pins
    TRISB = 0x00;  // Set PORTB as output for relays
    TRISC6 = 0;    // TX pin output
    TRISC7 = 1;    // RX pin input
    
    // UART configuration
    SPBRG = 31;    // Baud rate setting for 9600
    TXSTA = 0x24;  // Enable transmission
    RCSTA = 0x90;  // Enable serial port and continuous receive


    
    // LCD initialization code (if using an LCD display)
    // Relay initialization
    RELAY1 = 0;    // Initially off
    RELAY2 = 0;
    
    // Initialize GSM module commands (AT commands for text mode, etc.)
    send_string("AT\r\n"); // Initialize GSM module
    __delay_ms(1000);
    send_string("AT+CMGF=1\r\n"); // Set SMS text mode
    __delay_ms(1000);
}
void send_string(char* str) {
    while (*str != '\0') {
        while (!TXIF);  // Wait for TX buffer to be empty
        TXREG = *str;   // Send the character
        str++;
    }
}
void read_sms() {
    char cmd[16];
    int i = 0;
    
    // Wait until SMS is received
    while(!RCIF);
    
    // Read the SMS content
    while (RCIF && i < 16) {
        cmd[i++] = RCREG;  // Read each character
    }
    cmd[i] = '\0';  // Null-terminate the string
    
    // Process the received command
    process_command(cmd);
}
void process_command(char* cmd) {
    if (strstr(cmd, "ON1")) {
        RELAY1 = 1;  // Turn on device 1
        send_string("Device 1 ON\r\n");
    } else if (strstr(cmd, "OFF1")) {
        RELAY1 = 0;  // Turn off device 1
        send_string("Device 1 OFF\r\n");
    } else if (strstr(cmd, "ON2")) {
        RELAY2 = 1;  // Turn on device 2
        send_string("Device 2 ON\r\n");
    } else if (strstr(cmd, "OFF2")) {
        RELAY2 = 0;  // Turn off device 2
        send_string("Device 2 OFF\r\n");
    } else {
        send_string("Invalid Command\r\n");
    }
}




Explanation of the Code


  1. Initialization: The initialize() function configures the UART for serial communication, sets up the relay control pins, and initializes the GSM module by sending AT commands.

  2. Sending and Receiving Data: The send_string() function sends strings (such as AT commands or responses) via UART. The read_sms() function reads the incoming SMS message and stores it in a buffer.

  3. Command Processing: The process_command() function checks the received SMS for specific commands like "ON1" or "OFF1" and controls the corresponding relays accordingly.


Conclusion


A GSM-based remote control system using a PIC microcontroller is an effective solution for remotely managing various devices. This project can be expanded to control multiple devices, provide feedback via SMS, and integrate with home automation systems. The flexibility of GSM communication combined with the power of a PIC microcontroller offers a wide range of applications, from industrial automation to smart home solutions.


Further Enhancements


  1. Security: Implement password protection or caller ID verification to ensure only authorized users can control the system.

  2. Real-Time Monitoring: Integrate sensors to monitor the status of the controlled devices and send updates to the user.

  3. Multiple Device Control: Expand the system to control more devices and implement a more sophisticated command structure.

  4. Smartphone App: Develop a mobile app to provide a user-friendly interface for controlling the system instead of using SMS commands.


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 






0 views0 comments

Related Posts

See All

Comentarios


bottom of page