Saturday, 25 October 2014

Electronic Voting Machine Using Arduino

VOTING MACHINE USING ARDUINO

Hello readers, before I give you a brief about the topic that I am going to discuss with you today, I would like to share with you a very small story. Few days back I was posted on Election duty as a presiding officer and this news was not less than an earthquake for me but then a senior colleague of mine told me that one should do it at least once in a life time. I went for it and believe me it is really tough and demanding duty. I spent two days away from home and during that time there was one thing which was more precious than my own life, Can you guess what that thing was? It was the Electronic Voting Machine (EVM). Now after spending two days with this machine I thought I should also design a one for my own use and today I will discuss with you the design of EVM using Arduino.

Generally EVM has two parts-

Control Unit

Ballot Unit

Control unit stores all the votes in the memory and is generally battery operated. Control unit also contains important buttons like result, close, print, clear. Ballot unit contains buttons of the contesting parties. A connecting cable is used for connecting ballot unit with the control unit.


Fig. below shows a pictorial block diagram of the EVM machine that I have designed.


Three buttons are provided for the three contesting parties (PARTY-A , PARTY-B, PARTY-C). Voters can use these buttons to vote for their party. So these three buttons are accessible to the voters. Voters are not given the access of the rest of the four buttons.

Total button can be pressed any time to get the count of the total number of votes that are polled so far. Close button if pressed closes the voting process and if this button is pressed then PARTY-A, B and C buttons will become in effective and pressing of these three buttons will not have any effect on the system. Once close button is pressed, Result button can be pressed to check the results of the poll. One Result button is pressed the machine will tell you the exact number of votes that are polled for each of the three contesting parties and it will also tell the result of the poll that is which party has won the election. The machine is programmed to also indicate the vote difference b/w the winning party and the first runner up party. In case tie happens b/w any two parties, or b/w all three contesting parties then the machine will show the tie result on the lcd screen. Clear button is also provided and if this button is pressed then entire memory of the machine gets empty and all the stored vote count becomes zero.

So clear and total button can be pressed any time during the voting process and if these buttons are pressed corresponding action that is programmed into the system will happen.

Close button must be pressed before result button is pressed to get the result.

The vote count is saved in the on chip EEPROM of the Arduino and so if power cut occurs then also the votes that are entered into the system will remain safe and again when the system is powered up the voting will begin from the previous state.

The circuit diagram drawn on proteus software is shown below-


All the buttons are connected to the digital pins of the arduino except for one (Clear button) which is connected to analog pin A0. Though clear button is connected to analog channel pin A0 it actually is working as a digital pin. PC0/ADC0 is the name of pin A0 so A to D conversion channel is an alternative functionality of this pin and it surely can behave as a normal digital input/output pin.

16*2 LCD display is interfaced with arduino to display the information to the user.  The software code was written in arduino IDE and was tested both on proteus software and on actual hardware and it worked perfectly in both these cases. The entire software code of the Electronic Voting Machine is given below-

Code-
 #include<LiquidCrystal.h> // lcd library
#include <EEPROM.h> //EEPROM library
LiquidCrystal lcd(13,12,11,10,9,8); // lcd control and data lines
// button pin definitions
int result=5;
int closed=6;
int total=7;
int clearbutton=A0;
int a=4;
int b=3;
int c=2;
// temporary variables used in program
int v1;
int v2;
int v3;
int v;
int cflag;

void setup()
{
  cflag=EEPROM.read(0); //read the status of cflag from memory
  v1=EEPROM.read(1);// v1 stores the vote count of party A
  v2=EEPROM.read(2); // v2 stores thevote count of party B
  v3=EEPROM.read(3); // v3 stores the vote count of party C
  pinMode(a,INPUT); // declaration of buttons as input
  pinMode(b,INPUT);
  pinMode(c,INPUT);
  pinMode(total,INPUT);
  pinMode(closed,INPUT);
  pinMode(result,INPUT);
  pinMode(clearbutton,INPUT);
  digitalWrite(a,HIGH); //default status of buttons when not pressed is high
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(total,HIGH);
  digitalWrite(closed,HIGH);
  digitalWrite(result,HIGH);
  digitalWrite(clearbutton,HIGH);
  lcd.begin(16,2);
  if(cflag==0)
  {
  lcd.print("Press button");
  lcd.setCursor(0,1);
  lcd.print("to vote...");
  delay(1000);
  }
  if(cflag==1)
  {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Voting Closed");
  lcd.setCursor(0,1);
  v=v1+v2+v3;
  lcd.print("Total Votes:");
  lcd.print(v);
  }
}

void rpt()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Press button");
  lcd.setCursor(0,1);
  lcd.print("to vote...");
}


void votedifference() // subrotine to calculate vote difference
{
  if(v1>v2)
  {
    if(v2>v3)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("A wins by");
      lcd.setCursor(0,1);
      lcd.print(v1-v2);
      lcd.print(" votes");
    }
    else
    {
      if(v1>v3)
      {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("A wins by");
      lcd.setCursor(0,1);
      lcd.print(v1-v3);
      lcd.print(" votes");
      }
      if(v1<v3)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("C wins by");
        lcd.setCursor(0,1);
        lcd.print(v3-v1);
        lcd.print(" votes");
      }
    }
    }
   
    else
    {
      if(v1>v3)
      {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("B wins by");
      lcd.setCursor(0,1);
      lcd.print(v2-v1);
      lcd.print(" votes");
      }
     
      else
      {
      if(v2>v3)
      {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("B wins by");
      lcd.setCursor(0,1);
      lcd.print(v2-v3);
      lcd.print(" votes");
      }
      if(v2<v3)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("C wins by");
        lcd.setCursor(0,1);
        lcd.print(v3-v2);
        lcd.print(" votes");
      }
    }
    }
}

void loop()
{
  if(digitalRead(a)==LOW && cflag==0) // if party A button is pressed
  {
    v1=v1+1;
    EEPROM.write(1,v1);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("vote received...");
    delay(1500);
    rpt(); 
  }
 
  if(digitalRead(b)==LOW && cflag==0) // if party B button is pressed
  {
    v2=v2+1;
    EEPROM.write(2,v2);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("vote received...");
    delay(1500);
    rpt(); 
  }
 
  if(digitalRead(c)==LOW && cflag==0) // if party C button is pressed
  {
    v3=v3+1;
    EEPROM.write(3,v3);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("vote received...");
    delay(1500);
    rpt(); 
  }
  // if total button is pressed and close button was not pressed earlier
  if(digitalRead(total)==LOW && cflag==0)
  {
    v=v1+v2+v3;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Total votes:");
    lcd.setCursor(0,1);
    lcd.print(v);
    delay(2000);
    rpt();
  }
 
  if(digitalRead(closed)==LOW) // if close button is pressed
  {
    cflag=1;
    EEPROM.write(0,cflag);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Voting Closed...");
    lcd.setCursor(0,1);
    v=v1+v2+v3;
    lcd.print("Total Votes:");
    lcd.print(v);
    while(digitalRead(result)==HIGH);
  }
 
  // if result button is pressed and before that close button was pressed
  if(digitalRead(result)==LOW && cflag==1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("A:");
    lcd.print(v1);
    lcd.setCursor(7,0);
    lcd.print("B:");
    lcd.print(v2);
    lcd.setCursor(0,1);
    lcd.print("C:");
    lcd.print(v3);
    delay(1500);
   
    // logic for result of voting process
    if(v1==v2 && v2==v3)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Result Tied");
      delay(1500);
    }
   
    if(v1==v2 && v1>v3)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Tie b/w A and B");
      delay(1500);
    }
   
    if(v2==v3 && v2>v1)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Tie b/w B and C");
      delay(1500);
    }
    if(v1==v3 && v1>v2)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Tie b/w A and C");
      delay(1500);
    }
   
    if(v1>v2)
    {
      if(v1>v3)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Party A wins");
        delay(1500);
        votedifference();
      }
      else if(v3>v1)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Party C wins");
        delay(1500);
        votedifference();
      }
    }
   
    else
    {
      if(v2>v3 && v1!=v2)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Party B wins");
        delay(1500);
        votedifference();
      }
      else if(v3>v2)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Party C wins");
        delay(1500);
        votedifference();
      }
    }
  }
 
  if(digitalRead(clearbutton)==LOW) // if clear button is pressed
  {
    for (int i = 0; i < 512; i++)
    {
      EEPROM.write(i, 0);
    }
    v1=0;
    v2=0;
    v3=0;
    cflag=0;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Memory Cleared");
    delay(1500);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Press button");
    lcd.setCursor(0,1);
    lcd.print("to vote...");
  }
}

A snap shot during proteus simulation when result button is pressed is shown below-


When clear button is pressed the lcd will show the message memory cleared as shown below-


I hope that after reading this article, readers will have a better understanding of EVM implementation using Arduino and I also believe that the description and coding provided here will help you to extend this project further by interfacing a GSM modem with the machine for sending SMS to the mobile phone numbers all the participating candidates/parties so that they can also get to know the result of each and every voting machine instantly.  

THANKS FOR READING…….
UMESH DUTTA

8 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thanks for sharing such useful information with us and Please keep sharing more interesting info of Electronics & Communication Engineering with us.

    Election Ink Manufacturer | Electronic Voting Machine Manufacturer

    ReplyDelete
  3. Thanks for reading the article, I will upload few more interesting articles soon...

    ReplyDelete
  4. hello sir,i have done the above project .initially it worked well but now lcd screen shows
    "voting closed....
    total votes =0"
    i have uploaded the code again but it is showing the same .
    kindly waiting for your replay

    ReplyDelete
    Replies
    1. Hi akhil, please check the status of pin 6 of arduino, use a pull up resistor of 10K ohm to make it high. Just connect one end of 10K pull up resistor to +5V and the other end to pin 6 of arduino. I hope it will solve the issue, please get back if it doesn't work.

      Delete
  5. الان مع صيانة الكتروستار خدمة الدعم الفنى والصيانة تصلكم اينما كنتم فى اسرع وقت

    ReplyDelete
  6. نوفر لكم في شركة مكافحة حشرات بالاحساء خدمات مكافحة الحشرات المتطورة بافضل الاسعار من خلال استخدام مبيدات حشرية ذات خصائص فعالة في القضاء على الحشرات من اول استخدام موقعنا:


    http://abraj-dubai.net/%D8%B4%D8%B1%D9%83%D8%A9-%D9%85%D9%83%D8%A7%D9%81%D8%AD%D8%A9-%D8%AD%D8%B4%D8%B1%D8%A7%D8%AA-%D8%A8%D8%A7%D9%84%D8%AF%D9%85%D8%A7%D9%85-%D8%A8%D8%A7%D9%84%D8%A7%D8%AD%D8%B3%D8%A7%D8%A1/

    ReplyDelete
  7. Hello Mr Umesh iam hobbiest of arduino. Iam working with arduino uno and GSM 800. Can i get the code for GSM based voting system with arduino. Iam glad if u send me the code to pavanhyd2000@gmail.com

    ReplyDelete