First own big Code for an LCD Countdown Timer

Hey guys!

I searched a long time on google. etc. but i haven't found a nice Countdown Timer for my LCD(16x2).I needed
it for an exposure unit to make my PSB's(you beam the Layout with UV-Light on the Foto-resist).
But i haven't found anything so i maked it by myself.

The Countdowntimer:

  • 2 row LC-Display with 16 coloumns
  • Input of time over an 100k Poti(A0)
  • 1 Row : "Text you like" + show off the Set-time in minutes and seconds
  • 2.Row : shows the running Countdown
  • button to reset the Timer and adjust the Time( without debounce )
  • Output to switsch an Relais (for the UV-Tube)

there's only the LiquidCrystal Library inbound (no Timer.h, etc.)

also i send the Layout and the Circuit plan of my Project.
eventually i make an Photo of it.

Have fun!

PS: sorry for the bad english and the German Comments. An english version of the code will be coming.

/*****************************Intro************************************
///Countdowntimer version 1.0
   
   Ein einfacher Timer der mit einem LC-Display, einem 100k Potentiometer,
   einem einfachen Taster als Eingang und einem schaltenden Ausgang 
   ausgestattet ist.
   
   In dieser Konfiguration lässt sich die Zeit über den Poti an A0(PC0,Pin 23) 
   von 00:00 min bis ca. 17:05 min einstellen.
   Die Konfiguration lässt sich in "void_readAin" umstellen.
   
   Ein (nicht entprellter) Highaktiver Taster an 8(PB0,Pin 14) dient als Eingang.
   Drücken = A/D Wert des Potis übernehmen und in den Timer schreiben 
     -> negative Flanke : Timer starten/Ausgang 13(PB5,Pin 19)High setzen
   Drücken und Halten = A/D Wert einstellen
   nach ablauf des Timers = Ausgang 13(PB5,Pin 19) Low setzen
 
   Verdrahtung:
   
   Poti 100k (10Gang) = Schleifer=> A0/Pin 23; Anfang/Ende=>5V/GND
   Taster mit 10K Pulldown Widerstand => 8/Pin 14
   Ausgang => 13/Pin 19
   LCD => siehe Unten 

**********************************************************************/

#include <LiquidCrystal.h>

//----LCD-PINS---(rs, en,d4,d5,d6,d7)----------------------// 
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); 

//-------------------- Taster/Ausgänge --------------------//

int varpin = A0;
int buttonstate;
int const buttonPin = 8;                 // Resetbutton Pin Deklarierung
int uvout = 13;                          // Ausgang für UV-Licht

//----------------Variablen für Countdown------------------//

int long countdowntime;                  // Countdown Variable bzw. Resetwert
int val;                                 // Variable für aktuellen Zustand 
int lastval;                             // Variable für den vorherigen Zustand
int long minutes;                        // Countdown in Minuten
int long seconds;                        // Countdown in Sekunden
volatile unsigned char tick;             // Variable für den Timer
int inputtime ;                          // Variable für analogeingang     


//--------------- Timer Überlauf auslesen ------------------//

ISR (TIMER2_OVF_vect)                    // Wenn Timer 1 Überläuft gib ein High über
{	                 
  ++tick;	                         // tick aus.		    
}

void setup() {
  inputtime = analogRead(varpin);        // analogwert einlesen  
  countdowntime = 0;                     // Starte bei 00:00
  lcd.begin(16, 2);                      // initialisiere Display
  lcd.setCursor(0,0);                    // setze Cursor für 1. Zeile
  lcd.print("Time:");                    // Beschriftung der ersten Zeile
  readAin ();                            // Analogwert eintragen 
}


void loop()
{
  buttonstate = digitalRead(buttonPin);    // auslesen des Digitalwertes an Pin 7
  val = digitalRead(tick);                 // Overflow des Timers auslesen
  
if (buttonstate != HIGH)                 
{
  lcd.setCursor(0, 0);                     // erste Zeile
  lcd.print("Time:");                      // Schreibe "Time:" 
  
  if (countdowntime<=0);                   // wenn 'countdowntime 0 
  {                                        //
    digitalWrite(uvout, LOW);              // schalte UV-Licht aus 
  }                                        //
 
  if (countdowntime>0)
  {       
    if (val != lastval)                   // wenn sich 'val' von 'lastval' unterscheidet
    {                                     //
      countdowntime--;                    // inkrementiere 'countdowntime'
      digitalWrite(uvout, HIGH);          // schalte UV-Licht ein
    }                                     //
     
    lcd.setCursor(0,1);                   // Setze Cursor für Countdown
    printTime();                          // gebe Zeit aus  
        

    val = lastval;                        // aktuellen Zustand merken   
    delay(1000);                           // 1 sekunde Pause
  }
}

else
{  
  lcd.setCursor(0,0);          
  lcd.print("SET : ");                     // "Time:" zu "Set :" ändern

  lcd.setCursor(5, 0);                     // Cursor hinter "Set :" setzen
  readAin();                               // Schreibe Set-Time
  
  countdowntime = inputtime;               // reset
    
}
}



void printTime ()
{
  minutes = countdowntime/60;           // Aufteilung von 'countdowntime' in Minuten
  seconds = countdowntime%60;           // und Sekunden 
        
  if (minutes<10)                       // wenn minuten unter 10
  {                                     //   
    lcd.print('0');                     // schreibe "0" vor minuten
  }                                     //
         
  lcd.print(minutes);                   // gebe Minuten aus
  lcd.print(":");                       // schreibe ":"
      
  if (seconds<10)                       // wenn Sekunden unter 10 
  {                                     //  
    lcd.print("0");                     // schreibe erst Null und dann
    lcd.print(seconds);                 // die Sekunden
    lcd.write(' ');                     // entferne Werte nach sekunden 
  }                                     //
  else                                  //
  {                                     //
    lcd.print(seconds);                 // schreibe die Sekunden normal
    lcd.print(" ");                     //
  }                                     // 
  
}

void readAin ()
{
inputtime = analogRead(varpin);           // Analogwert in 'inputtime' schreiben 
int showminutes = inputtime /60;          // inputtime/60 = showminutes = Minuten ausrechnen
int showseconds = inputtime %60;          // inputtime%60 = showseconds = Sekunden ausrechnen

 if (showminutes<10)                      // wenn 'showminutes' unter 10
 {                                        //
   lcd.print('0');                        // schreibe erst "0" 
 }                                        //
 
lcd.print(showminutes);                   // schreibe 'showminutes'
   
lcd.print(":");                           // schreibe ":"
    
if (showseconds<10)                       // wenn 'showseconds' unter 10
 {
   lcd.print("0");                        // schreibe erst Null
   lcd.print(showseconds);                // dann die Sekunden
   lcd.write(' ');                        // entferne letzte Ziffer 
 }
 else                                     // wenn nicht
 {                                        //
   lcd.print(showseconds);                // schreibe die Sekunden normal
   lcd.print(" ");                        // und lösche die Ziffer dahinter
 }
 delay(150);                              // Verlangsame den kompletten vorgang
 
}

LCD-Countdown Timer Bestückungsplan.pdf (80.6 KB)

LCD-Countdown Timer Layout.pdf (54 KB)

LCD-Countdown Timer Schaltplan.pdf (16.4 KB)