Arduino Mega 2560 Based Voting System with TFT Display Interface
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface an Arduino Mega 2560 with an ILI9341 TFT display and multiple pushbuttons. The primary function of this circuit appears to be a voting system, where the Arduino Mega 2560 collects inputs from the pushbuttons and displays the voting results on the TFT display. The pushbuttons are likely used for voters to select their choices, and the system is capable of displaying the vote counts in real-time.
Component List
Arduino Mega 2560
- Microcontroller board based on the ATmega2560
- It has 54 digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.
ILI9341 TFT Display
- A 2.8 inch color TFT LCD display with a 320x240 pixel resolution.
- It uses the ILI9341 driver and communicates with the microcontroller via SPI.
Pushbuttons (14 instances)
- Simple tactile pushbuttons used for user input.
- Each button has four pins: two for the button contacts and two for an optional internal pull-up or pull-down resistor.
Wiring Details
Arduino Mega 2560
3V3connected to ILI9341 TFT DisplayLED5Vconnected to ILI9341 TFT DisplayVCCGNDconnected to ILI9341 TFT DisplayGNDand all PushbuttonPin 1 (in)D7 PWMconnected to PushbuttonPin 2D8 PWMconnected to ILI9341 TFT DisplayRESETD9 PWMconnected to ILI9341 TFT DisplayDC/RSD10 PWMconnected to ILI9341 TFT DisplayCSD52connected to ILI9341 TFT DisplaySCKD51connected to ILI9341 TFT DisplaySDID22-D33connected to PushbuttonPin 4 (out)(one button per pin)
ILI9341 TFT Display
LEDconnected to Arduino Mega 25603V3VCCconnected to Arduino Mega 25605VGNDconnected to Arduino Mega 2560GNDRESETconnected to Arduino Mega 2560D8 PWMDC/RSconnected to Arduino Mega 2560D9 PWMCSconnected to Arduino Mega 2560D10 PWMSCKconnected to Arduino Mega 2560D52SDIconnected to Arduino Mega 2560D51
Pushbuttons
Pin 1 (in)connected to Arduino Mega 2560GNDPin 2connected to Arduino Mega 2560D7 PWM(only for one specific pushbutton)Pin 3 (out)connected to Arduino Mega 2560GND(common for all pushbuttons)Pin 4 (out)connected to Arduino Mega 2560D22-D33(one button per pin)
Documented Code
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// TFT display setup (connect appropriately to your setup)
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_MISO 12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
const int masterButtonPin = 7;
const int voteButtons[12] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33};
int voteCounts[12] = {0}; // Vote counts for each candidate
bool votingStarted = false;
const char* candidateNames[12] = {
"Candidate A", "Candidate B", "Candidate C", "Candidate D",
"Candidate E", "Candidate F", "Candidate G", "Candidate H",
"Candidate I", "Candidate J", "Candidate K", "Candidate L"
};
void setup() {
Serial.begin(9600);
// Initialize TFT display
tft.begin();
tft.setRotation(3); // Set rotation (adjust for your layout)
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
// Master button and voting buttons
pinMode(masterButtonPin, INPUT_PULLUP);
for (int i = 0; i < 12; i++) {
pinMode(voteButtons[i], INPUT_PULLUP);
}
// Initial display message
tft.setCursor(0, 0);
tft.println("Ready for voting");
}
void loop() {
if (digitalRead(masterButtonPin) == LOW && !votingStarted) {
votingStarted = true;
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.println("Voting Started");
delay(500); // Debounce delay
}
if (votingStarted) {
for (int i = 0; i < 12; i++) {
if (digitalRead(voteButtons[i]) == LOW) {
voteCounts[i]++;
displayVotes(); // Update the display with vote counts
delay(500); // Debounce delay to prevent double counts
}
}
}
}
void displayVotes() {
tft.fillScreen(ILI9341_BLACK); // Clear screen
tft.setCursor(0, 0); // Reset cursor position
for (int i = 0; i < 12; i++) {
tft.setCursor(0, i * 20); // Adjust line spacing
tft.print(candidateNames[i]);
tft.print(": ");
tft.println(voteCounts[i]); // Print the vote count for each candidate
}
}
This code is designed to run on the Arduino Mega 2560 and interfaces with the ILI9341 TFT display to show the voting results. The masterButtonPin is used to start the voting process, and the voteButtons array contains the pins connected to the voting buttons. When a button is pressed, the corresponding vote count is incremented and displayed on the screen. The displayVotes function updates the TFT display with the current vote counts for each candidate.