Skip to content

STM32-based seven-segment display counter with IR sensor trigger. Displays digits 0-9, incrementing on object detection with debouncing and auto-reset functionality.

Notifications You must be signed in to change notification settings

SanthoshKumar-BE/stm32-7segment-ir-counter

Repository files navigation

STM32 microcontrollers using STM32 HAL library. ๐Ÿš€ Features

Seven-Segment Display Control: Displays digits 0-9 with proper segment patterns IR Sensor Integration: Detects objects and increments counter Debouncing: Prevents multiple counts from single detection Auto Reset: Counter resets to 0 after reaching 9 HAL Library: Uses STM32 HAL for better portability

๐Ÿ› ๏ธ Hardware Requirements

STM32 microcontroller (tested on STM32F4xx series) Common cathode seven-segment display IR sensor module (active high output) Current limiting resistors (220ฮฉ - 330ฮฉ for each segment) Breadboard and jumper wires

๐Ÿ“‹ Pin Configuration Seven-Segment Display SegmentSTM32 PinDescriptionAPA0Top horizontalBPA1Top right verticalCPA2Bottom right verticalDPA3Bottom horizontalEPA4Bottom left verticalFPA5Top left verticalGPA6Middle horizontalDPPA7Decimal point IR Sensor ComponentSTM32 PinDescriptionIR SensorPB0 (configurable)Digital input ๐Ÿ”ง Circuit Diagram STM32 Seven-Segment Display PA0 ----[330ฮฉ]---- Segment A PA1 ----[330ฮฉ]---- Segment B PA2 ----[330ฮฉ]---- Segment C PA3 ----[330ฮฉ]---- Segment D PA4 ----[330ฮฉ]---- Segment E PA5 ----[330ฮฉ]---- Segment F PA6 ----[330ฮฉ]---- Segment G

PB0 --------------- IR Sensor OUT 3.3V -------------- IR Sensor VCC GND --------------- IR Sensor GND Display Common Cathode ๐Ÿ“‚ Project Structure stm32-7segment-ir-counter/ โ”œโ”€โ”€ Core/ โ”‚ โ”œโ”€โ”€ Inc/ โ”‚ โ”‚ โ””โ”€โ”€ main.h โ”‚ โ””โ”€โ”€ Src/ โ”‚ โ””โ”€โ”€ main.c โ””โ”€โ”€ main.txt โ”œโ”€โ”€ Drivers/ โ”‚ โ””โ”€โ”€ STM32F4xx_HAL_Driver/ โ”œโ”€โ”€ README.md ๐Ÿš€ Getting Started Prerequisites

STM32CubeIDE or any STM32-compatible IDE STM32CubeMX (for configuration) STM32 HAL library Hardware components listed above

Installation

Clone the repository bashgit clone https://github.com/yourusername/stm32-7segment-ir-counter.git cd stm32-7segment-ir-counter

Open in STM32CubeIDE

Import the project into your workspace Build the project (Ctrl+B)

Hardware Setup

Connect the seven-segment display to PA0-PA7 with current limiting resistors Connect the IR sensor to PB0 (or configure as needed) Power the circuit with 3.3V/5V as required

Flash the Program

Connect your STM32 via ST-Link Flash the program to your microcontroller

๐ŸŽฏ How It Works

Initialization: The system initializes GPIO pins and displays '0' Sensor Monitoring: Continuously monitors IR sensor input Edge Detection: Detects rising edge (object detection) Counter Increment: Increments display counter (0-9) Display Update: Updates seven-segment display with new digit Debouncing: 200ms delay prevents multiple counts Auto Reset: Counter resets to 0 after reaching 9

Code Structure

Segment Patterns: Hex values for each digit (0-9) Edge Detection: Prevents continuous counting HAL Functions: Clean, portable GPIO operations Debouncing: Software-based bounce elimination

โš™๏ธ Configuration Customizing Pins Edit the pin definitions in main.h: c#define IR_Sensor_Pin GPIO_PIN_0 #define IR_Sensor_GPIO_Port GPIOB Adjusting Debounce Delay Modify the delay in main.c: cHAL_Delay(200); // Adjust this value (milliseconds) Display Type For common anode displays, invert the segment patterns: cuint8_t segment[10] = { ~0x3f,// 0 (inverted) ~0x06,// 1 (inverted) // ... etc }; ๐Ÿ› Troubleshooting IssueSolutionDisplay shows wrong digitsCheck wiring and segment patternsMultiple counts per detectionIncrease debounce delayNo response from IR sensorVerify sensor wiring and powerDisplay too dim/brightAdjust resistor values ๐Ÿ”ฎ Future Enhancements

Multiple digit displays Different counting modes (up/down) EEPROM storage for count persistence LCD display option Interrupt-based sensor reading PWM brightness control

๐Ÿค Contributing

Fork the repository Create a feature branch (git checkout -b feature/enhancement) Commit changes (git commit -am 'Add new feature') Push to branch (git push origin feature/enhancement) Create a Pull Request

๐Ÿ™ Acknowledgments

STMicroelectronics for HAL library STM32 community for support and resources Open source embedded development communit Show Image

โญ Star this repository if you found it hel

About

STM32-based seven-segment display counter with IR sensor trigger. Displays digits 0-9, incrementing on object detection with debouncing and auto-reset functionality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages