EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / By using GSM SIM 300M and Atmega8 , How to write coding for sending SMS to 3 Persons when any one the port pin gets high …?

By using GSM SIM 300M and Atmega8 , How to write coding for sending SMS to 3 Persons when any one the port pin gets high …?

|

Microcontroller › AVR › By using GSM SIM 300M and Atmega8 , How to write coding for sending SMS to 3 Persons when any one the port pin gets high …?

  • This topic has 18 replies, 4 voices, and was last updated 12 years, 2 months ago by rajesh.
Viewing 15 posts - 1 through 15 (of 19 total)
1 2 →
  • Author
    Posts
  • November 1, 2012 at 6:03 am #1990
    5HUJ4
    Participant

    Hi Guys Good to be here , i need ur lil help….

     

    Can any body plzzzzzz send me the code for sending SMS  to 3 Persons using GSM SIM 300M Module when one of the port pin of Atmega8 Microcontroller gets high …?

     

    Eagerly waiting for ur replies ….

     

    Thank u …..

    November 2, 2012 at 6:05 am #8709
    AJISH ALFRED
    Participant

    Hi,

    Learn about GSM interfacing from engineers garage itself.

    /embedded/pic-microcontroller-projects/interface-gsm-module-call-message-circuit

     

    Now all you’ve to do is yo wait till a pin goes high before executing the message sending code.

     

    void main ()

    {

            while (1)

            {

                   while (PIN==0);                   //program will loop in this line itself only until the pin become logic high

     

                  /********************

                  Your message sending code

                  ********************/

            }

    }

     

    I hope this helps.

    November 3, 2012 at 5:26 am #8713
    AJISH ALFRED
    Participant

    You forget to initialize the port B. Port B should be set as input port.

    Define the following function and call it from the main() before “while ( PIN == 0 );”

     

    void init_Ports(void)
    {
    CLI(); //disable all interrupts
    DDRB = 0x00; //port B as input
    SEI(); //reanable all interrupts
    }

     

    On reset condition I think the ports are input by default, but try this too and update the result.

     

    Also tell me how are you giving a logic high to PB0 pin, I mean the circuit connected to PB0 pin.

    November 3, 2012 at 6:38 am #8714
    5HUJ4
    Participant

    Have a look at dis modified code , But still i have’nt received any SMS yet …

     

    Circuit Description :

    1)AVR Atmega8

    2)12Mhz Crystal Oscillator , Considering Bard rate =9600 , and UBRRL = 0x0077;

    3)Input to the PB0 pin , for an instance is directly given from the Vcc=5V as pulse for certain duration

    4)SIM 300M Module is used .

    5)”Requirement is just to  send the SMS to 1 persons , when PB0 pin gets high …..

    Plz suggest me any further modification ,eager waiting for ur reply ……..

     

    #include <avr/io.h>
    #include <util/delay.h>
    #include <avr/interrupt.h>
    #define F_CPU 12000000UL
    #define USART_BAUDRATE 9600 // Baud Rate value
    #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
    #define PIN PB0
    void usart_putstr(char * s);
    void usart_init();
    static void usart_putch(unsigned char send);
    unsigned int usart_getch();
    void init_Ports(void);

    int main ()
    {
    DDRD|=0xFC;//Setting the Tx and Rx Pins Low
    DDRB =0x00;//Setting the PortB as input port  
       while (1)
       {
       init_Ports();
       while (PIN==0); //program will loop in this line itself only until the pin become logic high
        
          usart_init(); // initialization of USART
          char b[] = “AT+CMGS=”;
          char no[]=”+918000000000″;
          char body[] =”Got the Output”; 
        {
         usart_putstr(b);
         _delay_ms(100);
         usart_putch(‘”‘);
         usart_putstr(no);
         _delay_ms(100);
         usart_putch(‘”‘);
         _delay_ms(100);
         usart_putch(‘r’);
         usart_putch(‘n’);
         _delay_ms(100);
         usart_putstr(body);
         _delay_ms(100);
         usart_putch(0x1A);
        }
        return 0;
     
       }
    }

    void usart_init()
        {
        UBRRL = 0x0077;
        _delay_ms(1);
        UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
        UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
        }
     
    unsigned int usart_getch()
        {
        while (!(UCSRA & (1 << RXC)) ); // Do nothing until data has been received and is ready to be read from UDR
        _delay_ms(1);
        return(UDR); // return the byte
        }
     

    static void usart_putch(unsigned char send)
        {
     
        while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
        // for more data to be written to it
        UDR = send; // Send the byte
        }
     

    void usart_putstr(char * s)
        {
          while(*s)
              {
                usart_putch(*s++);
              }
        }

    void init_Ports(void)
      {
        cli();                    //disable all interrupts
        DDRB = 0x00;   //port B as input
        sei();                   //reanable all interrupts
       }

     

     

     

     

     

     

     

    November 4, 2012 at 4:52 pm #8716
    AJISH ALFRED
    Participant

    have you checked the modem with hyperterminal, manually typing the code? connect your board with the hyperterminal and check whether your are getting the exactly same code displayed on the hyperterminal, when the pin become high.

    November 5, 2012 at 9:31 am #8718
    5HUJ4
    Participant

    yes i have checked the modem with hyperterminal, manually by  typing following code …

     

      AT+CMGF=1  response “OK” was returned.

      AT+CMGS=”9030888888″.  response “>” was returned.

      Then I typed my message, after that I Pressed Cltr+Z to send the message and it was sucessfull 

    But when i have dumped the code into Microcontroller then its not sending SMS ….!!!

     

    Can u plz suggest any further modification ……waiting for ur reply ….

    November 5, 2012 at 1:22 pm #8719
    5HUJ4
    Participant

    Finally i have changed my controller .This time i am using 89s52 with [email protected] .I have compiled the below code sucessfully and checked the output on Keil UART terminal window . But when i have dumped the same code into the controller its not sending any SMS …….. Plz suggest me any solution …..waiting fot ur reply ….!!!

     

    #include<at89x52.h>
    #define key P2^0
    void delay(int time);
    void init();
    void SMSString(unsigned char* text);
    void tx0(unsigned char x);
    void main()
    {
       P2=0x00;
       init();
       while(1)
    {
    if(key==1)
    {
      SMSString(“ATr”);
      delay(1000);
      delay(1000);
     
      SMSString(“AT+CMGF=1r”);
      delay(1000);
      delay(1000);

      SMSString(“AT+CMGS=”8080808080″r”);
      delay(1000);
     
      SMSString(“This is a test messag “);
      delay(1000);
      tx0(0x1A);
      delay(1000);
      delay(1000);
      delay(1000);
    }
    }
    }

    void delay(int time)        //This function produces a delay in msec.
    {
        int i,j;
        for(i=0;i<time;i++)
        for(j=0;j<1000;j++);
    }

    void init()
    {
      TMOD=0x20;
      SCON=0x50;
      TL1=0XFD; //9600 @ 11.0592
      TH1=0xFD;
      TR1=1;
    }

    void SMSString(unsigned char* text) //function to send SMS using GSM modem
    {
      unsigned char count = 0;
      while (text[count])
    {
     tx0(text[count++]);
    }
    }

    void tx0(unsigned char x) //send data to serial port 0
    {
     EA=0;
     SBUF=x;
     while(TI==0);
     TI=0;
     EA=1;
    }

     

     

    Important Note :From the GSM module i have removed Max 232 and using its 11 pin as TX and 12 pin as Rx pin  , conncting directly to the microcontroller in Cross fasion ( i mean  Tx 2 Rx and Rx to Tx and Gnd 2 Gnd )

     

     

     

     

    November 5, 2012 at 2:34 pm #8720
    AJISH ALFRED
    Participant

    Hi,

    Ok, you’ve typed the commands on hyperterminal manually and the modem sends sms. That means the modem is working.

    Now you must check whether your code is working; remove the gsm modem and connect your controller to the hyperterminal, and see whether the controller is sending the same command to the hyperterminal.

    If you can see the exactly same commands on the hyperterminal which you’ve manually typed previously, then your code is also working, otherwise some hardware issues.

    In embedded system knowing whether the problem is in hardware or software is the first step in debugging!

    November 6, 2012 at 6:27 am #8722
    5HUJ4
    Participant

    I have removed the GSM modem and connected  controller to the hyperterminal ….. But agian no output  now only problem left is with the coding ……..Waiting for ur reply ..!!

     

     

    November 6, 2012 at 9:56 am #8711
    5HUJ4
    Participant

     

     

    //Thanks ‘Ajish Alfred’  for ur suggestion .Here is the exact code which i have modified to, but still i am not gettting SMS . Plz can u find out the problrm and suggest me the correct coding ………. i am really ineed of it  : (

     

    //Eagerly Waiting for ur reply …………..!!

     

    #include<avr/io.h>
    #include<util/delay.h>
    #define F_CPU 12000000UL
    #define USART_BAUDRATE 9600 // Baud Rate value
    #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
    #define PIN PB0
    void usart_putstr(char * s);
    void usart_init();
    static void usart_putch(unsigned char send);
    unsigned int usart_getch();

    int main ()

    {
    DDRD|=0xFC;//Setting the Tx and Rx Pins Low
       while (1)
       {
       while (PIN==0); //program will loop in this line itself only until the pin become logic high
        
          usart_init(); // initialization of USART
          char b[] = “AT+CMGS=”;
          char no[]=”+918000000000″;
          char body[] =”Got the Output”; 
        {
         usart_putstr(b);
         _delay_ms(100);
         usart_putch(‘”‘);
         usart_putstr(no);
         _delay_ms(100);
         usart_putch(‘”‘);
         _delay_ms(100);
         usart_putch(‘r’);
         usart_putch(‘n’);
         _delay_ms(100);
         usart_putstr(body);
         _delay_ms(100);
         usart_putch(0x1A);
        }
        return 0;
     
       }
    }

    void usart_init()
        {
        UBRRL = 0x47;
        _delay_ms(1);
        UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
        UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
        }
     
    unsigned int usart_getch()
        {
        while (!(UCSRA & (1 << RXC)) ); // Do nothing until data has been received and is ready to be read from UDR
        _delay_ms(1);
        return(UDR); // return the byte
        }
     

    static void usart_putch(unsigned char send)
        {
     
        while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
        // for more data to be written to it
        UDR = send; // Send the byte
        }
     

    void usart_putstr(char * s)
        {
          while(*s)
              {
                usart_putch(*s++);
              }
        }

    November 8, 2012 at 6:18 pm #8728
    AJISH ALFRED
    Participant

     

     

    Sorry for the delayed response. I hope your init() function is setting things properly. Now try exactly the following code with the hyperterminal and tell me whether it displays something on the terminal window.

     

     

    #include<at89x52.h>
    #define key P2^0
    void delay(int time);
    void init();
    void SMSString(unsigned char* text);
    void tx0(unsigned char x);
    void main()
    {
       P2=0x00;
       init();
     

      tx0 (‘h’);

      tx0 (‘a’);

      tx0 (‘i’);

      SMSString(“ATr”);
      delay(1000);
      delay(1000);
     
      SMSString(“AT+CMGF=1r”);
      delay(1000);
      delay(1000);

      SMSString(“AT+CMGS=”8080808080″r”);
      delay(1000);
     
      SMSString(“This is a test messag “);
      delay(1000);
      tx0(0x1A);
      delay(1000);
      delay(1000);
      delay(1000);

     

      while ( 1 )

     {

         ;

      }

    }

    void delay(int time)        //This function produces a delay in msec.
    {
        int i,j;
        for(i=0;i<time;i++)
        for(j=0;j<1000;j++);
    }

    void init()
    {
      TMOD=0x20;
      SCON=0x50;
      TL1=0XFD; //9600 @ 11.0592
      TH1=0xFD;
      TR1=1;
    }

    void SMSString(unsigned char* text) //function to send SMS using GSM modem
    {
      unsigned char count = 0;
      while (text[count])
    {
     tx0(text[count++]);
    }
    }

    void tx0(unsigned char x) //send data to serial port 0
    {
     EA=0;
     SBUF=x;
     while(TI==0);
     TI=0;
     EA=1;
    }

    November 10, 2012 at 4:38 am #8730
    5HUJ4
    Participant

    Finally i got the output using 89C51 MC …….Ajish Alfre thanks for ur kind support , See u again ….Buy

    November 10, 2012 at 11:52 am #8731
    AJISH ALFRED
    Participant

    Thats great. See you, bye.

    November 30, 2012 at 6:01 am #8799
    5HUJ4
    Participant

    Hi Alfred …..im back again

    i have got the sucessful out put for sending Text Message  to different persons through GSM SIM300.Next i want to Send Voice Message from this SIM300 to the Mobile Phone .

    For this i have considered “APR9600 Voice recording/playback IC”,Firstly i will record some predefine voice into it,then i will connect it’s output to the MIC input of the SIM300.

    Further when i will give voice call to the user ,when it pickups the phone ,i ll play dis audio mesage …..

    For this entire setup i have made one interfacing circuit ,i want ur lil help to know its correct or not …….wysiwyg_imageupload:6839:height=317,width=504

    December 1, 2012 at 5:22 pm #8802
    AJISH ALFRED
    Participant

    Hi glad to see you again

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 19 total)
1 2 →
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Wish to buy Battery, Charger and Buck converter for 12V , 2A router May 13, 2025
  • Need Help Figuring Out the Schematics Of Circuit Board May 13, 2025
  • applying solder paste from a jar May 12, 2025
  • Question i-nears headphones magnetic drivers May 12, 2025
  • An Update On Tarrifs May 12, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise