Pinterest Stumbleupon Whatsapp
Ads by Google

The pomodoro technique Cut Through Procrastination With These Pomodoro Technique Apps & Software Cut Through Procrastination With These Pomodoro Technique Apps & Software Procrastination is a malady that pervades students and workers in all corners of the world and it infects amateurs and professionals alike. As a writer, I suffer from procrastination on a daily basis. Some people... Read More is a popular time management system that involves breaking work into 25 minute chunks with a 5 minute rest. Various software exists to help with this, but what if you want to use the pomodoro system while you’re working away from your computer, or while you’re at your workbench? Making an Arduino-powered pomodoro timer is a great introductory project 10 Great Arduino Projects for Beginners 10 Great Arduino Projects for Beginners Completing an Arduino project gives you a sense of satisfaction like no other. Most beginners aren't sure where to start though, and even beginner's projects can seem rather daunting. Read More to help you learn your way around an Arduino, and will actually result in something useful.

The Goal

In case you’d like to try to figure out how to set this up before looking ahead, here’s what we’re trying to do. We’ll have three lights; one for “work,” one for “break,” and a warning light. The work light will stay on for 25 minutes, and the warning light will also be on for the last two minutes of that interval. After 25 minutes, the work and warning lights will turn off, and the break light will turn on for 5 minutes (the warning light will again be on for the last two minutes).

Also included will be a button that will delay the change of the lights for two minutes to give you a little extra work time or break time.

What You Need

For this project, we’ll be using the follow parts – all of which you should have in your starter kit.

  • Arduino microcontroller (we used a Mega, but Uno would work just fine too)
  • Breadboard
  • USB cable
  • 6 wires
  • 3 x 330 Ohm resistors
  • 3 x LED (we’ve used green, yellow, and blue)
  • 1 pushbutton

Step 1: Setting Everything Up

Put each of the LEDs into a different column on the breadboard (it’s easiest if they’re spaced out a bit), and place the button a little further down. Make sure that the button is facing the right direction—there are two sets of two pins on a single side of the button, and those pins need to be in the same row.

pomoduino-setup1

Ads by Google

Run wires from pins 5, 7, and 13 to the column that contains the negative leg of the blue, yellow, and green LEDs (the negative leg is the shorter of the two). Next, put a resistor in the same column as each positive leg, and connect them to the negative rail on the side of the breadboard (the blue one, though the color doesn’t really matter, it’s just convention to use blue for clarity).

pomoduino-setup2

Also run a wire from the blue rail on the breadboard to one of the legs on the button, and another wire from the other leg (on the same side) to pin 2 on the Arduino. Then ground the blue rail into the GND pin on the Arduino.

pomoduino-setup3

Here’s a diagram that should clear up any confusion:

pomoduino

That’s it’s! Now on to the programming.

Programming Your Arduino

Below is the code for the Pomoduino timer – have a read through the inline comments, as they explain what each step of the code is doing.


int green = 13;
int yellow = 7;
int blue = 5;

int ledStateGreen = LOW;
int ledStateBlue = LOW;
long previousMillis = 0;
long interval;

int buttonPin = 2;
int buttonState = 1;
bool pressed = 0;
long pressTime = 0;

int phase = 0;

void setup() {
 pinMode(green, OUTPUT);
 pinMode(yellow, OUTPUT);
 pinMode(blue, OUTPUT);
 pinMode(buttonPin, INPUT_PULLUP);
 digitalWrite(buttonPin, HIGH);
}

