You are here:Home » Arduino Adjustable Countdown Timer With I2S LCD, Rotary Encoder and RTC module By Abhishek Ghosh Updated on Advertisem*nt Creating an adjustable countdown timer with an Arduino using an I2C LCD, rotary encoder, pushbuttons with interrupt handling, two status LEDs, and an RTC module to control a relay requires careful management of interrupts for responsive button handling while maintaining accurate timing. It is an advanced project. The person going to create it requires to know few theories and previous work experience I2C LCD, interrupt and RTC module. Here are related theories which can help you: For this project, we can not give you a Tinkercad simulation since RTC module, rotary encoder etc are absent in Tinkercad. The wiring is quite easy if you look at the sketch. Advertisem*nt --- Ensure you have the following libraries installed via the Arduino Library Manager: Vim 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 // under GNU GPL 3.0 License // Code written by Abhishek Ghosh // Website: https://thecustomizewindows.com // // #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <RTClib.h> #include <Encoder.h> // Define pins for rotary encoder #define ENCODER_PIN1 A0 #define ENCODER_PIN2 A1 #define BUTTON_PIN A2 // Define pins for pushbuttons using interrupts #define START_STOP_PIN 2 #define RESET_PIN 3 // Define pins for LEDs #define LED_RUNNING_PIN 4 #define LED_COMPLETE_PIN 5 // Initialize objects LiquidCrystal_I2C lcd(0x3F, 16, 2);// Adjust address and size as per your LCD RTC_DS3231 rtc; Encoder encoder(ENCODER_PIN1, ENCODER_PIN2); volatile bool startStopPressed = false; volatile bool resetPressed = false; // Timer variables int countdownMinutes = 0; unsigned long countdownEndTime = 0; bool timerRunning = false; void setup() { lcd.begin(); lcd.backlight(); pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(START_STOP_PIN, INPUT_PULLUP); pinMode(RESET_PIN, INPUT_PULLUP); pinMode(LED_RUNNING_PIN, OUTPUT); pinMode(LED_COMPLETE_PIN, OUTPUT); attachInterrupt(digitalPinToInterrupt(START_STOP_PIN), startStopInterrupt, FALLING); attachInterrupt(digitalPinToInterrupt(RESET_PIN), resetInterrupt, FALLING); // Initialize RTC if (!rtc.begin()) { lcd.print("RTC not found!"); while (1); } } void loop() { // Read rotary encoder long encoderValue = encoder.read(); if (encoderValue > 0) { countdownMinutes++; } else if (encoderValue < 0 && countdownMinutes > 0) { countdownMinutes--; } // Check if start/stop button was pressed if (startStopPressed) { startStopPressed = false; if (!timerRunning) { startTimer(); } else { stopTimer(); } } // Check if reset button was pressed if (resetPressed) { resetPressed = false; resetTimer(); } // Update LCD display updateDisplay(); // Check if timer has ended if (timerRunning && millis() >= countdownEndTime) { timerRunning = false; digitalWrite(LED_COMPLETE_PIN, HIGH); // Activate relay or perform any action when timer completes (optional) } } void startStopInterrupt() { startStopPressed = true; } void resetInterrupt() { resetPressed = true; } void startTimer() { countdownEndTime = millis() + (countdownMinutes * 60000); // Convert minutes to milliseconds timerRunning = true; digitalWrite(LED_RUNNING_PIN, HIGH); digitalWrite(LED_COMPLETE_PIN, LOW); } void stopTimer() { timerRunning = false; digitalWrite(LED_RUNNING_PIN, LOW); } void resetTimer() { countdownMinutes = 0; stopTimer(); digitalWrite(LED_COMPLETE_PIN, LOW); } void updateDisplay() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Set Timer: "); lcd.print(countdownMinutes); lcd.print(" min"); lcd.setCursor(0, 1); lcd.print("Status: "); if (timerRunning) { lcd.print("Running"); } else { lcd.print("Stopped"); } } Setup and Initialization: Initializes all necessary components including the LCD, RTC, rotary encoder, pushbuttons, and LEDs. The interrupt service routines (ISRs) are attached to the start/stop and reset buttons to handle their actions immediately upon press. Loop Function: Reads input from the rotary encoder to adjust the countdown time. Interrupt Service Routines (ISRs): Timer Control Functions: Display Update: Updates the LCD display to show the current countdown time and timer status (running or stopped). Ensure the interrupt pins ( Use volatile variables ( Customize LCD initialization ( Extend functionality by adding more buttons for additional features like pause, resume, etc. This sketch provides a foundation for building an adjustable countdown timer using interrupts for responsive button handling while maintaining accurate timing and display updates on an I2C LCD. Adjust and expand it further based on your specific project requirements and hardware setup. Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL. Some theory better to know before buying rotary encoders. Here Is Rotary Encoder For Dummies Guide Intended For Arduino, Raspberry Pi Users. Create a Arduino Temperature & Humidity Sensor DHT 11 With LCD 1602A Following Few Steps. Circuit Diagram, Code and Helpful Step by Step Guide For Troubleshooting. This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx. Here is How To Convert LCD Display to LCD Serial Display For Arduino. You Can Convert Your Existing LCD to Serial With a Simple Module or By Using Components. performing a search on this website can help you. Also, we have YouTube Videos. We'd love to know your thoughts on this article. If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us. Contact UsComponents Needed For This Project
Suggested final design.
Image is from
https://forum.arduino.cc/t/ardunio-8x-relay-timer-with-i2c-20×4-lcd-rotary-encoder/77097Libraries Required
Required Code/Sketch
Checks flags (startStopPressed
and resetPressed
) set by the interrupt service routines to execute corresponding functions (startTimer()
, stopTimer()
, resetTimer()
).
Updates the LCD display with current timer status.startStopInterrupt()
: Sets startStopPressed
flag when the start/stop button is pressed.resetInterrupt()
: Sets resetPressed
flag when the reset button is pressed.startTimer()
: Calculates the end time of the countdown based on the set minutes and starts the countdown.stopTimer()
: Stops the countdown timer.resetTimer()
: Resets the countdown timer and stops it.
Countdown Completion: When the countdown timer reaches zero (millis()
reaches countdownEndTime
), the timerRunning
flag is set to false. Optionally, an action can be performed such as lighting up an LED (LED_COMPLETE_PIN
) or triggering a relay.START_STOP_PIN
and RESET_PIN
) are connected to the correct pins on your Arduino board and configured correctly in attachInterrupt
.startStopPressed
and resetPressed
) for flags accessed within both the main loop and interrupt service routines to ensure proper handling of shared data.LiquidCrystal_I2C lcd(0x3F, 16, 2);
) based on your LCD module’s address and size.
Incorporate the RTC module to synchronize the timer with real-time if precise timing is critical.About Abhishek Ghosh
Here’s what we’ve got for you which might like :
Articles Related to Arduino Adjustable Countdown Timer With I2S LCD, Rotary Encoder and RTC module
Take The Conversation Further ...
Meet the Author over on Twitter to join the conversation right now!
Arduino Adjustable Countdown Timer With I2S LCD, Rotary Encoder and RTC module (2024)
Table of Contents
Components Needed For This Project
Libraries Required
Required Code/Sketch
Here’s what we’ve got for you which might like :
Take The Conversation Further ...
Top Articles
A $40 Million Batman Shopping Experience Lets Superfans Buy Bruce Wayne’s Supercar, Superstereo And More
Box Office: ‘Inside Out 2’ Scores $100 Million in Sensational Second Weekend
Eastbourne 2024: Emma Raducanu saves match point on way to first top-10 win against Jessica Pegula
Mum 'killed children, 7 and 11, because she didn't want husband to have them'
Tennessee Pictures and Facts
Tennessee Maps & Facts
Potato Shaders 1.19.4 → 1.18.2 (Shader Pack for Low-End PCs) — Shaders Mods
Best Minecraft shaders for version 1.20
Zuercher Portal Inmates Clinton Iowa
RCS – RECYCLED CLAIM STANDARD - ReSOURCE
Latest Posts
Flags, Symbols, & Currency of Jamaica
Nearly 2 million people stranded as devastating floods hit Bangladesh | CNN
Article information
Author: Ouida Strosin DO
Last Updated:
Views: 6788
Rating: 4.6 / 5 (76 voted)
Reviews: 83% of readers found this page helpful
Author information
Name: Ouida Strosin DO
Birthday: 1995-04-27
Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795
Phone: +8561498978366
Job: Legacy Manufacturing Specialist
Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet
Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.