Introduction: Kitchen Timer Using an Arduino
If you like cooking and have the habit of leaving the gas stove on for too long, this could be a serious problem because no one likes burnt food. To solve this problem I'm going to show you how to build your own kitchen trimmer that is powered by an Arduino.
This kitchen timer is very easy to build and can count down to a maximum duration of 30 minutes, the maximum duration can be changed by altering the code. And when the time interval is reached the timer fires a buzzer, reminding you to keep an eye on the food.
Step 1: Materials Required
For this project you will need -
- An Arduino UNO
- Breadboard
- LEDs
- A small buzzer
- A 10K Resistor
- Some Jumper wires
Step 2: Schematics
The circuit for this instructable can be found above, six LEDs are attached to digital pin 4 to 9 and the buzzer is connected to digital pin 3. The switch to start the timer is connected to digital pin 2. We have to use a push button switch for this project.
Step 3: Code
The code can be found in the attachments, make sure you select the right port while uploading the code and if this your first time using and Arduino you will need to download the Arduino IDE and install the drivers that come along with the Arduino IDE. The serial port to which the Arduino is connected can be found in the device manager if you are running windows.
<p>const int buttonPin = 2; // the number of the pushbutton pin<br>const int ledPin = 13; // the number of the LED pin const int led2Pin = 12; const int led3Pin = 11; const int led4Pin = 10; // the number of the LED pin const int led5Pin = 9; const int led6Pin = 7; const int led7Pin = 6; // the number of the LED pin const int led8Pin = 5; const int led9Pin = 4; const int led10Pin = 3; const int speakerOut = 1; // variables will change: int buttonState = 0; // variable for reading the pushbutton status int tastyTimeVariable = 0; // my time variable that has 1 added int i; int n; void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); pinMode(led2Pin, OUTPUT); pinMode(led3Pin, OUTPUT); pinMode(led4Pin, OUTPUT); pinMode(led5Pin, OUTPUT); pinMode(led6Pin, OUTPUT); pinMode(led7Pin, OUTPUT); pinMode(led8Pin, OUTPUT); pinMode(led9Pin, OUTPUT); pinMode(led10Pin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); pinMode(speakerOut, OUTPUT); delay(3000); } void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(ledPin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led2Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led3Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led4Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led5Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led6Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led7Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led8Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led9Pin, HIGH); } else { } delay(1000); buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { // add to timer tastyTimeVariable = tastyTimeVariable + 1; digitalWrite(led10Pin, HIGH); } else { } delay(1000); digitalWrite(led10Pin, LOW); digitalWrite(led9Pin, LOW); digitalWrite(led8Pin, LOW); digitalWrite(led7Pin, LOW); digitalWrite(led6Pin, LOW); digitalWrite(led5Pin, LOW); digitalWrite(led4Pin, LOW); digitalWrite(led3Pin, LOW); digitalWrite(led2Pin, LOW); digitalWrite(ledPin, LOW); delay(1000); if (tastyTimeVariable == 0) { } else if (tastyTimeVariable == 1) { digitalWrite (ledPin, HIGH); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } } else if (tastyTimeVariable == 2) { digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable == 3) { digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable == 4) { digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable == 5) { digitalWrite (led5Pin, HIGH); digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led5Pin, LOW); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable == 6) { digitalWrite (led6Pin, HIGH); digitalWrite (led5Pin, HIGH); digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led6Pin, LOW); delay(300L * 1000L); digitalWrite (led5Pin, LOW); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable == 7) { digitalWrite (led7Pin, HIGH); digitalWrite (led6Pin, HIGH); digitalWrite (led5Pin, HIGH); digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led7Pin, LOW); delay(300L * 1000L); digitalWrite (led6Pin, LOW); delay(300L * 1000L); digitalWrite (led5Pin, LOW); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable == 8) { digitalWrite (led8Pin, HIGH); digitalWrite (led7Pin, HIGH); digitalWrite (led6Pin, HIGH); digitalWrite (led5Pin, HIGH); digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led8Pin, LOW); delay(300L * 1000L); digitalWrite (led7Pin, LOW); delay(300L * 1000L); digitalWrite (led6Pin, LOW); delay(300L * 1000L); digitalWrite (led5Pin, LOW); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); //sound alarm } else if (tastyTimeVariable == 9) { digitalWrite (led9Pin, HIGH); digitalWrite (led8Pin, HIGH); digitalWrite (led7Pin, HIGH); digitalWrite (led6Pin, HIGH); digitalWrite (led5Pin, HIGH); digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led9Pin, LOW); delay(300L * 1000L); digitalWrite (led8Pin, LOW); delay(300L * 1000L); digitalWrite (led7Pin, LOW); delay(300L * 1000L); digitalWrite (led6Pin, LOW); delay(300L * 1000L); digitalWrite (led5Pin, LOW); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); //sound alarm } else if (tastyTimeVariable == 10) { digitalWrite (led10Pin, HIGH); digitalWrite (led9Pin, HIGH); digitalWrite (led8Pin, HIGH); digitalWrite (led7Pin, HIGH); digitalWrite (led6Pin, HIGH); digitalWrite (led5Pin, HIGH); digitalWrite (led4Pin, HIGH); digitalWrite (led3Pin, HIGH); digitalWrite (led2Pin, HIGH); digitalWrite (ledPin, HIGH); delay(300L * 1000L); digitalWrite (led10Pin, LOW); delay(300L * 1000L); digitalWrite (led9Pin, LOW); delay(300L * 1000L); digitalWrite (led8Pin, LOW); delay(300L * 1000L); digitalWrite (led7Pin, LOW); delay(300L * 1000L); digitalWrite (led6Pin, LOW); delay(300L * 1000L); digitalWrite (led5Pin, LOW); delay(300L * 1000L); digitalWrite (led4Pin, LOW); delay(300L * 1000L); digitalWrite (led3Pin, LOW); delay(300L * 1000L); digitalWrite (led2Pin, LOW); delay(300L * 1000L); for (i=0; i < 20; i++) { analogWrite(speakerOut,128); delay(250); digitalWrite(speakerOut, LOW); delay(250); } //sound alarm } else if (tastyTimeVariable > 10) { } }</p>
Step 4: Testing
After uploading the code the project is now complete, now it is time to test it. Power on the project and click the button once now the timer should start counting down for five minutes. To increase the timer duration click the button multiple times each time you click the timer will increment by 5 minutes.