Adjustable Timer With 7-Segment Display

by AustinS89 in Circuits > Arduino

127 Views, 1 Favorites, 0 Comments

Adjustable Timer With 7-Segment Display

circuit_image (29).png

In this project, we'll build an adjustable timer using an Arduino UNO and a 7-segment display. The timer duration is set using a DIP switch, and a tactile button starts the countdown. An LED and a buzzer provide visual and auditory alerts when the timer reaches zero.

This project was created by xboxusr666 using Cirkit Designer. Full credit goes to xboxusr666 for designing and sharing this innovative project with the community.

  1. Project Link: Adjustable Timer 7 Segment Display
  2. Documentation: Project Documentation

Supplies

  1. 1 x Arduino UNO
  2. 1 x SparkFun 7-Segment Serial Display (Green)
  3. 1 x Tactile Switch Button - 12mm Square
  4. 1 x DIP Switch (4 Position)
  5. 1 x LED (Red)
  6. 1 x Resistor (1 kΩ)
  7. 1 x Buzzer
  8. Jumper wires
  9. Breadboard or perfboard

Circuit Design

The complete circuit diagram and code are available in the Cirkit Designer IDE. You can view, edit, and interact with the project directly through the provided link.

  1. View the Circuit Diagram and Code: Open the project link in Cirkit Designer to access the detailed schematic and code.

Assemble the Circuit

circuit_image (29).png

Follow these detailed instructions to assemble the circuit. Refer to the circuit diagram in the Cirkit Designer IDE for visual guidance.

1. Setting Up the Arduino UNO

Place your Arduino UNO on the workspace or attach it to a breadboard if preferred.

2. Connecting the 7-Segment Display

  1. Power Connections:
  2. Connect the VCC pin of the 7-segment display to the 5V pin on the Arduino.
  3. Connect the GND pin of the display to one of the GND pins on the Arduino.
  4. I2C Communication Lines:
  5. Connect the SDA pin of the display to the A4 pin on the Arduino.
  6. Connect the SCL pin of the display to the A5 pin on the Arduino.

3. Wiring the Tactile Switch Button

  1. Button Connections:
  2. One leg of the button connects to a GND pin on the Arduino.
  3. The opposite leg connects to digital pin D2 on the Arduino.
  4. Pull-up Configuration:
  5. Since the button is configured with an internal pull-up resistor (set in the code), no external resistor is needed.

4. Setting Up the DIP Switch (4 Position)

The DIP switch allows you to set the timer value in binary form.

  1. Grounding One Side of the Switches:
  2. Connect pins 1, 2, 3, and 4 of the DIP switch to the GND rail.
  3. Connecting the Other Side to Digital Pins:
  4. Connect pin 5 of the DIP switch to digital pin D6 on the Arduino.
  5. Connect pin 6 to digital pin D5.
  6. Connect pin 7 to digital pin D4.
  7. Connect pin 8 to digital pin D3.
  8. Note: Pins 1 to 4 are internally connected to pins 5 to 8 when the switches are in the ON position, completing the circuit.

5. Connecting the LED and Resistor

  1. Anode Connection:
  2. Connect the anode (longer leg) of the LED to digital pin D7 on the Arduino.
  3. Cathode Connection:
  4. Connect the cathode (shorter leg) of the LED to one end of the 1 kΩ resistor.
  5. Connect the other end of the resistor to the GND rail.
  6. Purpose of the Resistor:
  7. The resistor limits the current through the LED to prevent damage.

6. Wiring the Buzzer

  1. Positive Terminal:
  2. Connect the positive pin (usually marked with a + or red wire) of the buzzer to digital pin D8 on the Arduino.
  3. Negative Terminal:
  4. Connect the negative pin of the buzzer to the GND rail.

7. Ensuring Common Ground

Make sure all GND connections are connected to the same ground rail or point on the Arduino to ensure proper circuit operation.

Upload the Code Using Cirkit Designer

The code for this project is included with the Cirkit Designer project link. You can upload it directly to your Arduino UNO without the need for any additional software.

Steps to Upload the Code:

  1. Connect Your Arduino:
  2. Use a USB cable to connect your Arduino UNO to your computer.
  3. Open the Code Tab:
  4. In the Cirkit Designer IDE, navigate to the Code tab.
  5. Select the USB Port:
  6. Click on the Port button within the IDE.
  7. Select the USB port that corresponds to your connected Arduino UNO.
  8. Upload the Code:
  9. Click the Upload button.
  10. The Cirkit Designer IDE will compile and upload the code directly to your Arduino UNO.
  11. Wait for the upload to complete. A confirmation message will appear once it's done.

Cirkit Designer automatically manages library installations and configurations, simplifying the upload process.

Test the Timer

Now that your circuit is assembled and the code is uploaded, it's time to test the adjustable timer.

1. Setting the Timer Value with DIP Switches

  1. Understanding the DIP Switches:
  2. Each of the four switches represents a bit in a 4-bit binary number.
  3. From left to right (pins 5 to 8 connected to D6 to D3), the switches represent bits 2^3, 2^2, 2^1, and 2^0 respectively.
  4. Configuring the Timer:
  5. Flip the switches to the ON position to represent binary 1.
  6. The combination of switches sets the timer value from 0 to 15 seconds.
  7. For example:
  8. All switches OFF: 0000 (0 seconds)
  9. Switch D3 ON (pin 8): 0001 (1 second)
  10. Switch D4 ON (pin 7): 0010 (2 seconds)
  11. Switches D3 and D4 ON: 0011 (3 seconds)
  12. Up to all switches ON: 1111 (15 seconds)

