Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Controlled Countdown Timer with Relay and Push Button Interaction

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Countdown Timer with Relay and Push Button Interaction

Circuit Documentation

Summary

The circuit in question is designed around an Arduino Nano microcontroller and includes an Adafruit PowerRelay Feather Wing, a 5643AS 7-segment display, multiple resistors, a red LED, and a 2-pin push switch. The Arduino Nano controls the 7-segment display and the relay module, while also monitoring a push button to potentially alter the display and relay state. The red LED is connected to the 3.3V power supply through the Arduino Nano and indicates power or status. Resistors are used for current limiting and pull-down purposes.

Component List

Arduino Nano

Adafruit PowerRelay Feather Wing

5643AS 7-segment display

Resistors (1k Ohms)

LED: Two Pin (red)

2Pin Push Switch

Wiring Details

Arduino Nano

Adafruit PowerRelay Feather Wing

5643AS 7-segment display

Resistors (1k Ohms)

LED: Two Pin (red)

2Pin Push Switch

Documented Code

#include <SevSeg.h>

SevSeg sevseg; // Create an instance of the object
#define RELAY 1
#define BUTTON 0

unsigned long previousMillis = 0;
const long interval = 1000; // 1 second
int countdown = 5;
bool relayState = false;

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {2, 3, 4, 5}; // Adjust these pins according to your wiring
  byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; // Adjust these pins according to your wiring
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // or COMMON_ANODE
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = true; // Use 'true' if you'd like to keep the leading zeros

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);

  pinMode(RELAY, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
  sevseg.setNumber(countdown, 0);
}

void loop() {
  unsigned long currentMillis = millis();

  if (digitalRead(BUTTON) == LOW) {
    delay(50); // Debounce delay
    if (digitalRead(BUTTON) == LOW) {
      countdown += 5;
      sevseg.setNumber(countdown, 0);
      while (digitalRead(BUTTON) == LOW); // Wait for button release
    }
  }

  if (countdown > 0 && !relayState) {
    digitalWrite(RELAY, HIGH);
    relayState = true;
  }

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (countdown > 0) {
      countdown--;
      sevseg.setNumber(countdown, 0);
    } else if (relayState) {
      digitalWrite(RELAY, LOW);
      relayState = false;
    }
  }

  sevseg.refreshDisplay(); // Must run repeatedly
}

This code is designed to run on an Arduino Nano and controls a 7-segment display and a relay. It includes a countdown timer that can be incremented by pressing a button. When the countdown is active, the relay is engaged. Once the countdown reaches zero, the relay is disengaged. The display shows the current countdown value, and the button press adds time to the countdown.