gsm_voting_feature_image

SMS Based Voting System – AVR GSM Project

Line Following Robot Kit

If you want a live demo of this, please register from the link given below. (Only in Pune)
REGISTER NOW!

This project can also be implemented using a PIC18F4520 microcontroller.

Hi friends !

Here I am showing a microcontroller based project called the "GSM Based Voting System". Using this system you can ask your users to vote for any of the four options. Four available options are identified by a letters ‘A’, ‘B’, ‘C’ and ‘D’. User can vote for any option by sending a text message to the mobile number.

For example if you want to create a poll like this.

Which is your favorite phone brand?

A: Nokia

B: Apple

C: Samsung

D: L.G.

So your user can vote for any of the four brands by sending a message like this

VOTE x

where x is the choice he/she wish to vote for. For example if they want to vote for Nokia, then they should send a message like this :

VOTE A

The number of vote received for each option is shown in real time on the LCD Module. The votes are stored in the internal EEPROM of the AVR so they are not lost on power failures. That means even if you switch off the device and switch it on after few days (or few years!) it will remember the votes !

sms based voting system using avr microcontroller

Fig. SMS Based Voting System

 

showing vote counts for each option

Fig. Vote Count Display

 

GSM Based Voting Project Demo

Fig. Voting Success !

 

avr project

Fig. Reply for Correct and Incorrect Votes.

Things Required and Estimate Cost


S. No. Item Image Cost
1

xBoard v2.0

Contains the core AVR circuit including 5v regulator, reset, ISP. It also includes easy interface for 2×16 character LCD.

xBoard - AVR ATmega32 Dev Board
Rs.1264
2

GSM-GPRS Modem SIM300 KIT

For getting connected to the GSM Network.

gsm module sim300
Rs.1699
3

Single Pin Female to Female Burg Wires

Used to interconnect the two boards.

 

Burg Wires
Rs. 50
4

USB AVR Programmer

To upload the program to the development board.

USB AVR Programmer
Rs. 489
5

12V DC Adapter-2A-SMPS

To power up xBoard v2.0 and the GSM Module. You need two of these.

12v dc adaptor
Rs. 360
    TOTAL
Rs. 3862
  • Also required is a working SIM card with available balance.
  • And a working mobile phone to send a testing vote to the system.

Schematic for the Project

The project is based around AVR ATmega32 microcontroller which is connected to a 16×2 LCD Module and a SIM300 GSM Module. We have used xBoard 2.0 development board to accelerate our development process. It is a ready made ATmega32 board with built in 16×2 LCD Module and many other common peripherals. So if you are working with xBoard 2.0 then you only need to connect the GSM Module. It involves connecting only three wires!

atmega32 gsm module connection

Fig. SIM300 and ATmega32 Schematic

We have made the prototype using xBoard development board because it has ATmega32 core circuit, 5v power supply circuit and the LCD module.

avr gsm module interface

Fig. SIM300 and ATmega32 Connection

 

xboard sim300 connection

Fig. SIM300′s PINs

 

xboard's usart pins

Fig. xBoard’s USART PINs

 

 

 

avr gsm module program

Fig. GSM Module connected with ATmega32

 

After completing the connection, power up xBoard 2.0 using a 12v 500 ma DC adaptor. And program the board with the HEX file for the project(download available at the end of article). Then insert a SIM card in SIM300 module and power it up using a 12v 2A DC Adaptor. Restart the xBoard 2.0 using its reset button.

Here are some links for your help.

NOTE

The board shown below is the new version of SIM300 Modem, it can also be used to make this project. New version is much smaller and low cost.

sim300 module new version

Fig. SIM300 Module New Version

 

Source Code for the Project


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

SMS Based Voting System.

                                     NOTICE
                           --------
NO PART OF THIS WORK CAN BE COPIED, DISTRIBUTED OR PUBLISHED WITHOUT A
WRITTEN PERMISSION FROM EXTREME ELECTRONICS INDIA. THE LIBRARY, NOR ANY PART
OF IT CAN BE USED IN COMMERCIAL APPLICATIONS. IT IS INTENDED TO BE USED FOR
HOBBY, LEARNING AND EDUCATIONAL PURPOSE ONLY. IF YOU WANT TO USE THEM IN 
COMMERCIAL APPLICATION PLEASE WRITE TO THE AUTHOR.

Change Log

21 Dec 2012 -  Added EEPROM Initialization on first boot, added function 
            SIM300SetTextMode()


WRITTEN BY:
AVINASH GUPTA
me@avinashgupta.com

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


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

#include <string.h>

#include "lib/lcd/lcd.h"
#include "lib/sim300/sim300.h"
#include "lib/usart/usart.h"



void Halt();
void Reply(const char *num,uint8_t stat);

int main(void)
{
   //Initialize LCD Module
   LCDInit(LS_NONE);

   //Intro Message
   LCDWriteString("Msg Based Voting");
   LCDWriteStringXY(0,1,"By Avinash Gupta");

   _delay_ms(1000);

   LCDClear();


   //Initialize SIM300 module
   LCDWriteString("Initializing ...");
   int8_t r= SIM300Init();

   _delay_ms(1000);

   //Check the status of initialization
   switch(r)
   {
      case SIM300_OK:
         LCDWriteStringXY(0,1,"OK !");
         break;
      case SIM300_TIMEOUT:
         LCDWriteStringXY(0,1,"No response");
         Halt();
      case SIM300_INVALID_RESPONSE:
         LCDWriteStringXY(0,1,"Inv response");
         Halt();
      case SIM300_FAIL:
         LCDWriteStringXY(0,1,"Fail");
         Halt();
      default:
         LCDWriteStringXY(0,1,"Unknown Error");
         Halt();
   }

   _delay_ms(1000);

   //Set message format to text
   r= SIM300SetTextMode();

   LCDClear();
   LCDWriteString("Set Text Mode ..");

   _delay_ms(1000);

   //Check the result of above operation
   switch(r)
   {
      case SIM300_OK:
      LCDWriteStringXY(0,1,"OK !");
      break;

      case SIM300_TIMEOUT:
      LCDWriteStringXY(0,1,"No response");
      Halt();

      case SIM300_FAIL:
      LCDWriteStringXY(0,1,"Fail");
      Halt();

      default:
      LCDWriteStringXY(0,1,"Unknown Error");
      Halt();
   }

   _delay_ms(1000);

   //IMEI No display
   LCDClear();

   char imei[16];

   r=SIM300GetIMEI(imei);

   if(r==SIM300_TIMEOUT)
   {
      LCDWriteString("Comm Error !");
      Halt();
   }

   LCDWriteString("Device IMEI:");
   LCDWriteStringXY(0,1,imei);


   _delay_ms(1000);

   //Manufacturer ID
   LCDClear();

   char man_id[48];

   r=SIM300GetManufacturer(man_id);

   if(r==SIM300_TIMEOUT)
   {
      LCDWriteString("Comm Error !");
      Halt();
   }

   LCDWriteString("Manufacturer:");
   LCDWriteStringXY(0,1,man_id);

   _delay_ms(1000);

   //Manufacturer ID
   LCDClear();

   char model[48];

   r=SIM300GetModel(model);

   if(r==SIM300_TIMEOUT)
   {
      LCDWriteString("Comm Error !");
      Halt();
   }

   LCDWriteString("Model:");
   LCDWriteStringXY(0,1,model);

   _delay_ms(1000);



   //Check Sim Card Presence
   LCDClear();
   LCDWriteString("Checking SIMCard");

   _delay_ms(1000);

   r=SIM300IsSIMInserted();

   if (r==SIM300_SIM_NOT_PRESENT)
   {
      //Sim card is NOT present
      LCDWriteStringXY(0,1,"No SIM Card !");

      Halt();
   }
   else if(r==SIM300_TIMEOUT)
   {
      //Communication Error
      LCDWriteStringXY(0,1,"Comm Error !");

      Halt();
   }
   else if(r==SIM300_SIM_PRESENT)
   {
      //Sim card present
      LCDWriteStringXY(0,1,"SIM Card Present");

      _delay_ms(1000);
   }

   //Network search
   LCDClear();
   LCDWriteStringXY(0,0,"SearchingNetwork");

   uint8_t     nw_found=0;
   uint16_t tries=0;
   uint8_t     x=0;

   while(!nw_found)
   {
      r=SIM300GetNetStat();

      if(r==SIM300_NW_SEARCHING)
      {
         LCDWriteStringXY(0,1,"%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0");
         LCDWriteStringXY(x,1,"%1");
         LCDGotoXY(17,1);

         x++;

         if(x==16) x=0;

         _delay_ms(50);

         tries++;

         if(tries==600)
            break;
      }
      else
         break;

   }
   LCDClear();

   if(r==SIM300_NW_REGISTERED_HOME)
   {
      LCDWriteString("Network Found");
   }
   else
   {
      LCDWriteString("Cant Connt to NW!");
      Halt();
   }

   _delay_ms(1000);

   LCDClear();

   //Show Provider Name
   char pname[32];
   r=SIM300GetProviderName(pname);

   if(r==0)
   {
      LCDWriteString("Comm Error !");
      Halt();
   }

   LCDWriteString(pname);

   _delay_ms(1000);

   //Voting system
   uint16_t votes[4];

   votes[0]=eeprom_read_word((const uint16_t *)0);
   votes[1]=eeprom_read_word((const uint16_t *)2);
   votes[2]=eeprom_read_word((const uint16_t *)4);
   votes[3]=eeprom_read_word((const uint16_t *)6);

   if(votes[0]==0xFFFF)
   {
      //No valid data on eeprom, so set all votes to 0
      votes[0]=votes[1]=votes[2]=votes[3]=0;

      //Clear EEPROM too
      eeprom_write_word((uint16_t *)0,0);
      eeprom_write_word((uint16_t *)2,0);
      eeprom_write_word((uint16_t *)4,0);
      eeprom_write_word((uint16_t *)6,0);


   }

   //Wait for MSG
   uint8_t id;
   char oa[20];//Origin Address ()the number from where the msg came

   UFlushBuffer();

   while(1)
   {
      LCDClear();

      uint8_t x=0;

      LCDWriteStringXY(0,0,"A=     B=");
      LCDWriteStringXY(0,1,"C=     D=");

      LCDWriteIntXY(2,0,votes[0],4);
      LCDWriteIntXY(9,0,votes[1],4);
      LCDWriteIntXY(2,1,votes[2],4);
      LCDWriteIntXY(9,1,votes[3],4);

      while(SIM300WaitForMsg(&id)!=SIM300_OK)
      {
         if(x)
         {
            LCDWriteStringXY(15,0,"%3");
            x=0;
         }
         else
         {
            LCDWriteStringXY(15,0,"%4");
            x=1;
         }
      }

      LCDWriteStringXY(15,0,"%2");

      _delay_ms(1000);

      //Now read the msg
      char msg[300];

      r=SIM300ReadMsg(id,msg,oa);

      if(r==SIM300_OK)
      {
         if(strcasecmp(msg,"VOTE A")==0)
         {
            votes[0]++;
            eeprom_write_word((uint16_t *)0,votes[0]);
            Reply(oa,1);
         }
         else if(strcasecmp(msg,"VOTE B")==0)
         {
            votes[1]++;
            eeprom_write_word((uint16_t *)2,votes[1]);
            Reply(oa,1);
         }
         else if(strcasecmp(msg,"VOTE C")==0)
         {
            votes[2]++;
            eeprom_write_word((uint16_t *)4,votes[2]);
            Reply(oa,1);
         }
         else if(strcasecmp(msg,"VOTE D")==0)
         {
            votes[3]++;
            eeprom_write_word((uint16_t *)6,votes[3]);
            Reply(oa,1);
         }
         else
         {
            //Invalid Choice
            Reply(oa,0);
         }

         _delay_ms(3000);

      }
      else
      {
         LCDClear();
         LCDWriteString("Err Reading Msg !");

         _delay_ms(3000);

      }

      //Finally delete the msg
      if (SIM300DeleteMsg(id)!=SIM300_OK)
      {
         LCDWriteString("Err Deleting Msg !");

         _delay_ms(3000);
      }

   }


   Halt();
}

void Halt()
{
   while(1);
}

void Reply(const char *num,uint8_t stat)
{

   uint8_t ref;
   int8_t r;

   if(stat)
      r=SIM300SendMsg(num,"Your vote has been successfully registered, Thank ! :) ",&ref);
   else
      r=SIM300SendMsg(num,"Invalid vote ! Please send VOTE x, where x can be A,B,C or D.Thanks!",&ref);

   if(r==SIM300_OK)
   {
      return;
   }
   else if(r==SIM300_TIMEOUT)
   {
      LCDClear();
      LCDWriteStringXY(0,0,"Can't Send Reply!");
      LCDWriteStringXY(0,1,"Time out !");

      _delay_ms(3000);
   }
   else
   {
      LCDClear();
      LCDWriteStringXY(0,0,"Can't Send Reply!");
      LCDWriteStringXY(0,1,"Fail  !");

      _delay_ms(3000);
   }

}

The source code is written in C language and compiled using the avr-gcc compiler with the help of latest Atmel Studio 6 IDE. The source code is dependent on the following libraries.

Notes

  1. If you are using a new ATMega32 MCU from the market set the LOW FUSE as 0x3F and HIGH FUSE are 0xC9.
  2. If you get NO display on LCD, adjust the contrast adjust preset RV1.
  3. Brownout detector is Enabled to prevent corruption of EEPROM, Brownout level is set to 4.0 volts. The above fuse bits ensure the proper brown out detector settings.
