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

Arduino UNO-Based Timer with Rotary Encoder and LCD Display for Relay Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Timer with Rotary Encoder and LCD Display for Relay Control

Circuit Documentation

Summary

This circuit is designed to control a relay using an Arduino UNO, a rotary encoder, and a 16x2 LCD display. The circuit also includes a current sensor and a trimmer potentiometer for additional functionality. The Arduino UNO is programmed to read inputs from the rotary encoder and display the information on the LCD. The relay is controlled based on the inputs and the current sensor readings.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Rotary Encoder

    • Description: A device that converts the angular position or motion of a shaft to an analog or digital code.
    • Pins: clk, dt, sw, gnd, +
  3. 16x2 LCD

    • Description: A liquid crystal display that can display 16 characters per line and has 2 lines.
    • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
  4. 1-Channel Relay (5V 10A)

    • Description: A relay module that can control high voltage devices with a low voltage signal.
    • Pins: NC, signal, C, power, NO, ground
  5. Trimmer Potentiometer

    • Description: A variable resistor used to adjust the level of voltage in a circuit.
    • Pins: leg1, wiper, leg2
    • Properties: Resistance: 10000 Ohms
  6. AC Supply

    • Description: A power supply that provides alternating current.
    • Pins: +ve, -ve
  7. Current Sensor 5A

    • Description: A sensor that measures the current flowing through a circuit.
    • Pins: 1, 2, GND, OUT, VCC

Wiring Details

Arduino UNO

Rotary Encoder

16x2 LCD

1-Channel Relay (5V 10A)

Trimmer Potentiometer

AC Supply

Current Sensor 5A

Code Documentation

#include <LiquidCrystal.h>
#include <EEPROM.h>

LiquidCrystal lcd(8, 7, 6, 5, 4, 3);

#define outputA 10 // clk pin of rotary encoder
#define outputB 11 // dt pin of rotary encoder
#define button 2   // sw pin of rotary encoder
#define led 13     // status led
#define relay 12   // in1 of relay

int count = 1;
int current_state;
int previous_state;
int hh = 0;
int mm = 0;
int ss = 0;
int h = 0;
int m = 0;
int s = 0;
int ledToggle;
int previousState = HIGH;
unsigned int previousPress;
volatile int buttonFlag;
int buttonDebounce = 20;

void setup() {
  lcd.begin(16, 2);
  pinMode(outputA, INPUT);
  pinMode(outputB, INPUT);
  pinMode(button, INPUT_PULLUP);
  pinMode(led, OUTPUT);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  attachInterrupt(digitalPinToInterrupt(2), button_ISR, CHANGE);
  Serial.begin(9600);
  previous_state = digitalRead(outputA);

  if (EEPROM.read(0) != 0 || EEPROM.read(1) != 0 || EEPROM.read(2) != 0) {
    lcd.setCursor(0, 0);
    lcd.print("Load Preset ?");
    lcd.print(" ");
    lcd.setCursor(0, 1);
    lcd.print("      <NO>      ");
    int temp = 5;
    while (temp > 0 && ledToggle == 0) {
      lcd.setCursor(14, 0);
      lcd.print(temp);
      temp--;
      delay(1000);
    }
    if (temp == 0 && ledToggle == 0) {
      hh = EEPROM.read(0);
      mm = EEPROM.read(1);
      ss = EEPROM.read(2);
      timer();
    } else {
      EEPROM.write(0, 0);
      EEPROM.write(1, 0);
      EEPROM.write(2, 0);
      ledToggle = 0;
    }
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" HH  MM  SS  OK ");
  lcd.setCursor(0, 1);
  lcd.print(" 0   0   0      ");
}

void loop() {
  encoder();
  if (count == 1) {
    lcd.setCursor(0, 0);
    lcd.print("<HH> MM  SS  OK ");
    while (count == 1) {
      encoder();
      if (ledToggle) {
        h = 1;
        m = 0;
        s = 0;
        lcd.setCursor(0, 0);
        lcd.print(" HH  MM  SS  OK ");
        lcd.setCursor(1, 1);
        lcd.print(hh);
        lcd