Components

Arduino Uno
16x2 LCD
Push button
Bread board
Power
Connecting wires


Circuit Diagram and Working Explanation


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.



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.



Program 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.



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



and then make pullup the input pin by software.



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



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



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

#define sw115
#define sw216
#define sw3 17
#define sw4 18
#define sw519
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 ();
   }
   
}


No comments

Theme images by Dizzo. Powered by Blogger.