Hardware voting terminal firmware for secure blockchain-based electronic voting system
Built with STM32L432KC microcontroller and ESP32 WiFi bridge over 11 months of solo development.
This project implements a blockchain-based voting system designed to ensure secure, transparent, and tamper-proof elections. The system leverages the STM32 microcontroller and ESP32 for hardware integration, along with custom-built libraries to manage the voting process and blockchain operations.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STM32L432KC (Main MCU) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Keypad β β LCD I2C β β R307 FP β β
β β Input β β Display β β Sensor β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ β
β β β β β
β ββββββββββββββββββββ΄βββββββββββββββββββ β
β β β
β β UART (115200 baud) β
β β β
ββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESP32-WROOM-32 (WiFi Bridge) β
β β
β ββββββββββββββββββ ββββββββββββββββββ β
β β HTTP Client β ββββββ β TLS/SSL β β
β β JSON Parser β β Encryption β β
β ββββββββββββββββββ ββββββββββββββββββ β
β β β
β β WiFi/HTTPS β
β β β
ββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β
β
ββββββββββββββββββ
β Backend API β
β (Node.js) β
ββββββββββ¬ββββββββ
β
β
ββββββββββββββββββ
β Hyperledger β
β Fabric β
ββββββββββββββββββ
- R307 Fingerprint Sensor integration via UART
- Template enrollment with 512-byte capacity
- Real-time matching with adjustable confidence scores
- Support for 1:1 verification mode
- ESP32 WiFi Bridge handles all network operations
- HTTPS support with TLS 1.2+
- Certificate validation (configurable)
- Command-response protocol via UART
- Automatic retry logic with exponential backoff
- 16x2 LCD Display with I2C interface (PCF8574)
- 4x4 Matrix Keypad for Aadhaar/VoterID entry
- Scrolling candidate list navigation
- Real-time status updates and error messages
- Loading animations during network operations
- Direct API calls to Hyperledger Fabric backend
- Vote submission with cryptographic proofs
- Receipt polling with transaction IDs
- Automatic session management
- Email receipt delivery
- SHA256 hashing for voter identity
- Fingerprint-based authentication proof
- OTP verification via email
- Auth token-based session management
- No local vote storage (direct blockchain submission)
| Component | Model/Spec | Quantity | Purpose |
|---|---|---|---|
| Microcontroller | STM32L432KC (NUCLEO-32) | 1 | Main voting logic controller |
| WiFi Module | ESP32-WROOM-32 DevKit | 1 | Network communication bridge |
| Fingerprint Sensor | R307 Optical Sensor | 1 | Biometric authentication |
| LCD Display | 16x2 with I2C (PCF8574) | 1 | User interface display |
| Keypad | 4x4 Matrix Membrane | 1 | Data entry (Aadhaar/VoterID) |
| Power Supply | 5V 2A adapter | 1 | System power |
| Jumper Wires | Male-to-Female | 20+ | Connections |
- Breadboard or custom PCB
- Enclosure for terminal housing
- Buzzer for audio feedback
- Status LEDs
PA9 (TX) β R307 RX (Yellow)
PA10 (RX) β R307 TX (White)
β R307 VCC (Red) β 5V
β R307 GND (Black) β GND
PA2 (TX) β ESP32 RX (GPIO16)
PA3 (RX) β ESP32 TX (GPIO17)
PB6 (SCL) β LCD SCL
PB7 (SDA) β LCD SDA
β LCD VCC β 5V
β LCD GND β GND
Rows:
PB0 β Row 1
PB1 β Row 2
PA8 β Row 3
PA11 β Row 4
Columns:
PA0 β Col 1
PA1 β Col 2
PA4 β Col 3
PA5 β Col 4
GPIO16 (RX2) β STM32 UART2 TX (PA2)
GPIO17 (TX2) β STM32 UART2 RX (PA3)
GND β STM32 GND (common ground)
Hardware/
βββ BlockchainVotingMX_STM32/
β βββ Core/
β β βββ Inc/ # Header files for STM32
β β βββ Src/ # Source files for STM32
β β βββ Startup/ # Startup assembly files
β βββ Drivers/ # STM32 HAL drivers
β βββ Debug/ # Debugging files
β βββ BlockchainVotingMX.ioc # STM32CubeMX configuration file
βββ Evoting_ESP32/
β βββ Evoting.ino # Arduino sketch for ESP32
βββ LICENSE # License file
βββ README.md # Project documentation
- Power on the terminal
- Enroll fingerprints (admin mode - if implemented)
- Connect to WiFi - ESP32 auto-connects on boot
- Verify backend connection - Check LCD for status messages
βββββββββββββββββββββββ
β 1. SELECT ELECTION β β Navigate with keypad (β/β/Enter)
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 2. ENTER AADHAAR β β 12-digit Aadhaar number
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 3. ENTER VOTER ID β β Alphanumeric Voter ID
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 4. SCAN FINGERPRINTβ β Place finger on R307
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 5. VERIFY IDENTITY β β Backend validates with stored template
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 6. SEND OTP β β OTP sent to registered email
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 7. ENTER OTP β β 6-digit OTP code
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 8. VERIFY OTP β β Backend validates OTP
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 9. SELECT CANDIDATEβ β Scroll through candidate list
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 10. CONFIRM VOTE β β Press # to confirm, * to cancel
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 11. CAST VOTE β β Vote submitted to blockchain
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 12. WAIT RECEIPT β β Polling blockchain for confirmation
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β 13. SHOW RECEIPT β β Display TX ID and success message
βββββββββββββββββββββββ
βββββ¬ββββ¬ββββ¬ββββ
β 1 β 2 β 3 β A β A = Up/Previous
βββββΌββββΌββββΌββββ€
β 4 β 5 β 6 β B β B = Down/Next
βββββΌββββΌββββΌββββ€
β 7 β 8 β 9 β C β C = Clear/Cancel
βββββΌββββΌββββΌββββ€
β * β 0 β # β D β # = Enter/Confirm
βββββ΄ββββ΄ββββ΄ββββ * = Back/Cancel
D = Menu (reserved)
- Custom Libraries:
esp32_bridge: Manages communication between STM32 and ESP32.keypad: Handles keypad input.sha256: Provides cryptographic hashing.r307: Interfaces with the biometric sensor.
- Blockchain Implementation: Ensures secure and immutable vote storage.
-
STM32 Setup:
- Open the
BlockchainVotingMX.iocfile in STM32CubeMX. - Generate the code and compile it using STM32CubeIDE.
- Flash the firmware onto the STM32 microcontroller.
- Open the
-
ESP32 Setup:
- Open the
Evoting.inofile in the Arduino IDE. - Install the required libraries for ESP32.
- Upload the sketch to the ESP32 board.
- Open the
-
Hardware Connections:
- Connect the STM32 and ESP32 using UART.
- Attach the keypad and biometric sensor to the STM32.
-
Run the System:
- Power on the hardware.
- Follow the on-screen instructions to cast votes.
If this project helped you or inspired your work, please give it a β!
- Lines of Code: ~3000+ (STM32) + ~800+ (ESP32)
- Development Time: 11 months
- Languages: C, C++
- Hardware Platforms: STM32L4, ESP32
- Communication Protocols: UART, I2C, HTTP/HTTPS
- Security: SHA256, TLS, Fingerprint biometrics
Built with β€οΈ and countless cups of coffee β
"From concept to completion, every line of code tells a story of persistence."
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the terms of the LICENSE file.
- Special thanks to the open-source community for providing tools and libraries that made this project possible.