Arduino Nano-Based Smart Timer with LCD Display and Relay Control
View and Edit Project In Cirkit Designer
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-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.
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.
Pushbutton
- Pins: Pin 2, Pin 1, Pin 3, Pin 4
- Description: A simple pushbutton used for user input.
Bulb
- Pins: positive, negative
- Description: A bulb used as an indicator or light source.
Buzzer
- Pins: PIN, GND
- Description: A buzzer used for audio feedback.
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.
240v Power Source
- Pins: Live, Neutral
- Description: A power source providing 240V AC.
Wiring Details
1-Channel Relay (5V 10A)
- signal connected to Arduino Nano D3
- C connected to 240v Power Source Live
- power connected to I2C LCD 16x2 Screen VCC (5V) and Arduino Nano 5V
- NO connected to bulb positive
- ground connected to Pushbutton Pin 4, I2C LCD 16x2 Screen GND, Pushbutton Pin 4, Pushbutton Pin 4, Pushbutton Pin 4, and Arduino Nano GND
I2C LCD 16x2 Screen
- SCL connected to Arduino Nano A5
- SDA connected to Arduino Nano A4
- VCC (5V) connected to 1-Channel Relay (5V 10A) power and Arduino Nano 5V
- GND connected to 1-Channel Relay (5V 10A) ground, Pushbutton Pin 4, Pushbutton Pin 4, Pushbutton Pin 4, Pushbutton Pin 4, and Arduino Nano GND
Pushbutton
- Pin 4 connected to 1-Channel Relay (5V 10A) ground, I2C LCD 16x2 Screen GND, Pushbutton Pin 4, Pushbutton Pin 4, Pushbutton Pin 4, and Arduino Nano GND
- Pin 1 connected to Arduino Nano D10
- Pin 1 connected to Arduino Nano D11/MOSI
- Pin 1 connected to Arduino Nano D13/SCK
- Pin 1 connected to Arduino Nano D12/MISO
Bulb
- positive connected to 1-Channel Relay (5V 10A) NO
- negative connected to 240v Power Source Neutral
Buzzer
- PIN connected to Arduino Nano D2
- GND connected to Arduino Nano GND
Arduino Nano
- D3 connected to 1-Channel Relay (5V 10A) signal
- 5V connected to 1-Channel Relay (5V 10A) power and I2C LCD 16x2 Screen VCC (5V)
- GND connected to 1-Channel Relay (5V 10A) ground, I2C LCD 16x2 Screen GND, Pushbutton Pin 4, Pushbutton Pin 4, Pushbutton Pin 4, Pushbutton Pin 4, and Buzzer GND
- A5 connected to I2C LCD 16x2 Screen SCL
- A4 connected to I2C LCD 16x2 Screen SDA
- D10 connected to Pushbutton Pin 1
- D11/MOSI connected to Pushbutton Pin 1
- D13/SCK connected to Pushbutton Pin 1
- D12/MISO connected to Pushbutton Pin 1
- D2 connected to Buzzer PIN
240v Power Source
- Live connected to 1-Channel Relay (5V 10A) C
- Neutral connected to bulb negative
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