Introduction: Kitchen Timer

Picture of Kitchen Timer

Kitchen timer is a simple gadget never thought of breaking down, but it eventually will be. Though it is cheap I have no interest to buy a new one, I asked myself can I make one for my own? Checking the parts stock found all I need were available, the arduino uno, OLED display, one buzzer, 3 push button, 1 on-off switch and 9V battery.

This instructable do not describe on how to make it but more on the arduino code, lets look at the major function of kitchen timer, in the photo though it has Chinese characters, you don't have to understand it known the usage, the two white button set the minutes, top one to count up, down one to count down, when two were pressed reset to zero, the red button start the count and press it again to pause it.

Step 1: The Schematic

Picture of The Schematic

I like to provide the schematic, please noted that my OLED has 4 pins only must connect the vcc to 3.3V output, the 3 push buttons were connected with common ground, simple enough. To cope with the broken timer, I maintained minute and second readout, but actually I only count the minutes, the seconds only for the timer activity to let you known it is working now. The only thing I have the implemented is the reset function, I used the power on-off switch to replace it, the OLED and UNO are not power saving, so when you are not using it, just switch it off.

Step 2: Arduino Code

Picture of Arduino Code

I used not to provide code except my own creation, I have not reference to other code of similar functionality, so it is 100% diy. The part before setup are library definition, pins initialization and variable declaration.

#include <Wire.h>
#include <Adafruit_GFX.H>

#include <Adafruit_SSD1306.h>

#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)

#error("Height incorrect, please fix Adafruit_SSD1306.h!");

#endif

#define buzzer 7

#define upButton 8

#define downButton 9

#define startButton 10

int minutes = 0; //initial value displayed

int seconds = 0; //initial value displayed

boolean halted; //stop buzzer

Step 3: Void Setup()

Picture of Void Setup()

In the setup defined the pinMode, initialized the OLD and displayed the initial time, beeped the buzzer for ready

void setup() {

// put your setup code here, to run once:

pinMode (buzzer, OUTPUT);

pinMode (upButton, INPUT);

pinMode (downButton, INPUT);

pinMode (startButton, INPUT);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) displayTime(minutes, seconds);

tone(buzzer, 600, 200);

}

Step 4: Void Loop()

Picture of Void Loop()

In the loop function the push buttons are pull up to HIGH, when it pushed trigger 3 subroutines to preform the functions, upTime() to increase one minute, downTime() to decrease one minute, the maximum minutes is 99, I think it is reasonable enough for general use, the last function countTime() will start down count the minute by up count the second.

void loop() {

// put your main code here, to run repeatedly:

halted=false;

digitalWrite(upButton, HIGH);

digitalWrite(downButton, HIGH);

digitalWrite(startButton,HIGH);

if (digitalRead(upButton)==LOW) upTime(); //read button

delay(100);

if (digitalRead(downButton)==LOW) downTime(); //read button

delay(100);

if (digitalRead(startButton)==LOW && minutes>0)

countTime(minutes, seconds); //copy the minutes

delay(100);

displayTime(minutes, seconds);

}

Step 5: Void UpTime() DownTime()

These two functions need not explain, but bewared that the minutes variable is a global variable, it can only be changed by functions.

void upTime() { //adjust the minutes only
tone(buzzer, 1200, 200);

minutes++;

if (minutes>99) minutes=0; //max 99 minutes

displayTime(minutes, 0);

}

void downTime() { //adjust the minutes only

tone(buzzer, 1200, 200);

minutes--;

if (minutes<0) minutes=99;

displayTime(minutes, 0);

}

Step 6: Void CountTime()

The countTime function start up count the second and down count the minute, this function requires two variables, the setMinutes and the setSeconds, setSeconds is always zero when it called the function, setMinutes is copied from the minutes variable where it will be set up or set down by push buttons but will not alter and remain the same within time count. This function included the routine to sound the buzzer when the time ended, within count time or buzzer sound you can press the start button to stop it.

void countTime(int setMinutes, int setSeconds) {

tone(buzzer, 600, 200);

digitalWrite(startButton,HIGH); //reset startButton

delay(500);

do {

if (digitalRead(startButton)==LOW) { //break countTime

tone(buzzer, 600, 200);

halted=true; //stop buzzer

break;

} else {

setSeconds++;

displayTime(setMinutes, setSeconds);

delay (1000);

if (setSeconds>59) {

setSeconds=0;

setMinutes--; //minutes not altered

}

}

} while (setMinutes>0);

displayTime(0, setSeconds);

if (halted==false) {

for (int x = 0; x<=200; x++) {

if (digitalRead(startButton)==LOW) { //stop buzzer

break;

} else {

tone(buzzer,1200);

delay(50);

tone(buzzer,600);

delay(50);

}

}

noTone(buzzer);

delay(200);

}

}

Step 7: Void DisplayTime()

The last function is to display the minute and second in OLED, I used two text size for easy recognization,

void displayTime (int setMinutes, int setSeconds) {
display.setTextColor(WHITE);

display.clearDisplay();

display.setTextSize(4);//text size

display.setCursor (15,2); //col , row

display.print(setMinutes);

display.setCursor (63,3); //col , row

display.print(":"); display.setTextSize(3);//text size

display.setCursor (85,8); //col , row

display.print(setSeconds);

display.display();

}

Comments

tytower (author)2017-08-12

Please put the complete ".ino" file up to make it easy to copy

About This Instructable

752views

14favorites

License:

More by martinhui:Kitchen TimerESP8266 Wall Clock 2.0Easy Wire Wrap Tools
Add instructable to: