New Year Countdown Card!
Hello my name is Jasleen Nanuan and on this inscrutable I will be presenting my final project which is a Ne w Years countdown card! In the project I have a 7 segment display which counts to 5 marking the year being 2025 which works with the push button going up by one each time pressed, I also have 2 leds and 1 rgb led looking like fireworks which work with the distance sensor. I also have a cover photo printed out to look like the night sky to really make this look more put together. I thought of this idea looking back at a project I made which was making a prop with the circuit which really influenced this idea as well as the fact that new years just passed. This is just a really fun way to wish someone a happy new year and show your tech skill off!
Supplies
Here are the components used and the links to the websites were you can buy them!
- Arduino Uno 1x
- Pushbutton1x
- Wires
- Assorted LEDs2x
- Seven Segment Display1x
- Resistors 330 omh resisters
- breadboard 1x
- Distance-Sensor 1x
- rgb-led1x
Wireing
First you need to connect to a power source which is 5v and gnd , you will also need to connect the ends to power and ground which will have the e;electricity flow all around the breadboard. Next, For the 2 leds you will need to connect the anode to power through a 330 ohms resister and the cathode to ground which will light up led without getting fried. for the rgb led you will need to connect the red pin to 3 , green pin to 5, blue pin to 6, and the common pin to power with resister which is 330 k omh resister. After that you will connect the distance sensor by connecting vcc to power, gnd to ground, trig pin to 9 on the Arduino, and echo pin to 10 on the Arduino. Then, you ned to conect the 7 segment display by conecting , segmentPins[0] (pin 2): Segment A, segmentPins[1] (pin 4): Segment B, segmentPins[2] (pin 8): Segment C, segmentPins[3] (pin 11): Segment D , segmentPins[4] (pin 12): Segment E, segmentPins[5] (pin A0): Segment F, segmentPins[6] (pin A1): Segment G, and also common pin is conected to power through a resister becuase you are useing a common anode 7 segement display. Lastly , you need to conect on side of push button to gnd, conect to power through a 330 resister, and conect the top to the ardunio through a wire to 7.
Code
This is the code I used:
// Pin setup
const int trigPin = 9; // Ultrasonic sensor trigger pin
const int echoPin = 10; // Ultrasonic sensor echo pin
const int redPin = 3; // RGB LED red pin
const int greenPin = 5; // RGB LED green pin
const int bluePin = 6; // RGB LED blue pin
const int buttonPin = 7; // Push button pin
const int segmentPins[] = {2, 4, 8, 11, 12, A0, A1}; // 7-segment display pins
// Segment numbers for 1 to 5
const byte segmentNumbers[5][7] = {
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1} // 5
};
int counter = 1; // Start from 1
bool buttonPressed = false;
void setup() {
// Setup pins
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
displayNumber(counter);
}
void loop() {
// Handle RGB LED with distance sensor
long distance = measureDistance();
if (distance < 10) {
setRGBColor(true, false, false); // Red
} else if (distance < 20) {
setRGBColor(false, true, false); // Green
} else {
setRGBColor(false, false, true); // Blue
}
// Handle button press for 7-segment display
if (digitalRead(buttonPin) == LOW) {
if (!buttonPressed) {
counter++;
if (counter > 5) counter = 1; // Reset to 1 after 5
displayNumber(counter);
buttonPressed = true;
delay(200); // Debounce delay
}
} else {
buttonPressed = false;
}
}
// Measure distance using the ultrasonic sensor
long measureDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
long distance = duration * 0.034 / 2; // Convert to cm
return distance;
}
// Set the color of the RGB LED
void setRGBColor(bool red, bool green, bool blue) {
digitalWrite(redPin, red);
digitalWrite(greenPin, green);
digitalWrite(bluePin, blue);
}
// Display a number on the 7-segment display
void displayNumber(int num) {
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], segmentNumbers[num - 1][i]);
}
}
The codes purpose:
This codes purpose is to have the 7 segment display count to 1-5 each time its pressed it goes up by one and the rest is to have the rgb led to work with the distance sensor so when anything is near the led stays on and changes colors. This code has a crucial role in having all off the components work together perfectly and add more features.
Common Mistakes
A common mistake can be the wiring because the wiring is so complex and their are to many wire going into the Arduino so we loose focus on which pin goes where and ends up in a mess and its always important to go slowly. Another thing to look out for is connecting the code to the port because this can waste a lot of time in trying to figure out whats wrong. Another mistake always looking out for weather or not if the the wires or resister is going in the correct lane which is if its meant to go to ground or power.