Shervin Shahbazi
Published © GPL3+

Arduino Pomodoro Timer

Distraction... Begone!!

IntermediateFull instructions provided3,634
Arduino Pomodoro Timer

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Resistor 330 ohm
Resistor 330 ohm
×3
LED (generic)
LED (generic)
×3
Pushbutton Switch, Pushbutton
Pushbutton Switch, Pushbutton
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Product

This is a model for what the product could look like through 3D design.

Schematics

Arduino Pomodoro Setup - Tinkercad

This is what the breadboard looks like when all components are attached.

Code

Pomodoro Arduino Timer Code

Arduino
Save this then upload it onto Arduino.
int red = 11;
int yellow = 12;
int white = 13;
int Red = LOW;
int White = LOW;
long previousMillis = 0;
long interval;
int buttonState = 1;
int buttonPin = 2;
bool prs = 0;
long time = 0;
int phase = 0;

void setup() {
 pinMode(red, OUTPUT);
 pinMode(yellow, OUTPUT);
 pinMode(white, OUTPUT); 
 pinMode(buttonPin, INPUT_PULLUP);
 digitalWrite(buttonPin, HIGH);
}

void loop() {
// this will update the current time and state of the button
unsigned long currentMillis = millis();
int buttonState = digitalRead(buttonPin);
// it measures the time since the last button press
long progress = currentMillis - previousMillis;
// checks out whether a button has been pressed over 2 seconds since last press so it prevents multiple presses registering
if ((time - currentMillis) > 2000){
 if(buttonState == 0){
   prs = 1;
   time = currentMillis;}
 else{
    prs = 0;}
}
// phase 0 is the studying time
// if button has been pressed, add 2 minutes to study timer
if (phase == 0){
 if (prs == 1){
   interval = 1500000;}
 // if the interval ends, record current the time for measuring  the next interval 
 if(currentMillis - previousMillis > interval) {
   previousMillis = currentMillis; 
 // sets the white and red LED states
 if (White == LOW){
   White = HIGH;
   Red = LOW;}
 else {
   White = LOW;}
 // applies LED states to LEDs then resets interval and switch to break phase
 digitalWrite(white, White);
 digitalWrite(red, Red);
 interval = 1380000;
 buttonState = 1;
 phase = 1;
 }
}
else {
 // if the button has been pressed, add 2 minutes to break timer
 if (prs == 1){
 interval = 420000;}
   // if the interval is over, record the current time for measuring the next interval 
   if(currentMillis - previousMillis > interval) {
     previousMillis = currentMillis;
   // sets red and white LED states
   if (Red == HIGH){;
     Red = LOW; }
   else {
     Red = HIGH;
     White = LOW;}
 // applies LED states to LEDs then resets interval and sets it to study phase
 digitalWrite(white, White);
 digitalWrite(red, Red);
 interval = 300000;
 buttonState = 1;
 phase = 0;
 }
}
// calculates the  time left in the interval
unsigned long timeLeft = (interval - progress);
// if there is less than two minutes left, yellow LED lights up
if (timeLeft < 120000) {
  digitalWrite(yellow, HIGH); }
else {
  digitalWrite(yellow, LOW); }
// reset the pressed variable for next time
 prs = 0;
}

Credits

Shervin Shahbazi
0 projects • 6 followers
Contact

Comments

Please log in or sign up to comment.