Wireless temperature sensor using gsm and microcontroller




Wireless temperature sensor using gsm and microcontroller is designed to measure temperature from remote location and then send it to any where you want on your mobile through SIM900D gsm module.PIC16F877A microcontroller is used to measure temperature from LM35 temperature sensor and then microcontroller is interfaced with SIM900D gsm module to send temperature through sms to a recipient. You can also also use more than one sensors to measure other physical parameters from remote location and then send them to any number you want.




I have already posted articles on digital temperature sensor using pic microcontroller and how to send sms using gsm module and pic microcontroller. I recommend you to 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 pic microcontroller and lm35 sensor and how to send sms using gsm and pic microcontroller. I have just combined coding and circuit diagram of those two articles.Circuit Diagram of wireless temperature sensor using pic microcontroller is shown below :

wireless temperature sensor using gsm
wireless temperature sensor using gsm

In above circuit diagram temperature sensor can be located at remote location and you can connect more than one sensor like light sensor, motion sensor ,pressure sensor according to requirement of your project. Lcd is use optional. Gsm module is used to send sms to any mobile number.you can also use other wire less communication source like Bluetooth if distance is not more than 5 meter.This project have many applications in remote monitoring systems.you can change it with ease according to your specifications.




 Components list

The following bill of material doesn't include power supply components for 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

 

Coding

Following code is written in MIKRO C and it is self explantory. I have also give comment on each line of code for your understanding.

// *****************written by [email protected]***************
//****You can also email me to fire me for your project/organzation**
// 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 funtion*************************************
void READ_temp(void)
{
temp = ADC_Read(0);
temp = temp * 0.4887;

}
void data_converstion(void)
{

inttostr(temp,txt);
}
void display(void)
{
lcd_out(1,1,”TEMPERATURE=”);
lcd_out(1,13, Ltrim(txt));
Lcd_Chr_Cp(0xdf);
Lcd_Chr_Cp(‘C’);
Lcd_Chr_Cp(‘ ‘);

}
//********************String transmit function****************
void send_to_modem(char *s)
{
while(*s)
{
UART1_WRITE(*s++);
}
UART1_WRITE(0X0D);
}
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_converstion();
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(); // funtion to send temperature value
delay_ms(10000); // send sms afer every 10 seconds
}
}
Above code send temperature value to given number after every 10 seconds. you can also make this code more flexible by adding interrupts instead of adding delay function so that microcontroller keep doing other things if you are using same microcontroller for other application as well.Below is a circuit diagram to test either microcntroller is sending data or not.I have test this code on many gsm modules and its work perfectly.

wireless temperature sensor
wireless temperature sensor

If you have any issue after reading this article, you are welcome to comment your problems on this post. Also subscribe to my blog to get updates of my upcoming articles in your inbox.



25 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;

  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…….

  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

  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

  5. Hello sir..plz sent me complete coding and simulation kindly..i have no time for longtime for my graduation project …kindly sir­čśö

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

    please

Leave a Comment