Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Electronic Voting Machine using Internal EEPROM of AVR

By Ashutosh Bhatt June 25, 2013

The microcontroller based voting machines made the process of voting and counting the voted lot easier than before. Previously the votes were marked in paper which are then stored safely in a box and inside a well secure room for days. The process of separating the votes and counting them manually may take a lot of days. But after finding the electronic voting machine the votes can be marked without using papers, which makes the voting process eco-friendly. Moreover it makes the counting process faster and the results can be announced in a comparatively shorter period of time. 

There should be a controller inside the Electronic Voting Machine (EVM) which controls the process and there should be storage medium where the details of the vote are stored. There should be a ballet unit which is been used in such a way that the one who came to cast the vote can do only one vote. There should be a keypad also which can be used by those who wish to cast a vote. In this project the AVR microcontroller is used to demonstrate the working of a simplest voting machine which can communicate with a PC serially and which can store the count of votes in its internal memory.

 


 

This project is all about how we can make use of internal EEPROM of the AVR for storing data for future purpose. In this project we are making an Electronic Voting Machine (EVM) using the EEPROM of the AVR. As in the case of normal EVM, there is a control unit and a ballet unit. The ballet unit can be used to cast the vote only after it is enabled by pressing a key in the control unit. After casting a single vote the ballet unit will get disabled again. Each and every time a user press a key the LCD displays which candidate he voted for.

The interesting part is that each and every time a vote being casted, the count will get updated automatically in the internal EEPROM. Hence once the polling is done we can disconnect the unit from power supply and keep it safe till the day of counting. We can power up the board and even after a long period of time we can read out the number of votes casted for each candidate by connecting the EVM to the through HyperTerminal via serial communication with AVR. 

 

Project Source Code

###


#define F_CPU 8000000
 
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "lcd.h"
#include "usart.h"
 
void switch_init ( void );
void led_init ( void );
void evm_init ( void );
void evm_raedy_wait ( void );
void evm_vote ( void );
char read_key_wait ( void );
void update_count ( int candidate_address );
void send_count_out ( void );
void reset_count ( void );
 
int main ( void )
{
char poll_result_mode = 1;
evm_init ();
 
MENU:
//-----------------------------------------//
stdout = &lcd_out;
lcd_clear ();
printf ( "A-POLL B-COUNT");
printf ( "nRESET COUNT-C" );
//-----------------------------------------//
 
poll_result_mode = read_key_wait ();   // wait till any key is pressed 
                 // and read the current key pad value
switch ( poll_result_mode )
{
case 0:
while ( 1 )
{
evm_raedy_wait ();
evm_vote ();
}
goto MENU;
case 1:
send_count_out ();
goto MENU;
 
case 2:
reset_count ();
goto MENU;
}
 
while ( 1 );
}
void switch_init ( void )
{
cli();
DDRC &= 0xE0;
PORTC = 0xFF;
DDRD |= 0x80;
PORTD |= 0x80;
sei();
}
 
void led_init ( void )
{
cli();
DDRD |= 0x80;
PORTD |= 0x80;
sei();
}
 
void evm_init ()
{
led_init ();
switch_init ();
usart_init();
lcd_init ();
}
 
void evm_raedy_wait ( void )
{
lcd_clear ();
printf ( "_______EVM______" );
//============ wait till evm unit enabled by external switch ===============//
while ( ( PINC & 0x10 ) );
_delay_ms ( 50 );
while ( !( PINC & 0x10 ) );
PORTD &= 0x7F;
//============ wait till evm unit enabled by external switch ===============//
lcd_clear ();
printf ( "YOU CAN VOTE NOW" );
}
 
char read_key_wait ( void )
{
char button;
 
while ( 0x0F == ( button = ( PINC & 0x0F ) ) );   // wait till any key is pressed 
 // and read the current key pad value
_delay_ms ( 50 );
 
switch ( button )
{
case 0x0B:
return 0;
 
case 0x07:
return 1;
 
case 0x0D:
return 2;
 
case 0x0E:
return 3;
};
 
return 0;
}
 
void evm_vote ( void )
{
char button;
 
button = read_key_wait ();   // wait till any key is pressed 
 // and read the current key pad value
switch ( button )
{
case 0:
update_count ( 0 );
lcd_clear ();
printf ( "You voted for A" );
break;
 
case 1:
update_count ( 1 );
lcd_clear ();
printf ( "You voted for B" );
break;
 
case 2:
update_count ( 2 );
lcd_clear ();
printf ( "You voted for C" );
break;
 
case 3:
update_count ( 3 );
lcd_clear ();
printf ( "You voted for D" );
break;
};
 
PORTD |= 0x80;
_delay_ms ( 3000 );
}
 
void update_count ( int candidate_address )
{
int base_address = 100;
int count = 0;
 
count = eeprom_read_byte ( ( unsigned char * ) ( base_address + candidate_address ) );
count ++;
eeprom_write_byte ( ( unsigned char * ) ( base_address + candidate_address ), count );
}
 
void send_count_out ( void )
{
int base_address = 100;
int i = 0;
 
stdout = &uart_out;
printf ( "n______________________EVM______________________" );
 
for ( i = 0; i < 4; i ++ )
printf ( "nCANDIDATE : %c, NO. VOTES : %d", ( 'A' + i ), eeprom_read_byte ( ( unsigned char * ) ( base_address + i ) ) );
}
 
void reset_count ( void )
{
int base_address = 100;
int i = 0;
for ( i = 0; i < 4; i ++ )
eeprom_write_byte ( ( unsigned char * ) ( base_address + i ), 0 );
 
lcd_clear ();
printf ( "RESET [OK]");
_delay_ms ( 2000 );
}

########## LCD ##########

#ifndef _LCD_H
#define _LCD_H
 
#ifndef F_CPU
#define F_CPU 8000000
#endif
 
#include<avr/io.h>
#include<util/delay.h>
#include<inttypes.h>
#include <stdio.h>
#include <string.h>
 
#define rs PA0
#define rw PA1
#define en PA2
 
void lcd_init();
void dis_cmd(char);
void dis_data(char);
void lcdcmd(char);
void lcddata(char);
void lcd_clear(void);
void lcd_2nd_line(void);
void lcd_1st_line(void);
void lcd_string(const char *data);
int lcd_print(char c, FILE *stream);
int lcd_scroll(const char *data);
 
FILE lcd_out = FDEV_SETUP_STREAM(lcd_print, NULL,
                                         _FDEV_SETUP_WRITE);
 
char disp_beg [] = "                ";
 
int lcd_print(char c, FILE *stream)
{
  if('n' == c)
  lcd_2nd_line();
  else
    dis_data(c);
 
  return 0;
}
 
int lcd_scroll(const char *data)
{
int i;
int j = 0;
 
strcat(disp_beg, data);
 
for(i = 0; i < 14; i ++)
strcat(disp_beg, " ");
 
while(1)
{
for(i = 0;i < 16;i ++)
{
if(!disp_beg[i + j])
return 0;
else;
 
dis_data(disp_beg [i + j]);
}
j ++;
_delay_ms(500);
lcd_clear ();
}
 
return 0;
}
 
void lcd_string(const char *data)
{
for(;*data;data++)
dis_data (*data);
}
 
void lcd_clear(void)
{
dis_cmd(0x01);
_delay_ms(10);
}
 
void lcd_2nd_line(void)
{
dis_cmd(0xC0);
_delay_ms(1);
}
 
void lcd_1st_line(void)
{
dis_cmd(0x80);
_delay_ms(1);
}
 
void lcd_init() // fuction for intialize 
{
DDRA=0xFF;
dis_cmd(0x02); // to initialize LCD in 4-bit mode.
dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x80);
dis_cmd(0x01);
_delay_ms(500);
    stdout = &lcd_out;
}
 
void dis_cmd(char cmd_value)
{
char cmd_value1;
cmd_value1 = cmd_value & 0xF0; //mask lower nibble because PA4-PA7 pins are used. 
lcdcmd(cmd_value1); // send to LCD
 
cmd_value1 = ((cmd_value<<4) & 0xF0); //shift 4-bit and mask
lcdcmd(cmd_value1); // send to LCD
}
 
 
void dis_data(char data_value)
{
char data_value1;
data_value1=data_value&0xF0;
lcddata(data_value1);
 
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);
}
 
void lcdcmd(char cmdout)
{
PORTA=cmdout;
PORTA&=~(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(1);
PORTA&=~(1<<en);
}
 
void lcddata(char dataout)
{
PORTA=dataout;
PORTA|=(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(1);
PORTA&=~(1<<en);
}
 
#endif
 
 

###

 


Project Source Code

###


#ifndef _USART_H
#define _USART_H
 
#ifndef F_CPU
#define F_CPU 8000000
#endif
 
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
 
#include<avr/io.h>
#include<util/delay.h>
#include <stdio.h>
 
void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();
void usart_send_string(const char* data);
int uart_print(char c, FILE *stream);
 
FILE uart_out = FDEV_SETUP_STREAM(uart_print, NULL,
                                         _FDEV_SETUP_WRITE);
 
int uart_print(char c, FILE *stream)
{
 
  if (c == 'n')
    uart_print('r', stream);
  loop_until_bit_is_set(UCSRA, UDRE);
  UDR = c;
  return 0;
}
 
void usart_init()
{
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
 
stdout = &uart_out;
}
 
void usart_putch(unsigned char send)
{
while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte 
}
 
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
}
 
void usart_send_string(const char* data)
{
for(; *data; data ++)
usart_putch(*data);
}
 
#endif

###

 


Circuit Diagrams

circuit

Project Components

  • ATmega16
  • LCD
  • Resistor

Project Video


Filed Under: AVR, Electronic Projects
Tagged With: avr, eeprom, electronic voting machine
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • Create Voltage Report in HFSS
  • Can anyone please help me with this single board computer?
  • Anyone successfully communicated to the BlueNRG-M0 module on the B-L4S5I-IOT01A board
  • How to Build an Audio Tone Control?
  • Current version of LTspice not working on Windows 11?

RSS Electro-Tech-Online.com Discussions

  • KiCad custom symbol definition correct approach
  • Measuring controller current output with a meter
  • restarting this Christmas project
  • Anyone In The US Ordered From AliExpress Recently?
  • My Advanced Realistic Humanoid Robots Project

Featured Tutorials

Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
    Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
    Practical application of hardware filters with real-life examples
  • A filter design example
    A filter design example
  • Types of filter responses
    Types of filter responses
  • What are the two types of hardware filters?
    What are the two types of hardware filters?
  • What are hardware filters and their types?
    What are hardware filters and their types?
More Tutorials >

Recent Articles

  • Posifa sensors improve low-flow accuracy in compact systems
  • Acopian releases low-profile power supplies rated to 900 W
  • Octavo Systems OSDZU-3 REF Development Platform
  • Same Sky adds enclosure design to its audio engineering capabilities
  • Waterproof SMA-to-MHF I LK assemblies introduced by Amphenol RF

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

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

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe