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

Arduino UNO-Based Timer with Servo Control and Keypad Input

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Timer with Servo Control and Keypad Input

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller, a servo motor, a 4x4 membrane matrix keypad, and a buzzer. The Arduino UNO controls the servo motor and the buzzer based on input received from the keypad. The user can set a timer using the keypad, and once the timer expires, the servo motor stops, and the buzzer sounds an alarm.

Component List

Arduino UNO

Servo

4X4 Membrane Matrix Keypad

Buzzer

Wiring Details

Arduino UNO

Servo

4X4 Membrane Matrix Keypad

Buzzer

Code Documentation

#include <Servo.h>
#include <Keypad.h>

Servo myServo;
const int buzzerPin = 10;

// Keypad setup
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  myServo.attach(9); // Attach servo to pin 9
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Enter time in seconds:");
}

void loop() {
  static String inputString = "";
  char key = keypad.getKey();

  if (key) {
    if (key == '#') {
      int timeDuration = inputString.toInt();
      Serial.print("Timer set for: ");
      Serial.print(timeDuration);
      Serial.println(" seconds");
      inputString = "";
      startTimer(timeDuration);
    } else if (key == '*') {
      inputString = "";
      Serial.println("Input cleared");
    } else {
      inputString += key;
      Serial.print(key);
    }
  }
}

void startTimer(int duration) {
  myServo.write(90); // Start the servo motor
  delay(duration * 1000); // Wait for the specified duration
  myServo.write(0); // Stop the servo motor
  triggerAlarm();
}

void triggerAlarm() {
  for (int i = 0; i < 5; i++) {
    digitalWrite(buzzerPin, HIGH);
    delay(500);
    digitalWrite(buzzerPin, LOW);
    delay(500);
  }
  Serial.println("Time's up!");
}

This code initializes the servo motor, keypad, and buzzer. The user can input a time duration using the keypad, and the servo motor will run for the specified duration. Once the timer expires, the servo motor stops, and the buzzer sounds an alarm.