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
You are here: Home / Topics / gsm based water pump controller using atmega16

gsm based water pump controller using atmega16

|

Microcontroller › AVR › gsm based water pump controller using atmega16

  • This topic has 7 replies, 3 voices, and was last updated 9 years, 2 months ago by Shashank Rao.C.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • May 24, 2013 at 7:08 am #2435
    Shashank Rao.C
    Participant

    hi every one,

                           I want to do gsm based water pump controller using atmega16 microcontroller. Can anyone tell me how ti interface sim300 with mcu using rs232?

    only simple connection is enough or any handshake or extra signals needed? Please help me for coading

    May 25, 2013 at 4:19 am #9823
    AJISH ALFRED
    Participant

    Hi Shashank,

    You need a RS232 to TTL convereter cable. Connect the TX pin at the TTL end of the cable to RX of MCU and RX of MCU to TX pin of the TTL end of the cable. No need of other pins.

    May 27, 2013 at 5:38 am #9827
    Shashank Rao.C
    Participant

    sir can you give me coding for that? i am very very new to embedde c.

     i got similar coding from efy. i did some changes. but it is for 8051. i am confused that how to covert that for atmega16 please help me…

    coding is as bellow. i am unable to understand that how it works. means how mcu will know that msg has been recived, what it tells and how it will take action….

     

     

    #include<reg51.h>
    sbit rs=P3^7;
    sbit rw=P3^6;
    sbit e=P3^5;
    sbit pump=P1^0;
    void gsmcmdsend(unsigned char *cmd);
    void cmm(char value);
    void dat(char value);
    void compare();
    unsigned char card_id[96];
    unsigned char header[]=”SRC”;
    unsigned char gsm_cmd3[]=”AT&W”;
    unsigned char gsm_cmd4[]=”AT+CMGF”;
    void gsmcmdsend(unsigned char *cmd)        
    {
        unsigned char i;
        for(i=0;*cmd!=’’;i++)
        {
            SBUF=*cmd;
               while(TI==0);
            TI=0;
            cmd++;
            }
            SBUF=0x0A;
            while(TI==0);
            TI=0;
            SBUF=0x0D;
            while(TI==0);
            TI=0;
            while(RI==0);
            RI=0;
    }
    void delay(int count)    //Function to provide delay
    {
        int i,j;
        for(i=0;i<count;i++)
        for(j=0;j<1275;j++);
    }
    void cmm(char value)
    {
        P2 = value;
        rs=0;
        rw=0;
        e=1;
        delay(1);
        e=0;
        delay(1);
        return;
    }
    void dat(char value)
    {
        P2 =value;
        rs=1;
        rw=0;
        e=1;
        delay(1);
        e=0;
        delay(1);
        return;
    }
    void lcdin()
    {    cmm(0x38);
        cmm(0x0e);
        cmm(0x01);
        cmm(0x06);
        cmm(0x85);
        return;
    }
    void recieve()     //Function to recieve data serialy from RS232  
    {
        unsigned char k;
         for(k=0;k<=87;k++)
         {  
             while(RI==0);  
              card_id[k]=SBUF;
              RI=0;
        }
    }
    void main()
    {
        int l,i;
        P1=0x00;
        lcdin();
        TMOD=0x20;            //Enable Timer 1
        TH1=0XFD;
        SCON=0x50;
        TR1=1;
    gsmcmdsend(gsm_cmd3);
    cmm(0x01);
    gsmcmdsend(gsm_cmd4);
    cmm(0x01);
    cmm(0x85);
    for(i=0;i<3;i++)
        {dat(header);}
        cmm(0xc0);
    while(1)
           {
             recieve();
             for(l=83;l<=87;l++)
             {  
                  dat(card_id[l]);
             }          
             compare();
        }
    }
    void compare()
    {                                                    
    if ((card_id[83]==’p’)&&(card_id[84]==’u’) && (card_id[85]==’m’) && (card_id[86]==’p’) && (card_id[87]==’o’)&&(card_id[88]==’n’))
        pump=1;
    else if((card_id[83]==’p’)&&(card_id[84]==’u’) && (card_id[85]==’m’) && (card_id[86]==’p’) && (card_id[87]==’o’)&&(card_id[88]==’f’))  
        pump=0;
    ;
    }
     
    end;                        //end of program 

    June 4, 2013 at 2:17 pm #9889
    nkonnect
    Participant

    hello as you have mentioned that you want particular information but firstly you have to decide that which type of pump controller system you want to develope and till how much costing you want to gone??

     

    June 4, 2013 at 3:53 pm #9890
    Shashank Rao.C
    Participant

    I want to control about 1-1.5Hp pump. Actually i need only coding for ATmega16. Hardware i can build. I want make pump on an off. Also when pump is on and off i shoul send me a msg that pump is on/off. I am using sim300 module for gsm.

    June 5, 2013 at 12:44 pm #9895
    nkonnect
    Participant

    ok i understand your problem, but tell me more functionality you want in gsm pump controller system that you are developing right now.so i can help you better for that.

    June 5, 2013 at 1:25 pm #9896
    Shashank Rao.C
    Participant

    my idea is when i send a message as MTR ON pump should run and i should get a message as MOTER IS ON. when i send MTR OFF pump should turn off and i should get a message as MOTER IS OFF. system should have a LCD interface and it should display MOTER ON when pump is on. And it should display MOTER IS OFF when its off.

    any how rx and tx of rs232 is connected to tx and rx of mcu. port a is connected to lcd in 8 bit manner.

    June 6, 2013 at 10:13 am #9898
    Shashank Rao.C
    Participant

    Hi NK,

                 I have written a code for this purpose. Actually these code were collected and rearrange from this site only. I have done small changes.

     

    i have not tried this. can you please check this? Please tell me any any modifications are needed or not.

     

     

    #define F_CPU 12000000UL      // set CPU freq.
    #define USART_BAUDRATE 9600
    #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
    #include<avr/io.h>
    #include<util/delay.h>

    #define LCD_DATA PORTA    // LCD DATA PORT.
    #define  ctrl PORTB       // CONTROL PORT FOR LCD.
    #define en PB2            // ENABLE SINGNAL FOR LCD.
    #define rw PB1            // READ/WRITE SIGNAL FOR LCD.
    #define rs PB0            // REGISTER SELECTION SIGNAL FOR LCD.
    #define MOTOR_CONTROL PORTC // MOTOR CONTROL PORT.

    void LCD_cmd(unsigned char cmd);
    void init_LCD(void);
    void LCD_write(unsigned char data);

    void usart_init();
    void usart_putch(unsigned char send);
    unsigned int usart_getch();
    void compare_string();

    unsigned int final_result;
    unsigned char msg[] = “”;
    unsigned char on[]=”MTR ON”;
    unsigned char off[]=”MTR OFF”;

    int main(void);
    {
    while(1)
    {
    uart_init();                    // initialize UART port.

    usart_message(“ATrn”);          // Sent AT into USART.
    _delay_ms(10000);
    usart_message(“AT+CMGF=1rn”);   //Select mesage mode in text mode.
    _delay_ms(1000);
    usart_message(“AT+CPMS=’SM’rn”); // Select the mesage memory.
    _delay_ms(1000);
    usart_message(“AT+CMGR=1rn”);   // Read the message from index 1.
    usart_getch(msg[]);
    compare_string();
    final_result=fresult;
    if(final_result==0)
    {
    PORTC=0x01;
            usart_message(“ATrn”);          // Sent AT into USART.
           _delay_ms(10000);
            usart_message(“AT+CMGF=1rn”);   //Select mesage mode in text mode.
           _delay_ms(1000);
            usart_message(“AT+CPMS=’SM’rn”); // Select the mesage memory.
           _delay_ms(1000);
            usart_message(“AT+CMGS=+918197103408rn”);   // SEND the message.
            usart_message(“MOTER IS ON.”);
            init_LCD();
            LCD_write(“MOTOR IS ON.”);
             }
    if(final_result==1)
    {
    PORTC=0x00;
            usart_message(“ATrn”);          // Sent AT into USART.
           _delay_ms(10000);
            usart_message(“AT+CMGF=1rn”);   //Select mesage mode in text mode.
           _delay_ms(1000);
            usart_message(“AT+CPMS=’SM’rn”); // Select the mesage memory.
           _delay_ms(1000);
            usart_message(“AT+CMGS=+918197103408rn”);   // SEND the message.
            usart_message(“MOTER IS OFF.”);
            init_LCD();
            LCD_write(“MOTER IS OFF.”);
             }
    }
    }

    LCD_write(“MOTER IS OFF.”);
    void init_LCD(void)              //Function to initialize LCD.
    {
    LCD_cmd(0x38);
    mode
    _delay_ms(1);
    // initialization of 16X2 LCD in 8bit
    LCD_cmd(0x01); // clear LCD
    _delay_ms(1);
    LCD_cmd(0x0E); // cursor ON
    _delay_ms(1);
    LCD_cmd(0x80);
    0th position
    _delay_ms(1);
    return;
    }

    void LCD_cmd(unsigned char cmd)           //Function to LCD command.
    {
    LCD_DATA=cmd;
    ctrl =(0<<rs)|(0<<rw)|(1<<en);
    _delay_ms(1);
    ctrl =(0<<rs)|(0<<rw)|(0<<en);
    _delay_ms(50);
    return;
    }

    void LCD_write(unsigned char data)            //Function to write a letter in LCD.
    {
    LCD_DATA= data;
    ctrl = (1<<rs)|(0<<rw)|(1<<en);
    _delay_ms(1);
    ctrl = (1<<rs)|(0<<rw)|(0<<en);
    _delay_ms(50);
    return ;
    }

    void LCD_write_string(unsigned char *str)         //Function to write a string in LCD.
    value of the string in pointer *str
    {
    int i=0;
    while(str!=’’)
    go on till the NULL character in the string
    {
    LCD_write(str
    );
    sending data on LCD byte by byte
    i++;
    }
    return;

    void usart_init()                                // Function to initialize USART.
    {
    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
    UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate
    value..
    // into the low byte of
    the UBRR register
    UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the
    baud rate value..
    // into
    the high byte of the UBRR register
    }

    void usart_message(unsigned char *var) // transmits ASCII string
    {
    int h;
    while(*var)
    usart_putch(*var++);
    for(h=0;h<=200;h++); //sends characters one by one till string ends
    }

    unsigned int usart_getch()
    {
    while ((UCSRA & (1 << RXC)) == 0);
    // Do nothing until data have been
    received and is ready to be read from UDR
    return(UDR); // return the byte
    }

     
    int compare_string();              // Function to string comparition.
    {
     
    {
        char on[],off[], msg[], result,fresult;
     
        
        result = compare_string1(on, msg);
         if(result==0)
         {
         fresult=1;
         return fresult;
         }

         result = compare_string2(off,msg);

        if ( result == 0 )
          {
              fresult=0;
              return fresult;
          }
    }
            
       
     
    int compare_string1(char *on, char *msg)
    {
       while(*on==*msg)
       {
          if ( *on == ‘’ || *msg == ‘’ )
             break;
     
          on++;
          msg++;
       }
       if( *on == ‘’ && *msg == ‘’ )
          return 0;
       else
          return -1;
    }

    int compare_string2(char *off, char *msg)
    {
       while(*off==*msg)
       {
          if ( *off == ‘’ || *msg == ‘’ )
             break;
     
          off++;
          msg++;
       }
       if( *off == ‘’ && *msg == ‘’ )
          return 0;
       else
          return -1;
    }
    }

     

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

RSS Recent Posts

  • question about speaker crossover August 19, 2022
  • How does a transistor works as a switch? August 19, 2022
  • Designspark PCB V10.0 on Windows 11 - fails to start August 19, 2022
  • Pedestal fan August 19, 2022
  • Peltier control August 19, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2022 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