Setting AVR Fuse Byte

Fig.: Setting the Fuse bytes.

 

Reference

This project is based on SIM300 GSM Module, following tutorial explains more about the module :

Downloads

Help Us!

We try to publish beginner friendly tutorials for latest subjects in embedded system as fast as we can. If you like these tutorials and they have helped you solve problems, please help us in return. You can donate any amount as you like securely using a Credit or Debit Card or Paypal.

We would be very thankful for your kind help.

By
Avinash Gupta
Facebook, Follow on Twitter.
www.AvinashGupta.com
me@avinashgupta.com

Avinash

Avinash Gupta is solely focused on free and high quality tutorial to make learning embedded system fun !

More Posts - Website

Follow Me:
FacebookLinkedInGoogle Plus

About Avinash

Avinash Gupta is solely focused on free and high quality tutorial to make learning embedded system fun !

33 thoughts on “SMS Based Voting System – AVR GSM Project

  • By Jitesh - Reply

    Hello Avinash,
    Your tutorials on GSM interface has really boosted my moral to venture in this area. Great job indeed. I had a project in my mind but could not get started due to lack of exposure, which your tutorials have given me. I seek a little guidance from you in this regard. It is as follows:-

    Make a call to GSM module and get a voice message recorded. Then send a sms containing few mobile numbers. Now, the GSM module should call each of these numbers and play the recorded message.

    Thanks in advance

  • By shiv kumar singh - Reply

    give the advantage of this project

  • By Rupa - Reply

    Hi, A , avinash can you please send me some data sheets or some IEE papers on the same for my refference. this would help me for my seminar.
    Please reply me.

    Thanks You

    Rupa.

  • By Kiran - Reply

    Dear Sir,

    I have build a same project as an interest and learning basics of GSM module. I have compiled and downloaded the program. However, when one vote registered it automatically halted sometimes only VOTE A works nad vote B not works some time vice versa.

    Can you please guide me?

    • By Avinash - Reply

      What is your Order ID for purchase of xBoard and GSM Module?

    • By balaji - Reply

      Hi kiran… I’m also trying the same project. In that It simply waits for a msg. Not receiving any msg. Do i need to change anything in the code or connections? please let me know.

  • By pidu - Reply

    would you mind plz give me the pcb layout for the sms based voting system.

  • By mxaz - Reply

    can this project turn to STUDENT RESULT CHECKER SMS RETRIEVAL?

  • By sazzad - Reply

    May i know why do we use L1 and C3?

  • By aarushi mittal - Reply

    helo sir please send me the list of projects for ece students

  • By pidu - Reply

    how do i reset all the counters???

  • By biplob - Reply

    Dear Sir,

    I want to build a finger print based voting macine project . so i needs serial communication code with atmega8/16/32/ or 128

    Can you please guide me?

  • By Sony - Reply

    there is function SIM300SetTextMode(), I hope it is sending AT+CMGF=1 command to the module. But, is it enough if we execute this function only once at the start of the program after initialization??

    • By kiran patil - Reply

      dear soni,
      yes u need to issue this command only once on powerup, it is sufficient.

  • By jay shah - Reply

    hello sir…
    i want to know thw originating address of the received message can u help me how to dfind it….in this project u have written oa in sendmsg function bt i do not get the oa.

  • By nevil - Reply

    good projects! now i starting this projects.

  • By jay shah - Reply

    sir the receiving of message is not properly done. many times it does not display the initial characters. also i am trying it on atmega 16. i hav reduced the code size but still it gives error. can u rectify it o say the changes.

  • By GEE ROFAS - Reply

    Sir, where can i get the SIM300 library?…… i have seen you in separate projects that you have uploaded the LCD library, but what about that of SIM300?

  • By SAI KISHOR - Reply

    Respected Sir,
    I really love your tutorials and i just have a doubt can i use your SIM300 library to a code written in Winavr or not please let me know and sir can i use them for SIM900 module bought from your site

  • By Kabindra shakya - Reply

    can i design x board myself?
    and also i am having problem with the r = SIM300ReadMsg(id,msg,oa);
    oa is undefined

  • By AMIT - Reply

    HELLO ! Avinash sir , I am working on cellphone based voting system for my project but i can’t use x2 board i have to make it in zero pcb . i have burnt my ic atmega32 from market using hex file . The circuit diagram above atmega32 schematic and its connection to sim300 also have done but lcd doesn’t show require output but lcd is on.
    Tell me sir that above ckt diagram is of board or not.
    Reply me soon
    plz

    • By Avinash - Reply

      @AMIT,

      You should first make it exactly as shown i.e. using xBoard v2.0 only. Or get the complete setup prepared by our expert staffs.
      Then you should move on to making the same circuit using general purpose PCBs (that you are calling zero pcb)

  • By programmer - Reply

    hlw sir can i share a project with you??

    • By Avinash - Reply

      @Programmer

      Please send it to may email ID.

  • By aditya - Reply

    Hi kiran… I’m also trying the same project. In that It simply waits for a msg. Not receiving any msg. Do i need to change anything in the code or connections? please let me know.

    REPLY

  • By mari - Reply

    how can we avoid double voting from this system. and how much do you sell it’s prototype. regards

    • By Avinash - Reply

      @Mari,

      Please let us know your contact details like address on our email ID. Thank you.

  • By dijith k - Reply

    I am intrested in your project.

  • By dijith k @dijithkdijo@gmail.com - Reply

    sir,if i am using atmeg16 what all changes should i made in the above project.

    • By Avinash - Reply

      sorry I don’t know

  • By dijith k @dijithkdijo@gmail.com - Reply

    sir,i am beginner,so please provide me with the procedures and block daigram of this project

  • By Varun - Reply

    sir, i have seen your project of wireless electronic notice board using GSM modem last time .. right now when i am prepared to buy th components from you i couldnt see that blog can u please help me out to find out that blog..so that it helps me in buying and referring to the doubts . THANK YOU

  • By abdallah - Reply

    hello ,i dont have xboard and i cant buy it , but i have atmega32 ,is there is way to build the circuit without xboard ???uuu

Leave a Reply

Your email address will not be published. Required fields are marked *


6 × = six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>