Timer

Start 

This project yields a programmable timer.

Modules 

Gather the following parts to complete this project.

Parts

All Parts
All Parts
LCD Display
Button
Rotary potentiometer
Piezo Buzzer
Cable
PartQuantity
LCD Display 1
Button 1
Rotary potentiometer 1
Piezo Buzzer 1
Cable 4

A Countdown 

Let's start with the most simple timer. Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket. Take another cable and unwrap it. Plug one side into the button socket and the other into Digital socket D6.

All the parts you'll need
All the parts you'll need
Take a cable...
... and unwrap it
Plug one side into the LCD Display socket
... and the other into any I2C socket
Take a cable...
... and unwrap it
Plug one side into the button socket
... and the other into Digital socket D6

Upload

Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
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
#include <Wire.h>
#include "rgb_lcd.h"

//Change here if you're using a different socket
#define buttonSocket 6

int milliseconds;
int Time;
int seconds;

int Seconds(int milliseconds) {
  seconds = milliseconds / 1000;
  return seconds;
}

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

void setup()
{
  pinMode(buttonSocket, INPUT);
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  Serial.begin(9600);

}

void loop()
{
  Serial.println(Time);
  lcd.setRGB(colorR, colorG, colorB);
  lcd.setCursor(0, 0);
  lcd.print("Press to start:");
  lcd.setCursor(0, 1);
  lcd.print(" ");
  Time = 10;
  if (digitalRead(buttonSocket)) {
    while (Time > 0) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Time remaining:");
      lcd.setCursor(0, 1);
      lcd.print("       ");
      lcd.setCursor(0, 1);
      lcd.print(Time);
      delay(1000);
      Time = Time - 1;
      Serial.println(Time);
    }
    while (!digitalRead(buttonSocket)) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Time is up!     ");
      lcd.setCursor(0, 1);
      lcd.print("       ");
    }
    delay(100);
  }
}

Observe

After pressing the button, the countdown will begin. The clock ticks down in seconds.

The screen shows the starting text
The screen shows the starting text
And with a press of the button...
... the countdown starts
A message when the time is up

Modify

Changing the time value in the code will change the countdown.

Adding Some Sound 

Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D8.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the buzzer socket
... and the other into Digital socket D8

Upload

Upload the code shown below. This tutorial uses Digital socket 8. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
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
#include <Wire.h>
#include "rgb_lcd.h"

//If you use different sockets change them below
#define buttonSocket 6
#define buzzerSocket 8

int Time;

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

void setup()
{
  pinMode(buttonSocket, INPUT);
  pinMode(buzzerSocket, OUTPUT);
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);

}

void loop()
{
  lcd.setRGB(colorR, colorG, colorB);
  lcd.setCursor(0, 0);
  lcd.print("Press to start:");
  lcd.setCursor(0, 1);
  lcd.print(" ");
  Time = 10;
  digitalWrite(buzzerSocket, LOW);
  if (digitalRead(buttonSocket)) {
    while (Time > 0) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Time remaining:");
      lcd.setCursor(0, 1);
      lcd.print("       ");
      lcd.setCursor(0, 1);
      lcd.print(Time);
      delay(1000);
      Time = Time - 1;
    }
    while (!digitalRead(buttonSocket)) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Time is up!     ");
      lcd.setCursor(0, 1);
      lcd.print("       ");
      digitalWrite(buzzerSocket, HIGH);
    }
    delay(100);
  }
}

Observe

When the timer has reached the end of its countdown, the buzzer turns on. A button press will reset it.

Alarming!Alarming!

Adding some control 

Now we'll add a rotary potentiometer so we can set the timer amount without needing a computer. Take a cable and unwrap it. Plug one side into the rotary potentiometer and the other into Analog socket A3.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the rotary potentiometer socket
... and the other into Analog socket A3

Upload

Upload the code below. This tutorial uses Analog socket A3. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
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
#include <Wire.h>
#include "rgb_lcd.h"

//Change here if you're using a different socket
#define buttonSocket 6
#define buzzerSocket 8
#define dialSocket A3

int Time;

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

void setup()
{
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);

  pinMode(buttonSocket, INPUT);
  pinMode(buzzerSocket, OUTPUT);
}

void loop()
{
  digitalWrite(buzzerSocket, LOW);
  lcd.setRGB(colorR, colorG, colorB);
  lcd.setCursor(0, 0);
  lcd.print("Timer Amount:   ");
  lcd.setCursor(0, 1);
  lcd.print("       ");
  lcd.setCursor(0, 1);
  lcd.print((map(analogRead(dialSocket), 0, 1024, 0, 3600)));
  delay(100);
  if (digitalRead(buttonSocket)) {
    Time = (map(analogRead(dialSocket), 0, 1024, 0, 3600));
    while (Time > 0) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Time remaining:");
      lcd.setCursor(0, 1);
      lcd.print("       ");
      lcd.setCursor(0, 1);
      lcd.print(Time);
      delay(1000);
      Time = Time - 1;
    }
    while (!digitalRead(buttonSocket)) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Time is up!");
      lcd.setCursor(0, 1);
      lcd.print("       ");
      digitalWrite(buzzerSocket, HIGH);
    }
  }
}

Observe

Now the timer amount can be set to any amount between 0 and 3600 seconds (one hour).

Changeable!Changeable!

Modify

Changing the maxTime variable will change what time range can be chosen.