list of products from Amazon (Not mine, i just link them!) Scroll Down For Article! Note: Elegoo boards are not Arduino, but they are compatible with Arduino IDE and are mutch more affordable!
This Arduino code implements a countdown timer with a 7-segment display driven by a 4511 IC, a buzzer for an alarm, and an optional start/reset button. Here's a brief explanation:
Components and Setup
Pins:
counterPins[]
: Connected to the 4511 IC inputs (D, C, B, A) for driving the 7-segment display.buzzerPin
: Controls a buzzer for an alarm.startButtonPin
: Optional button for starting or resetting the countdown.
Setup:
- Configures
counterPins
as outputs to control the 7-segment display. - Configures the buzzer pin as output and turns it off initially.
- Configures the button pin as input with a pull-up resistor.
- Displays the initial countdown value (9) on the 7-segment display.
- Configures
Functionality
Button-Controlled Countdown:
- The
loop()
waits for the button press (LOW
signal due to the pull-up resistor) to start the countdown. - A debounce delay of 200ms prevents false triggers.
- The
Countdown Logic:
- The
countdown()
function decrements the counter from the specified start value (9 by default) to 0. - Each decrement updates the 7-segment display via the
updateCounter()
function, which converts the counter value to binary and sets the corresponding pins on the 4511 IC. - A 1-second delay creates the countdown effect.
- The
Alarm Activation:
- When the countdown reaches 0, the
activateAlarm()
function activates the buzzer, causing it to beep 5 times with 200ms on/off intervals.
- When the countdown reaches 0, the
Key Functions
updateCounter(int value)
: Converts the counter value to binary and sends the signal to the 4511 IC to update the 7-segment display.countdown(int startValue)
: Handles the countdown sequence and triggers the alarm when finished.activateAlarm()
: Controls the buzzer to produce an audible alert when the countdown ends.
updateCounter
function translates a given number (0–9) into its binary equivalent and sends it to the 4511 IC to control the 7-segment display. For example, if the input value
is 5, its binary equivalent is 0101
. The function loops through the counterPins
array, setting each pin to match the binary representation: pin 7 gets 1
(least significant bit), pin 6 gets 0
, pin 5 gets 1
, and pin 4 gets 0
. Similarly, if value
is 3, its binary representation is 0011
, so pin 7 gets 1
, pin 6 gets 1
, pin 5 gets 0
, and pin 4 gets 0
. This way, the binary pattern is sent to the IC to display the correct digit on the 7-segment display.Summary
The code creates a simple countdown timer that starts on a button press, displays the countdown on a 7-segment display, and activates a buzzer alarm when the countdown completes.
0 Comments