Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Electronic Voting System with TFT Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Electronic Voting System with TFT Display

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with an ILI9341 TFT display and multiple pushbuttons. The primary function of the circuit is to create a voting system where each pushbutton corresponds to a candidate, and the votes are displayed on the TFT screen. The Arduino UNO is used as the central processing unit to manage button presses, count votes, and control the display output.

Component List

Arduino UNO

ILI9341 TFT Display

Pushbuttons (12 units)

Resistor (220 Ohms)

Battery 9V

Wiring Details

Arduino UNO

ILI9341 TFT Display

Pushbuttons

Resistor (220 Ohms)

Battery 9V

Documented Code

#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>

// TFT Display pins
#define TFT_CS     10
#define TFT_RST    9
#define TFT_DC     8

// Create TFT object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

// Pin definitions for buttons
const int masterButton = 12;  // Master Unit Button on Pin 12
const int voteButtons[12] = {2, 3, 4, 5, 6, 7, A0, A1, A2, A3, A4, A5};  // Voting buttons for 12 candidates

// Candidate names
const char* candidateNames[12] = {
  "Alice", "Bob", "Charlie", "David",
  "Eve", "Frank", "Grace", "Heidi",
  "Ivan", "Judy", "Mallory", "Oscar"
};

// Vote count variables
int voteCounts[12] = {0};  // Store vote counts for each candidate
bool votingActive = false;  // Flag for when voting starts

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600);

  // Initialize the TFT display
  tft.begin();
  tft.setRotation(3);  // Set rotation to landscape (adjust if needed)
  tft.fillScreen(ILI9341_BLACK);  // Clear the screen

  // Display "Ready for Voting" message
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.print("Voting Ready!");

  // Set pin modes for buttons with internal pull-up resistors
  pinMode(masterButton, INPUT_PULLUP);  // Master unit button
  for (int i = 0; i < 12; i++) {
    pinMode(voteButtons[i], INPUT_PULLUP);  // Voting buttons
  }
}

void loop() {
  // Check if the Master Unit Button is pressed to start voting
  if (digitalRead(masterButton) == LOW && !votingActive) {
    votingActive = true;
    tft.fillScreen(ILI9341_BLACK);  // Clear the screen
    tft.setCursor(0, 0);
    tft.setTextColor(ILI9341_GREEN);
    tft.setTextSize(2);
    tft.print("Voting Started");
    delay(1000);  // Pause for effect
    updateVoteDisplay();
  }

  // If voting is active, check for votes
  if (votingActive) {
    for (int i = 0; i < 12; i++) {
      if (digitalRead(voteButtons[i]) == LOW) {
        voteCounts[i]++;  // Increment the vote count for the candidate
        Serial.print(candidateNames[i]);
        Serial.println(" received a vote!");
        updateVoteDisplay();  // Update the display with new vote counts
        delay(500);  // Simple debounce delay
      }
    }
  }
}

// Function to update the vote count display
void updateVoteDisplay() {
  tft.fillScreen(ILI9341_BLACK);  // Clear the screen
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  // Display votes for each candidate in rows
  int yPosition = 0;
  for (int i = 0; i < 12; i++) {
    tft.setCursor(0, yPosition);
    tft.print(candidateNames[i]);
    tft.print(": ");
    tft.print(voteCounts[i]);

    yPosition += 20;  // Move to the next line (adjust for spacing)
    if (yPosition > 220) {
      tft.fillScreen(ILI9341_BLACK);  // Clear screen when it overflows
      yPosition = 0;
    }
  }
}

This code is designed to run on the Arduino UNO and interfaces with the ILI9341 TFT display to create a voting system. It initializes the display and sets up the buttons with internal pull-up resistors. When the master button is pressed, it activates the voting system, and each button press on the voting buttons increments the vote count for the corresponding candidate. The display is updated in real-time to show the current vote counts.