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

Arduino Nano Controlled Timer Relay with LCD Interface and Buzzer Feedback

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Timer Relay with LCD Interface and Buzzer Feedback

Circuit Documentation

Summary

This circuit is designed to control a relay that switches a 240V power source to a bulb, with the relay being controlled by an Arduino Nano microcontroller. The Arduino Nano also interfaces with an I2C LCD 16x2 screen for display purposes and monitors multiple pushbuttons for user input. A buzzer provides audible feedback. The circuit is powered by a 5V supply, which is distributed to the components that require it.

Component List

1-Channel Relay (5V 10A)

I2C LCD 16x2 Screen

Pushbutton

Bulb

Buzzer

Arduino Nano

240v Power Source

Wiring Details

1-Channel Relay (5V 10A)

I2C LCD 16x2 Screen

Pushbuttons

Bulb

Buzzer

Documented Code

#include <LiquidCrystal.h> // Include LiquidCrystal library for LCD
#include <Keypad.h> // Include Keypad library for keypad input

// Define pins for components
const int buzzerPin = 2;
const int relayPin = 3;
const int lcdPin1 = 4;
const int lcdPin2 = 5;
const int lcdPin3 = 6;
const int lcdPin4 = 7;
const int lcdPin5 = 8;
const int lcdPin6 = 9;
const int switch1Pin = 10;
const int switch2Pin = 11;
const int switch3Pin = 12;
const int switch4Pin = 13;

// Initialize LCD and keypad
LiquidCrystal lcd(lcdPin1, lcdPin2, lcdPin3, lcdPin4, lcdPin5, lcdPin6);
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3};
byte colPins[COLS] = {14, 15, 16, 17};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Global variables
int timerMinutes = 0;
bool timerActive = false;
bool lightOn = false;
unsigned long lastTime = 0;

void setup() {
  // Initialize pins
  pinMode(buzzerPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(switch1Pin, INPUT_PULLUP);
  pinMode(switch2Pin, INPUT_PULLUP);
  pinMode(switch3Pin, INPUT_PULLUP);
  pinMode(switch4Pin, INPUT_PULLUP);

  // Initialize LCD
  lcd.begin(16, 2);
  lcd.print("Timer: 00:00");
}

void loop() {
  char key = keypad.getKey();

  if (key == '1') {
    timerMinutes += 10;
  } else if (key == '2') {
    timerMinutes += 60;
  } else if (key == '3') {
    timerMinutes -= 1;
    if (timerMinutes < 0) {
      timerMinutes = 0;
    }
  } else if (key == '4') {
    timerActive = !timerActive;
    if (timerActive) {
      lastTime = millis();
    } else {
      timerMinutes = 0;
    }
  }

  // Update timer display
  int hours = timerMinutes / 60;
  int minutes = timerMinutes % 60;
  lcd.setCursor(6, 0);
  lcd.print(hours, DEC);
  lcd.print(":");
  lcd.print(minutes, DEC);

  // Check if timer is active and time has elapsed
  if (timerActive && millis() - lastTime >= timerMinutes * 60000) {
    lightOn = true;
    digitalWrite(relayPin, HIGH);
  }

  // Turn off light after 24 hours
  if (lightOn && millis() - lastTime >= 24 * 60 * 60 * 1000) {
    lightOn = false;
    digitalWrite(relayPin, LOW);
    timerMinutes = 0;
    timerActive = false;
  }

  // Play buzzer for feedback
  if (lightOn) {
    digitalWrite(buzzerPin, HIGH);
  } else {
    digitalWrite(buzzerPin, LOW);
  }
}

This code is designed to run on an Arduino Nano and controls the relay, buzzer, and LCD based on input from a keypad. It includes a timer function that can be set and activated using the keypad. When the timer is active and the set time elapses, the relay is turned on, which in turn switches on the bulb. The buzzer provides audible feedback when the light is on. The LCD displays the current timer setting.