Sunday 13 November 2016

Sending SMS using Atmega16

Hello Friends, in this post we are going to send text sms using atmega16a and Gsm module.
First of all, GSM module is communicated using atmega16a using serial communication.

Stuffs required:

  1. Atmega16a 
  2. GSM module
  3. 12V, 2A dc adapter
  4. Sim card having sms pack
  5. Some jumper wires
Connection:

Make connection like this. 

Atmega16a                              GSM module
Tx              ========>          Rx
Rx              ========>          Tx
Gnd            ========>          Gnd

Simulating it on proteus
Proteus simulation


After making connections, use the following code. 
Note: We are using internal rc oscillator having frequency 8 MHz. The baud rate is 9600.


/*
Code starts here 
*/

#define F_CPU 8000000UL   // 8MHZ crytal frequency 

#include<avr/io.h>
#include<util/delay.h>

void uart_init(uint16_t ubrr_value)
{
   UBRRL = ubrr_value;                         //baud rate selection
   UBRRH = (ubrr_value>>8);                    // baud rate selection
   UCSRC|=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);    // data size of 8 bit
   UCSRB=(1<<RXEN)|(1<<TXEN);        // recieve enable , transmitter enable, interrupt on recieve
}

unsigned char uart_rx()
{
   while(!(UCSRA & (1<<RXC)));
   return UDR;
}

void USART_WriteChar(char data)
{
 UDR=data;
   while(!(UCSRA & (1<<UDRE)));          
_delay_ms(100);
}

void USART_WriteString(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
USART_WriteChar(str[j]);
}
}

 void main()
 {

 int value=0,final=0,value1=0,value2=0;
 float val=0.0;                                                                                                                                                                                                                                                                  
 DDRB=0XFF;
 DDRC=0XFF;
 uart_init(51);
 _delay_ms(20);
 while(1)
 {

USART_WriteString("AT");
_delay_ms(500);

USART_WriteChar('\n\r');
_delay_ms(1500);

USART_WriteString("AT+CMGF=1");
_delay_ms(500);
USART_WriteChar('\n\r');
_delay_ms(1000);

USART_WriteString("AT+CSMP=17,167,0,241");
_delay_ms(500);
USART_WriteChar('\n\r');
_delay_ms(1000);

USART_WriteString("AT+CMGS=");
_delay_ms(500);
USART_WriteChar('"');
_delay_ms(500);
USART_WriteString("+9199xxxxxxxx");
_delay_ms(500);
USART_WriteChar('"');
_delay_ms(500);
USART_WriteChar('\n\r');
_delay_ms(1000);
USART_WriteString("Hello World ..... ");
_delay_ms(2000);

USART_WriteChar(0x1A);

_delay_ms(30000);  // delay of 30 seconds
 }
}

/*
Code ends here 
*/
 Hope you guys had enjoyed the tutorial. In the next post, we will learn about uploading data on thingspeak channel.


No comments:

Post a Comment