[PIC] Monitor Temperature value using SMS nokia 6300 and PIC16f877a

Status
Not open for further replies.

Mahmoud Abuzayed

Newbie level 3
Joined
Jan 4, 2014
Messages
4
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Visit site
Activity points
54
Hello... I made temperature sensor using pic16f877a. NOW i want to send this reading using sms...
i want when i send for example "Temperature" to the phone connected to the pic it responds to me as message "Temperature is: 20°" i mean sms communication and i guess it is done by fbus and AT commands, my problem i cannot write the full source code i face problems... can you help me
I want to use Nokia 6300 by connecting(Rx to D+ and Tx to D-) of the usb cable connected to the phone.
Here is my code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
 
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
        
int temp;
char text1[]="Temperature= ";
char txt[17];
char terminator=0x1A;
//  AT commands initialization
const char atc0[] = "AT";                        // Every AT command starts with "AT"
const char atc1[] = "ATE0";                      // Disable command echo
const char atc2[] = "AT+CMGF=1";                 // TXT messages
const char atc3[] = "AT+CMGS=\"+972597233195";    // Send message to cell number : 0123456789 (Enter your cell phone number instead of 0123456789)
const char atc4[] = "AT+CMGR=1";                 // Command for reading message from location 1 from inbox
const char atc5[] = "AT+CMGD=1,4";               // Erasing all messages from inbox
 
// temperature measurment function
void Read_temp (void)
{
     temp = ADC_Read(0);
     temp = temp*0.4887;
     IntToStr(temp,txt);
     Lcd_Out(1,1,text1);
     Lcd_Out(1,13,Ltrim(txt));
     Lcd_Chr_Cp(0xdf);
     Lcd_Chr_Cp('C');
     Lcd_Chr_Cp(' ');
 }
void send_sms ()
{
                 UART1_Write_Text("AT");
                 UART1_Write(13); //Enter
                 UART1_Write(10) ;  // CTRL+Z
                 UART1_Write_Text("AT+CMGF=1");
                 UART1_Write(13);
                 UART1_Write(10) ;
                 Delay_ms(2000);
                 UART1_Write_Text("AT+CMGS=");
                 UART1_Write(34);
                 UART1_Write_Text("+972597233195");
                 Delay_ms(100);
                 UART1_Write(34);
                 UART1_Write(13);
                 UART1_Write(10) ;
                 Delay_ms(1000);
                 UART1_Write_Text("Teperature is: ");
                 UART1_Write_Text(temp);  // temperature sending
                 UART1_Write_Text('C');
                 UART1_Write_Text(0x6F); 
                 UART1_Write(13);//Enter
                 UART1_Write(26);
                 UART1_Write(13);
          }
 
        
void read_sms()
{
char uart_rd;
 
if (UART1_Data_Ready())       // If data is received,
     {
         uart_rd = UART1_Read();     // read the received data,
         if(strcmp(uart_rd,"Temperature")==0)
         {
         send_sms ();
         }
         }
         }
 
void main() 
{ 
  ADC_Init();
  UART1_Init(9600);      // Initialize hardware UART1 and establish communication at 9600 bps
  Delay_ms(100);        // Wait for UART module to stabilize
  ADCON1 = 0b00001110; // Analog channel select @ AN0
  TRISA=0b00000001;
  trisc=0;
  portc=0;
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
                            
 
  while(1)
  {
    Read_temp();
    delay_ms(100);
    read_sms();
    delay_ms(1000);
  }
}



Here is proteus:
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…