Electronic Voting Machine using Arduino

Published  October 9, 2015   19
S Saddam
Author
Arduino Based Electronic Voting Machine

We all are quite familiar with voting machines, even we have covered few other electronic voting machine projects previously using RFID with 8051AVR microcontroller, and Raspberry Pi. In this project, we have used the arduino uno board to build a simple electronic voting machine. If you are looking for a similar Fingerprint based biometric voting machine project, you can check the link.

 

Components

  1. Arduino Uno
  2. 16x2 LCD
  3. Push button
  4. Bread board
  5. Power
  6. Connecting wires

 

Arduino Electronic Voting Machine Circuit Diagram and Working 

In this project we have used four push buttons for four different candidates. We can increase the number of candidate but for better understanding we have limited it to four. When any voter press any of four button then respecting voting value will increment by one each time. After whole voting we will press result button to see the results. As the "result" button is pressed, arduino calculates the total votes of each candidate and show it on LCD display.

Arduino Based Electronic Voting Machine

Circuit of this project is quite easy which contains Arduino, push buttons and LCD. Arduino controls the complete processes like reading button, incrementing vote value, generating result and sending vote and result to LCD. Here we have added five buttons in which first button is for BJP, second for INC, third is for AAP, forth is for OTH means others and last button is used for calculating or displaying results.

Arduino Based Electronic Voting Machine Circuit Diagram

 

The five push buttons are directly connected with pin 15-19(A1-A5) of Arduino with respect to ground. A 16x2 LCD is connected with arduino in 4-bit mode. Control pin RS, RW and En are directly connected to arduino pin 12, GND and 11. And data pin D4-D7 is connected to pins 5, 4, 3 and 2 of arduino.

 

Arduino EVM Code Description

First of all we include header and define pins for LCD and than initialize some variables and pin for taking candidate's voting input means switch.

Define

After it, initialize the LCD and give direction to input-output pins.

Initialize

and then make pullup the input pin by software.

Pull up

 In code we have used digital read function to read Button pressed.

reading

And then displaying voting on the LCD with the candidate party’s Name.

Displaying

Code

//Arduino based EVM Code

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define sw1 15
#define sw2 16
#define sw3 17
#define sw4 18
#define sw5 19
int vote1=0;
int vote2=0;
int vote3=0;
int vote4=0;
void setup()
{
  pinMode(sw1, INPUT);
  pinMode(sw2,INPUT);
  pinMode(sw3,INPUT);
  pinMode(sw4,INPUT);
  pinMode(sw5,INPUT);
  lcd.begin(16, 2);
  lcd.print("Voting Machine");
  lcd.setCursor(0,1);
  lcd.print("Circuit Digest");
  delay(3000);
  digitalWrite(sw1, HIGH);
  digitalWrite(sw2, HIGH);
  digitalWrite(sw3, HIGH);
  digitalWrite(sw4, HIGH);
  digitalWrite(sw5, HIGH);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("BJP");
  lcd.setCursor(4,0);
  lcd.print("INC");
  lcd.setCursor(8,0);
  lcd.print("AAP");
  lcd.setCursor(12,0);
  lcd.print("OTH");
}
void loop()
{
  lcd.setCursor(0,0);
  lcd.print("BJP");
  lcd.setCursor(1,1);
  lcd.print(vote1);
  lcd.setCursor(4,0);
  lcd.print("INC");
  lcd.setCursor(5,1);
  lcd.print(vote2);
  lcd.setCursor(8,0);
  lcd.print("AAP");
   lcd.setCursor(9,1);
  lcd.print(vote3);
  lcd.setCursor(12,0);
  lcd.print("OTH"); 
  lcd.setCursor(13,1);
  lcd.print(vote4);
  if(digitalRead(sw1)==0)
    vote1++;
    while(digitalRead(sw1)==0);
  if(digitalRead(sw2)==0)
    vote2++;
    while(digitalRead(sw2)==0);
  if(digitalRead(sw3)==0)
    vote3++;
    while(digitalRead(sw3)==0);
   if(digitalRead(sw4)==0)
    vote4++;
    while(digitalRead(sw4)==0);
   if(digitalRead(sw5)==0)
   {
     int vote=vote1+vote2+vote3+vote4;
     if(vote)
     {
      if((vote1 > vote2 && vote1 > vote3 && vote1 > vote4))
      {
       lcd.clear();
       lcd.print("BJP Wins");
       delay(2000);
       lcd.clear();
      }
      else if((vote2 > vote1 && vote2 > vote3 && vote2 > vote4))
      {
       lcd.clear();
       lcd.print("INC Wins");
       delay(2000);
       lcd.clear();
      }
      else if((vote3 > vote1 && vote3 > vote2 && vote3 > vote4))
      {
       lcd.clear();
       lcd.print("AAP Wins");
       delay(2000);
       lcd.clear();
      }
     else if(vote4 > vote1 && vote4 > vote2 && vote4 > vote3)
     {
       lcd.setCursor(0,0);
       lcd.clear();
       lcd.print("OTH Wins");
       delay(2000);
       lcd.clear();
     }
     
      else if(vote4 > vote1 && vote4 > vote2 && vote4 > vote3)
     {
       lcd.setCursor(0,0);
       lcd.clear();
       lcd.print("OTH Wins");
       delay(2000);
       lcd.clear();
     }
     
     else
     {
       lcd.clear();
       lcd.print("   Tie Up Or   ");
       lcd.setCursor(0,1);
       lcd.print("   No Result   ");
       delay(1000);
       lcd.clear();
     }
     
    }      
     else 
     {
       lcd.clear();
       lcd.print("No Voting....");
       delay(1000);
       lcd.clear();
     }
     vote1=0;vote2=0;vote3=0;vote4=0,vote=0;
     lcd.clear();
   }
   
}
  

Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Submitted by Prosenjeet Sengupta on Wed, 07/27/2016 - 21:46

Permalink

It doesn't store the result so if power suppyly is lost the memory erases.... You can use eeprom of the arduino using eeprom.h library to store the result

Submitted by Hira on Sat, 07/01/2017 - 22:21

Permalink

Hi !can u help me?
When I am doing coding in ardino it showing code error .can u tell me why ?

Submitted by yash jain on Sat, 03/10/2018 - 20:40

Permalink

sir I am getting the error in the program as "stray '\302' in program" so what should I do and where are the 16 and 2 pin connected ?

Submitted by Tanka on Fri, 07/13/2018 - 15:08

Permalink

How much votes can it save? I mean how many votes can be saved on arduino's internal eeprom. I am using Arduino Uno which has 1024 bytes of eeprom.