2. Starting the Timer

  1. Press the Tactile Button:
  2. Press the button connected to D2 to start the timer.
  3. The button uses an internal pull-up resistor, so pressing it connects D2 to GND.
  4. Timer Countdown:
  5. The 7-segment display will show the timer counting down from the set value.
  6. The display may blink the decimal point to indicate the timer is running.

3. Observing the Alerts

  1. When Timer Reaches Zero:
  2. The LED connected to D7 will start blinking.
  3. The buzzer connected to D8 will emit beeping sounds intermittently.
  4. The 7-segment display will show 0000 or may blink to indicate the timer has finished.

4. Resetting the Timer

  1. Press the Button Again:
  2. Press the tactile button to reset or stop the timer.
  3. You can set a new timer value using the DIP switches and start the process again.

Additional Tips

Debugging Connections:

  1. If something isn't working, double-check all your connections against the circuit diagram.
  2. Ensure that all components are securely connected and that there are no loose wires.

Power Supply:

  1. The Arduino UNO can be powered via the USB connection during testing.
  2. If using an external power supply, ensure it provides a stable 5V.

Code

Below is the Arduino code for the adjustable timer. You can also access and edit this code directly in the Cirkit Designer IDE.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>

// Define the pin connections
const int buttonPin = 2; // The push button is connected to pin D2
const int ledPin = 7; // The LED is connected to pin D7
const int buzzerPin = 8; // The buzzer is connected to pin D8

// Define the DIP switch pins
const int dipPins[4] = {3, 4, 5, 6}; // DIP switches connected to pins D3, D4, D5, D6

// Create display object
Adafruit_7segment display = Adafruit_7segment();

// Variables to hold the timer value and state
unsigned long timerValue = 0;
unsigned long previousMillis = 0;
bool timerRunning = false;
bool displayBlinkState = false;

void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Set the button as an input with an internal pull-up resistor
pinMode(ledPin, OUTPUT); // Set the LED as an output
pinMode(buzzerPin, OUTPUT); // Set the buzzer as an output

// Initialize the DIP switch pins
for (int i = 0; i < 4; i++) {
pinMode(dipPins[i], INPUT_PULLUP);
}

// Initialize the display
display.begin(0x70); // Pass in the address
display.clear(); // Clear the display
display.writeDisplay();

// Read the initial timer value from the DIP switches
timerValue = readDipSwitches();
displayTimer(timerValue, true); // Display the initial timer value
}

void loop() {
// Check if the button is pressed
if (digitalRead(buttonPin) == LOW) {
delay(200); // Debounce delay
if (!timerRunning) {
timerRunning = true;
timerValue = readDipSwitches(); // Update the timer value in case the DIP switches changed
previousMillis = millis(); // Reset the timer
displayTimer(timerValue, false); // Update display without blinking decimal
} else if (timerValue == 0) {
// Restart the timer if it has finished counting down
timerRunning = false;
display.clear();
display.writeDisplay();
}
}

// Timer logic
if (timerRunning && timerValue > 0) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
timerValue--;
displayTimer(timerValue, displayBlinkState);
displayBlinkState = !displayBlinkState; // Toggle the blink state
}
} else if (timerValue == 0 && timerRunning) {
// Timer has reached 0, blink the display, LED, and buzzer
blinkAll();
}
}

// Function to read the DIP switch settings and calculate the timer value
unsigned long readDipSwitches() {
unsigned long value = 0;
for (int i = 0; i < 4; i++) {
if (digitalRead(dipPins[i]) == LOW) { // Active LOW switches
value += (1 << (3 - i)); // Calculate the value based on switch position
}
}
return value;
}

// Function to display the timer value on the 7-segment display
void displayTimer(unsigned long value, bool showDecimal) {
display.clear();
// Print the value in decimal format with leading zeros
if (value < 10) {
display.print("000");
display.print(value);
} else if (value < 100) {
display.print("00");
display.print(value);
} else if (value < 1000) {
display.print("0");
display.print(value);
} else {
display.print(value);
}
display.writeDisplay();
// Blink the right-most decimal point
if (showDecimal) {
display.drawColon(false);
uint8_t led = display.displaybuffer[4]; // Get the current state of the last digit
display.writeDigitRaw(4, led | 0b10000000); // Turn on the decimal point
display.writeDisplay(); // Update the display with the decimal point on
}
}

// Function to blink "0000" on the display, the LED, and beep the buzzer
void blinkAll() {
displayBlinkState = !displayBlinkState;
if (displayBlinkState) {
// Turn on the LED and buzzer
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
// Display "0000" with no decimals
display.print("0000");
display.writeDisplay();
} else {
// Turn off the LED and buzzer
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
// Clear the display
display.clear();
display.writeDisplay();
}
}


Notes:

  1. Libraries Used:
  2. Adafruit GFX Library
  3. Adafruit LED Backpack Library
  4. These libraries are automatically managed within the Cirkit Designer IDE.

How It Works

DIP Switches: Set the initial timer value in binary form, allowing you to choose a duration between 0 and 15 seconds.

Tactile Button: Starts and stops the timer. When pressed, it initiates the countdown based on the DIP switch settings.

7-Segment Display: Provides a visual countdown of the timer value using I2C communication with the Arduino.

LED and Buzzer: Activate when the timer reaches zero, providing visual and auditory alerts to signal that the countdown has finished.

Acknowledgments

All credit for this project goes to xboxusr666, who designed and shared this project using Cirkit Designer. We appreciate the opportunity to showcase this innovative design and thank xboxusr666 for contributing to the Cirkit Designer community.

Conclusion

You've successfully built an adjustable timer using an Arduino and a 7-segment display. This project serves as an excellent introduction to working with timers, user input, and display output in embedded systems. Feel free to explore the project further in Cirkit Designer, modify it, and expand upon it to suit your needs.