Adjustable Rotary Encoder Timer

A countdown timer that can change value using a Rotary Encoder

COMPONENTS AND SUPPLIES

Rotary Encoder

1

4 Digit Display Module

1

InventrKits HERO

The HERO is a derivative of “Arduino UNO R3 Reference design” we just changed up a few things to make it our own. If you’re curious about what goes into our HERO board we published the open-source hardware files on our GitHub.

1

Male to Female Wire

9

ABOUT THIS PROJECT

A countdown timer that can change value using a Rotary Encoder

SCHEMATICS

Rotary Encoder countdown timer

COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *

#include <TM1637.h> // Define the connections pins: #define CLKSeg 10 #define DIOSeg 11 #define CLKRE 6 #define DTRE 7 #define SWRE 5 TM1637 tm(CLKSeg,DIOSeg); // Create array that turns all segments on: int countPress = 0; //holds how many times the Rotary Encoder switch is pressed int countStatus = 0; //Timer Status int sec; //Countdown in second value int timeVal = 9; //display value (will be changed to 5 if the display is on tens value on seconds: 00:X0) int customTime[4]; //four integers values of the 7 segment display int counter = 0; int aState; int aLastState; void setup() { Serial.begin(9600); pinMode (CLKRE,INPUT); pinMode (DTRE,INPUT); pinMode (SWRE,INPUT); tm.init(); tm.set(2); boot(); } void loop(){ if (countStatus != 0) //Start countdown if countStatus == 1, can be changed o bool { displayTime(); } else { GetREVal(); //Get Encoder values } } void displayTime() //decrements total seconds, converts into minute format and shows into display { int minutes = sec / 60; int seconds = sec % 60; tm.display(3, seconds % 10); tm.display(2, seconds / 10 % 10); tm.point(1); tm.display(1, minutes % 10); tm.display(0, minutes / 10 % 10); if(sec <= 0) { alarmHere(); //Runs the alarm function } else { sec–; } delay(1000); } void GetREVal() //Gets Rotary Encoder Value { aState = digitalRead(CLKRE); // Reads the “current” state of the outputA // If the previous and the current state of the outputA are different, that means a Pulse has occured if (aState != aLastState){ // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise if (digitalRead(DTRE) != aState) { counter ++; } else { counter –; } if (counter > timeVal) //timeVal is always = 9 unless the selection is on first digit of the seconds (00:X0 – X can only be on maximum of 6 because 60 sec is max) { counter = 0; } else if (counter < 0) { counter = timeVal; } tm.display(countPress, counter); } aLastState = aState; // Updates the previous state of the outputA with the current state if (digitalRead(SWRE) == LOW) //if Rotary Encoder button is pressed { if (countPress != 4) //if Rotary Encoder is not pressed 4 times { if (countPress == 1) //If you pressed the Rotary encoder for the 2nd time { timeVal = 5; //Maximum value shown in the seven segment should be 5 delay(300); tm.display(countPress, counter); //show number in the display customTime[countPress] = counter; countPress = countPress + 1; } else // If the Rotary encoder is not pressed on the 2nd time { timeVal = 9; //Maximum value for shown is the display should always be 9 delay(300); tm.display(countPress, counter); customTime[countPress] = counter; countPress = countPress + 1; } } else // if Encoder switch is pressed four times { sec = Getval(); //get the total time in seconds format countStatus = 1; //start the timer } } } int Getval() //Compute the total time in seconds { int totalMin = (customTime[0] * 10) + customTime[1]; //Minute time in tens x 10 + Minutes in ones = total minutes int valSec = (customTime[2] * 10) + customTime[3]; //Second time in tens x 10 + Second in ones = total extra seconds int totalSec = (totalMin *60) + valSec; //total minutes * 60 secs + extra seconds = total seconds to countdown return totalSec; } void boot() //display 00:00 at start { tm.display(3, 0); tm.display(2, 0); tm.point(1); tm.display(1, 0); tm.display(0, 0); } void alarmHere() //put code here for custom alarm or timer end { }
PROJECT AUTHOR
Leave a comment
TEAM MEMBERS
Belrey Dahonog

Coding and Circuit Design

TABLE OF CONTENTS
Leave a comment
Share on whatsapp
Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on pinterest
Share on email

SIMILAR PROJECTS YOU MIGHT LIKE

I cascaded four SN74HC595 shift registers to control 32 LEDs on 4 registers using 3 wires. I am adding a I2C 20×4 LCD screen to display the register and led values. I might add a standard 16×2 LCD screen to show up it is done.
A simple light meter. It’s not calibrated to any meaningful scale, but the digital readout shows a higher number the brighter is the light falling on the photoresistor.