Simple Arduino Timer

by madnerd in Circuits > Arduino

16822 Views, 51 Favorites, 0 Comments

Simple Arduino Timer

Simple Timer
lcdclock.jpg

Need a timer to check how much times you spent on a task ?
Or maybe you want to make a clock without a RTC module ?

I didn't find a code to make one easily so I share mine.
This is also a good test to check if your DFRobot LCD Keypad Shield works correctly and learn how to use it.

  • First, we will upload our code
  • Then, we will see how to use our timer.
  • Aftewards, i'll explain how to use the LCD/Keypad
  • Finally, I'll explain how to manage time

As always documentation and code are available in english/french on http://github.com/pigetArduino/lcdclock

Make It!

dfrobot_lcdshield.png

Components

  • Arduino Uno : 6€
  • DF Robot LCD Keypad shield : 4€

Total : 10€

You should find theses components easily on most E-commerce using these keywords
DF Robot shield is already soldered, you only have to plug it on the Arduino Uno.

Upload

Download the software, libraries and upload the code with Arduino

  • Download : http://lcdclock.madnerd.org
  • Copy lcdclock and libraries folder into your arduino sketchbook (Documents/Arduino)
  • Upload lcdclock.ino

Board : Arduino/Genuino Uno

  • The led on the LCD Keypad can be removed, if you find it too bright.
  • We didn't make a 3D printed case for this project, but you can find some on thingiverse.com

Manual

lcdtimer_manual.png

Here is a manual on how to use the timer.

  • LEFT: -1 minute
  • RIGHT: +1 minute
  • UP: +1 hour
  • DOWN -1 hour
  • RST: Reset timer
  • Select: Turn off/on backlight

You can use this manual as a template for your own projects:
Download: shield-manual.svg

Every illustrations / text in my tutorial are licence as Creative Commons (by) and available with the source code in the folder docs/

Feel free to use it in your own tutorials!

Control the LCD/Keypad

All libraries on my projects are included with the source code.

Official DFRobot manual : https://www.dfrobot.com/wiki/index.php/LCD_KeyPad_Shield_For_Arduino_SKU:_DFR0009

LCD

  • Setup screen
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup(){
	lcd.begin(16, 2);
}
  • Print Text
lcd.print("Hello World")
  • Set Cursor Position
lcd.setCursor(column,row)

KeyPad

  • Setup
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

//Buttons are all on Analog0
int read_LCD_buttons(){
  adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 555)  return btnLEFT;
  if (adc_key_in < 790)  return btnSELECT;
  return btnNONE;  // when all others fail, return this...
}
Check keypress
void loop(){
 lcd_key = read_LCD_buttons();  // read the buttons
 switch (lcd_key){              // depending on which button was pushed, we perform an action
   case btnRIGHT:{
	//Right button action
        break;
  }
   case btnLEFT:{
       //Left button action
       break;
  }
   case btnUP:{
      //Up Button action
      break;
  }

   case btnDOWN:{
      //Down Button action
      break;
  }
  case btnSELECT:{
     //Select Button action
     break;
  }
 }
}

Manage Time

To manage the time , we are using timelib
https://github.com/PaulStoffregen/Time

  • Setup
//setTime(hr,min,sec,day,mnth,yr);
setTime(0,0,0,1,1,2000);
  • Get time
void loop(){
	now(); //Get current time
	
	Serial.println(hour());
	Serial.println(minute());
	Serial.println(second());
}