void loop() {
 
// update current time and state of button
unsigned long currentMillis = millis();
int buttonState = digitalRead(buttonPin);

// measure time since last button press
long progress = currentMillis - previousMillis;

// check to see if button has been pressed
// over 2 seconds since last press
// (to prevent multiple presses registering)
if ((pressTime - currentMillis) > 2000){
 if(buttonState == 0){
   pressed = 1;
   pressTime = currentMillis;}
 else{
    pressed = 0;}
}

// phase 0 is "work" phase
// if button has been pressed, add 2 minutes to work timer
if (phase == 0){
 if (pressed == 1){
   interval = 1620000;}
 
 // if interval is over, record current
 // time for measuring next interval 
 if(currentMillis - previousMillis > interval) {
   previousMillis = currentMillis; 

 // set green and blue LED states
 if (ledStateGreen == LOW){
   ledStateGreen = HIGH;
   ledStateBlue = LOW;}
 else {
   ledStateGreen = LOW;}

 // apply LED states to LEDs
 // reset interval and switch to "break" phase
 digitalWrite(green, ledStateGreen);
 digitalWrite(blue, ledStateBlue);
 interval = 1500000;
 buttonState = 1;
 phase = 1;
 }
}

else {
 
 // if button has been pressed, add 2 minutes to break timer
 if (pressed == 1){
 interval = 420000;}
 
   // if interval is over, record current
   // time for measuring next interval 
   if(currentMillis - previousMillis > interval) {
     previousMillis = currentMillis; 

   // set blue and green LED states
   if (ledStateBlue == HIGH){;
     ledStateBlue = LOW; }
   else {
     ledStateBlue = HIGH;
     ledStateGreen = LOW;}

 // apply LED states to LEDs
 // reset interval and set to "work" phase
 digitalWrite(green, ledStateGreen);
 digitalWrite(blue, ledStateBlue);
 interval = 300000;
 buttonState = 1;
 phase = 0;
 }
}

// calculate time left in interval
unsigned long timeLeft = (interval - progress);

// if there are less than two minutes left, light up yellow LED
if (timeLeft < 120000) {
  digitalWrite(yellow, HIGH); }
else {
  digitalWrite(yellow, LOW); }

// reset pressed variable
 pressed = 0;
}

Note: when you’re testing this, you probably don’t want to wait for 25 minutes to see if it works. In the video below, I have the intervals set to 5 seconds for green, 2 seconds for blue, and 1 second for yellow. Use a shorter interval to make sure everything’s working correctly before you use it to keep track of time!

Once you have everything wired up and the code entered into the IDE, you’re ready to go! Upload the sketch and you’ll have a working pomodoro timer with a 2-minute delay button. If the warning light goes on and you need more time, just hit the button.

You may notice that the button is wired up directly to the Arduino input pin. By using one of the pullup resistors built into the Arduino, you don’t need to run a wire from the 5V port to the button or use a resistor in line with it. You can get more information on the Arduino reference for digital pins.

More Advanced Challenges

If you’ve made your Pomoduino and you’re looking to take on something slightly more advanced, you could try any of the following:

  • Add a sequence of LEDs that light up and serve as a counter of the number of completed work sessions
  • Make the button add two minutes to the timer for each time you push it
  • Add a speaker and play a noise when it’s time to get back to work
  • Use a 9V battery to make it portable
  • Instead of using a warning light, blink the green or blue light for a minutes before switching
  • Display a countdown on an LED display

Other Great Beginner Projects

If you’re new to Arduino, we have plenty of fun tutorials for you to take on. Try a traffic light controller Arduino Programming For Beginners: The Traffic Light Controller Arduino Programming For Beginners: The Traffic Light Controller Last week, we learnt about the basic structure of an Arduino program and took a closer look at the 'blink' example. Hopefully you took the opportunity to experiment with code, adjusting the timings. This time,... Read More , a futuristic LED cube How To Make a Pulsating Arduino LED Cube That Looks Like It Came From The Future How To Make a Pulsating Arduino LED Cube That Looks Like It Came From The Future If you’ve dabbled with some beginner Arduino projects, but are looking for something a little permanent and on a whole other level of awesome, then the humble 4 x 4 x 4 LED cube is... Read More , a sunrise alarm Arduino Night Light and Sunrise Alarm Project Arduino Night Light and Sunrise Alarm Project Today, we'll be making a sunrise alarm clock, which will gently and slowly wake you without resorting to an offensive noise-making machine. Read More , or an alarm system How To Make a Simple Arduino Alarm System How To Make a Simple Arduino Alarm System Detect movement, then scare the heck out of an intruder with a high pitched alarm sounds and flashing lights. Does that sound fun? Of course it does. That's the goal of today's Arduino project, suitable... Read More . If you decide to take on one of the more advanced challenges listed above, let us know how it goes!

  1. Harry Hutton
    July 22, 2015 at 8:30 pm

    Hey! Not sure if this is just my computer but the text box you put the code into above is only one line thick.

    Whenever I paste it into my program I get a huge single line of code. Separating it out with the enter button is a bit time consuming, and if you don't do it right certain bits of code get commented out by //.

    Just thought i'd let you know in case anyone else has the same issue in future.

    • Dann Albright
      July 25, 2015 at 2:48 pm

      Thanks for pointing that out! I'll see if I can fix it.

    • James Bruce
      July 25, 2015 at 2:57 pm

      Hi Harry, I'm looking into fixing this, but in the meantime, here it is in a pastebin: http://pastebin.com/caQ71RYV

Leave a Reply

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