Wireless Temperature Sensor using GSM and Microcontroller

The wireless temperature sensor has been designed to measure temperature from a remote location and send it to your mobile device through the SIM900D GSM module. We use the PIC16F877A microcontroller to measure temperature using an LM35 temperature sensor. Then, we interface the microcontroller with the SIM900D GSM module to send the temperature via SMS to a recipient. It is possible to use multiple sensors to measure various physical parameters from a remote location and send them to any desired number.

Project Overview

The wireless temperature sensor project utilizes a GSM module and a microcontroller to measure temperature from a remote location and send it to a designated mobile number through SMS. The PIC16F877A microcontroller interfaces with an LM35 temperature sensor to measure the temperature. The system sends the measured temperature through SMS using the SIM900D GSM module. Additionally, users can integrate other sensors to measure different physical parameters and send them to any desired mobile number.

Circuit Diagram

We have already posted articles on digital temperature sensor using PIC microcontroller and how to send SMS using GSM module and PIC microcontroller. We recommend you go through these articles before reading this article further. If you have gone through these articles, now you have knowledge about how to measure temperature using the PIC microcontroller and LM35 sensor, as well as how to send SMS using GSM and PIC microcontroller.

Below is the circuit diagram of the wireless temperature sensor that uses a PIC microcontroller:

wireless temperature sensor using gsm
wireless temperature sensor using gsm

In the above circuit diagram, the temperature sensor can be located at a remote location, and you can connect more than one sensor, such as a light sensor, motion sensor, or pressure sensor, according to the requirements of your project. The LCD is optional. The GSM module is used to send SMS to any mobile number. You can also use other wireless communication sources like Bluetooth if the distance is not more than 5 meters. This project has many applications in remote monitoring systems. You can easily modify it according to your specifications.

Components

The following bill of materials doesn’t include power supply components for the microcontroller and GSM module:

Resistors,"R2",2k,72-0502
Resistors,"R3",10k,
Capacitors,"C1",22pF,
Capacitors,"C2",22pF,
Integrated Circuits,"U1",PIC16F877A,
Integrated Circuits,"U2",LM35,
Diodes,"D1",DIODE,
Diodes,"D2",DIODE,
Diodes,"D3",DIODE,
Diodes,"D4",DIODE,
Miscellaneous,"LCD1",LM016L,
Miscellaneous,"X1",8MHz,
GSM MODULE SIM900D

Code

The code for this project is written in the MIKROC compiler. If you do not know how to use MikroC for Pic, you can refer to these tutorials:

This code reads and transmits temperature data from an LM35 sensor using a microcontroller. It initializes an LCD module and sets up AT commands for communication with a modem. The main loop repeatedly reads temperature values, converts them to a string, displays them on the LCD with the degree symbol, and then sends this temperature data as an SMS message using the modem. The loop has a delay in sending SMS updates every 10 seconds. This code effectively provides a system for monitoring and transmitting temperature information via SMS.

// Author: Bilal Malik (bilalmalikuet@gmail.com)
// Note: You can also email me for project/organization-related inquiries

// LCD module connections
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_RS at RB7_bit;

sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_RS_Direction at TRISB7_bit;

// Temperature variables
int temp;
char txt[7];

// AT commands initialization
char AT[] = "AT";
char noecho[] = "ATE0";
char mode_text[] = "AT+CMGF=1";
char mobile_no[] = "AT+CMGS=\"+92090078601\"";
char terminator = 0x1A;
char text1[] = "temperature=";

// Temperature measurement function
void READ_temp(void)
{
    temp = ADC_Read(0);
    temp = temp * 0.4887;
}

void data_conversion(void)
{
    inttostr(temp, txt);
}

void display(void)
{
    lcd_out(1, 1, "TEMPERATURE=");
    lcd_out(1, 13, Ltrim(txt));
    Lcd_Chr_Cp(0xdf); // Display degree symbol
    Lcd_Chr_Cp('C');
    Lcd_Chr_Cp(' ');
}

// String transmit function
void send_to_modem(char *s)
{
    while (*s)
    {
        UART1_WRITE(*s++);
    }
    UART1_WRITE(0X0D); // Carriage return
}

void send_to_modem1(char *s)
{
    while (*s)
        UART1_WRITE(*s++);
}

void send_sms()
{
    send_to_modem1(text1);
    delay_ms(1000);
    send_to_modem1(txt);
    delay_ms(1000);
    uart1_write(terminator);
    delay_ms(1000);
}

void main()
{
    lcd_init();
    ADC_Init();
    Uart1_Init(9600);

    while (1)
    {
        READ_temp();
        delay_ms(100);
        data_conversion();
        delay_ms(100);
        display();
        delay_ms(100);
        send_to_modem(AT);
        delay_ms(1000);
        send_to_modem(noecho);
        delay_ms(1000);
        send_to_modem(mode_text);
        delay_ms(1000);
        send_to_modem(mobile_no);
        delay_ms(1000);
        send_sms();       // Function to send temperature value
        delay_ms(10000);  // Send SMS every 10 seconds
    }
}

How does this Code Work?

// Author: Bilal Malik (bilalmalikuet@gmail.com)
// Note: You can also email me for project/organization-related inquiries

// LCD module connections
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_RS at RB7_bit;

sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_RS_Direction at TRISB7_bit;

This section defines the connections between the LCD module and the microcontroller’s GPIO pins.

// Temperature variables
int temp;
char txt[7];

The LM35 sensor obtains the temperature value and converts it into a string to store.

// AT commands initialization
char AT[] = "AT";
char noecho[] = "ATE0";
char mode_text[] = "AT+CMGF=1";
char mobile_no[] = "AT+CMGS=\"+92090078601\"";
char terminator = 0x1A;
char text1[] = "temperature=";

The AT commands will be sent to the GSM module via the UART communication and these variables store them.

// Temperature measurement function
void READ_temp(void)
{
    temp = ADC_Read(0);
    temp = temp * 0.4887;
}

This function reads the analog value from the LM35 temperature sensor connected to the microcontroller’s ADC pin. It then converts the analog value to temperature using the formula given in the code.

void data_conversion(void)
{
    inttostr(temp, txt);
}

This function converts the integer temperature value to a string format for displaying purposes.

void display(void)
{
    lcd_out(1, 1, "TEMPERATURE=");
    lcd_out(1, 13, Ltrim(txt));
    Lcd_Chr_Cp(0xdf); // Display degree symbol
    Lcd_Chr_Cp('C');
    Lcd_Chr_Cp(' ');
}

This function displays the temperature on the LCD module. It also adds the degree symbol and the letter ‘C’ for Celsius.

// String transmit function
void send_to_modem(char *s)
{
    while (*s)
    {
        UART1_WRITE(*s++);
    }
    UART1_WRITE(0X0D); // Carriage return
}

This function sends a string of characters via the UART communication to the GSM module. It sends each character one by one until it reaches the end of the string.

void send_to_modem1(char *s)
{
    while (*s)
        UART1_WRITE(*s++);
}

This function is similar to the previous one, but it does not send the carriage return character.

void send_sms()
{
    send_to_modem1(text1);
    delay_ms(1000);
    send_to_modem1(txt);
    delay_ms(1000);
    uart1_write(terminator);
    delay_ms(1000);
}

This function sends an SMS message containing the temperature value. It sends the text “temperature=” followed by the temperature value converted to a string. Finally, it sends the terminator character to indicate the end of the message.

void main()
{
    lcd_init();
    ADC_Init();
    Uart1_Init(9600);

    while (1)
    {
        READ_temp();
        delay_ms(100);
        data_conversion();
        delay_ms(100);
        display();
        delay_ms(100);
        send_to_modem(AT);
        delay_ms(1000);
        send_to_modem(noecho);
        delay_ms(1000);
        send_to_modem(mode_text);
        delay_ms(1000);
        send_to_modem(mobile_no);
        delay_ms(1000);
        send_sms();       // Function to send temperature value
        delay_ms(10000);  // Send SMS every 10 seconds
    }
}

The main function initializes the LCD, ADC, and UART modules. It then enters an infinite loop where it repeatedly measures the temperature, converts it to a string, displays it on the LCD, and sends it as an SMS. There are delays between each step to control the timing. The SMS sending is repeated every 10 seconds.


The code above sends temperature values to the given number every 10 seconds. You can make this code even more flexible by adding interrupts instead of using the delay function. This way, the microcontroller can continue with other tasks if it is used for multiple applications. Below is a circuit diagram to test whether the microcontroller is successfully sending the data. I have tested this code on several GSM modules, and it works perfectly.

wireless temperature sensor
wireless temperature sensor

Conclusion

In conclusion, the wireless temperature sensor project presented in this article demonstrates the use of a GSM module and a microcontroller to measure temperature from a remote location and send it to a designated mobile number via SMS. The project combines the capabilities of the PIC16F877A microcontroller and the LM35 temperature sensor to accurately measure temperature values. The system also allows for the integration of additional sensors to measure other physical parameters. This wireless temperature sensor has applications in remote monitoring systems and can be customized to suit specific requirements. By following the provided circuit diagram and using the code provided, users can easily implement this project and begin monitoring temperature remotely.

Related content:

Categories GSM

27 thoughts on “Wireless Temperature Sensor using GSM and Microcontroller”

  1. Hi;
    how can I use this code with MPlab MCC18 compiler; can you help me because I try to used with C18 compiler I can not succeeded.

    Thanks;

    Reply
  2. hiiiiiiii,,,,
    I am use sim300 gsm module. this module connect with computer through hyper terminal successfully but when it connect with PIC16f877a then there is no response from gsm modem plzzz give solution….
    i am waiting u r valuable reply…….

    Reply
  3. hello. nice piece. i would like to know if the gsm module requires airtime to be in the sim card while it repeatedly sends the data? secondly, i would like to know if it is possible to still send data back to the gsm module and receive data from the pIC . if this is possible, could i get a sample code? i want to constantly receive measurements from the PIC and monitor it on my mobile phone and be able to control some peripherals at will from my mobile phone

    Reply
  4. hey guys i am working on project
    ldr sensor using pic16f877a and gsm sim 900 to send a text to recipient
    im using hi tech as my compiler can someone help me with the code

    Reply
  5. Hello sir..plz sent me complete coding and simulation kindly..i have no time for longtime for my graduation project …kindly sir????

    Reply
  6. may i please get the link where you found those gsm libraries for proeus 7. i cant seem to find them anyyywhere.

    please

    Reply

Leave a Comment