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

Arduino Nano-Based Smart Timer with LCD Display and Relay Control

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Smart Timer with LCD Display and Relay Control

Circuit Documentation

Summary

This circuit is designed to control a 1-Channel Relay using an Arduino Nano, which in turn controls a bulb. The circuit also includes an I2C LCD 16x2 screen for displaying information, a buzzer for audio feedback, and multiple pushbuttons for user input. The Arduino Nano is programmed to manage the relay, display timer information on the LCD, and provide feedback through the buzzer.

Component List

  1. 1-Channel Relay (5V 10A)

    • Pins: NC, signal, C, power, NO, ground
    • Description: A relay module used to control high voltage devices with a low voltage signal.
  2. I2C LCD 16x2 Screen

    • Pins: SCL, SDA, VCC (5V), GND, VDD, VO, RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7, BLA, BLK
    • Description: A 16x2 character LCD screen with I2C interface for displaying information.
  3. Pushbutton

    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
    • Description: A simple pushbutton used for user input.
  4. Bulb

    • Pins: positive, negative
    • Description: A bulb used as an indicator or light source.
  5. Buzzer

    • Pins: PIN, GND
    • Description: A buzzer used for audio feedback.
  6. Arduino Nano

    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
    • Description: A small, complete, and breadboard-friendly microcontroller board based on the ATmega328.
  7. 240v Power Source

    • Pins: Live, Neutral
    • Description: A power source providing 240V AC.

Wiring Details

1-Channel Relay (5V 10A)

I2C LCD 16x2 Screen

Pushbutton

Bulb

Buzzer

Arduino Nano

240v Power Source

Code Documentation

#include <Wire.h>
#include <LiquidCrystal_I2C.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 switch1Pin = 10;
const int switch2Pin = 11;
const int switch3Pin = 12;
const int switch4Pin = 13;

// Initialize LCD and keypad
LiquidCrystal_I2C lcd(0x27, 16, 2); // Assuming the I2C address is 0x27
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 initializes the pins for the