pomodoro technique — is a popular time management system that involves breaking down work into 25-minute chunks with a 5-minute rest. There are various software for this, but what if you want to use the pomodoro system when you are away from your computer or in your workplace? Building an Arduino powered Pomodoro timer is a great introductory project to help you learn how to navigate Arduino and you’ll end up with something useful as a result.

Target

If you want to try and figure out how to set this up before looking to the future, here’s what we’re trying to do. We will have three lights; one for «work», one for «break», and a signal light. The work light will be on for 25 minutes and the indicator light will also be on for the last two minutes of this interval. After 25 minutes, the work and warning lights will turn off and the shutdown indicator will turn on for 5 minutes (the warning light will be on again for the last two minutes).

There will also be a button included that will delay lamp changes by two minutes to give you a bit of extra work time or a break.

What you need

For this project, we will be using the following parts — everything you should have in your starter kit.

  • Arduino microcontroller (we used Mega, but Uno would work fine too)
  • mock up
  • USB cable
  • 6 wires
  • 3 x 330 ohm resistors
  • 3 LEDs (we used green, yellow and blue)
  • 1 button

Step 1: Setting everything up

Place each of the LEDs in a separate column on the breadboard (it’s easiest if they’re spaced a bit), and place the button a little further down. Make sure the button is pointing in the right direction — there are two sets of two pins on one side of the button, and those pins should be in the same row.

pomoduino-setup1

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). Then place a resistor in the same column as each positive leg and connect them to the negative rail on the side of the breadboard (blue, although the color doesn’t really matter, it’s common to use blue for clarity). ,

pomoduino-setup2

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

pomoduino-setup3

Here is a diagram that should clear up any confusion:

pomoduino

This is it! Now about programming.

Programming Your Arduino

Below is the Pomoduino timer code — read the inline comments as they explain what each step of the code does.

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 test this, you probably don't want to wait 25 minutes to see if it works. In the video below, I have intervals set to 5 seconds for green, 2 seconds for blue, and 1 second for yellow. Use a shorter interval to make sure everything is working properly before using it for time tracking!

Once you have everything set up and the code entered into the IDE, you are ready to go! Upload the sketch and you'll have a working pomodoro timer with a 2-minute delay button. If the warning light comes on and you need more time, just press the button.

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

More complex tasks

If you've made Pomoduino and want to take something more advanced, you can try any of the following:

Other projects for beginners

If you are new to Arduino, we have many interesting tutorials for you. Try a traffic light controller futuristic led cube, sunrise alarm or alarm system . If you decide to solve one of the more difficult tasks listed above, let us know how it goes!

Похожие записи