Project is not available for free download! If you are interested in purchasing the software part of the project with the functionality described on the given page, contact: martinius96@gmail.com
Arduino LCD Stopwatch Firesport Schematics Code Eagle

Stopwatch for fire sport through Arduino


  • I have to guess every village or part of the city.
  • Every week, especially during the summer season, village competitions take place and teams score valuable points, achievements and failures, which are also decided by one hundredth of a second.
  • My stopwatch implementation uses millis, an internal Arduino timer that returns milliseconds since the processor started.
  • So we can measure the time to 2 decimal places, ie perform timing every 10ms, which is 0.01 seconds.
  • The problem, however, is the speed and limits of the I2C bus, the display itself, and of course the program calculations.
  • The system logic is performed every 10 or 100 milliseconds, depending on the software. (10 milliseconds - accuracy to 100ths, 100 milliseconds, transmission to tenths of a second)
  • The stopwatch has a 32-millisecond display problem. Since Arduino is not a multi-core processor, 3-hundredths are skipped. Can't do 2 things at once.
  • Therefore, I recommend that you only display the display once per second, or at action (stopwatch, clear time).
  • System functionality:

  • Stopwatch is started by a button (it can be replaced by a signal gun, the second button can stop and reset the time.
  • 2 make contacts located on the targets are activated when the target falls, stopping the left / right current on the stopwatch.
  • The last button is used to reset the time - reset the time, new team.
  • The stopwatch cannot in any way replace a certified stopwatch!

    What does the project use from the technical (hardware) side of the project?

  • Arduino Uno, or a separate AtMega chip (Scheme is compatible for Arduino Uno, Nano, Mega)
  • 16x2 or 20x4 LCD display with I2C converter
  • 2 buttons
  • 2 make contacts
  • Due to multiple source theft and unauthorized author changes, the source code will no longer be available!

    Stopwatch in action:

    Stopwatch to one hundredth of a second Stopwatch for tenths of a second

    Lib (I2C) LCD 16x2, 20x4

    Stopky na desatiny sekundy - verzia projektu zdarma. Stopky na stotiny sekundy sú platenené.

    /*|------------------------------------------------------------------------------------------|*/
    /*|VYHOTOVIL: MARTIN CHLEBOVEC                                                               |*/
    /*|HASICSKE STOPKY - VERZIA ZDARMA - NA DESATINY SEKUNDY S CASOM PRE DVA UTOKY - LAVY/PRAVY  |*/
    /*|FUNGUJE NA PRINCIPE FUNKCIE MILLIS() A VYKONAVANI KRATKYCH PROGRAMOVYCH CYKLOV            |*/
    /*|INPUT PULLUP ZAPOJENIE S 50kohm INTERNAMY REZISTOROM (PODLA SCHEMY)                       |*/
    /*|PROGRAM FUNGUJE PRE ZASTAVENIE A SPUSTENIE OBOCH CASOV JEDNYM TLACIDLOM                   |*/
    /*|PROGRAMOVU LOGIKU SI MOZETE UPRAVIT PRE OVLADANIE CASOV SAMOSTATNYMI KONTAKTMI NA TERCOCH |*/
    /*|PRI ZAUJME O VERZIU NA STOTINY (PRESNÉ) NA PLATFORME ESP32 --> martinius96@gmail.com      |*/
    /*|Doska: Arduino Uno, Nano, Mega, AtMega328P (Hardware I2C)                                 |*/
    /*|WEB: https://arduino.php5.sk/hasicske-stopky.php                                          |*/
    /*|PODPORA PROJEKTU PRE UVOLNENIE PLNEJ VERZIE ZDARMA: https://www.paypal.me/chlebovec       |*/
    /*|------------------------------------------------------------------------------------------|*/
    
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    //I2C adresa, stlpce, riadky, pouziva sa i 0x3F pre displej 20x4, 0x27 pre 16x2, skontruj cez I2C scanner https://playground.arduino.cc/Main/I2cScanner/
    LiquidCrystal_I2C lcd(0x3F, 20, 4);
    
    //DEKLARACIA DIGITALNYCH PINOV NA KTORE SU NAPOJENE TLACIDLA
    const int start_tlacidlo = 12;
    const int lavy_terc_kontakt = 11;
    const int pravy_terc_kontakt = 10;
    const int vynulovat_cas_tlacidlo = 9;
    
    boolean run = false;         //bezi cas pre LAVY UTOK?
    boolean run2 = false;         //bezi cas pre PRAVY UTOK?
    
    //STAVY NACITANYCH LOGICKYCH HODNOT TLACIDIEL
    int start_tlacidlo_stav = HIGH;
    int lavy_terc_kontakt_stav = HIGH;
    int pravy_terc_kontakt_stav = HIGH;
    int vynulovat_cas_tlacidlo_stav = HIGH;
    
    unsigned long timer = 0; //timer
    
    //PREMENNE PRE PRVY CAS - LAVY UTOK
    int second = 0;
    int minute = 0;
    int tenth = 0;
    
    //PREMENNE PRE DRUHY CAS - PRAVY UTOK
    int second2 = 0;
    int minute2 = 0;
    int tenth2 = 0;
    
    void setup() {
      lcd.begin(); //incializacia displeja na I2C zbernici
      lcd.backlight(); //zapnutie podsvietenia
      pinMode(start_tlacidlo, INPUT_PULLUP); //nastav ako vstup proti internemu 50kohm pullup rezistoru
      pinMode(lavy_terc_kontakt, INPUT_PULLUP);
      pinMode(pravy_terc_kontakt, INPUT_PULLUP);
      pinMode(vynulovat_cas_tlacidlo, INPUT_PULLUP);
      lcd.setCursor(0, 0); //nastav kurzor pre zapis na 1. riadok, 1. stlpec
      lcd.print("00:00:0 L. PRUD");
      lcd.setCursor(0, 1); //nastav kurzor pre zapis na 2. riadok, 1. stlpec
      lcd.print("00:00:0 P. PRUD");
    }
    
    void tickClock() {
      Serial.println(millis() / 10);
      if ((timer - millis() / 100) >= 100 || timer == 0) {
        tick();
        timer = millis() / 100;
      }
    }
    
    void loop() {
      tickClock();
      start_tlacidlo_stav = digitalRead(start_tlacidlo);
      lavy_terc_kontakt_stav = digitalRead(lavy_terc_kontakt);
      pravy_terc_kontakt_stav = digitalRead(pravy_terc_kontakt);
      vynulovat_cas_tlacidlo_stav = digitalRead(vynulovat_cas_tlacidlo);
      checkStart();
    }
    
    void checkStart() {
      if (start_tlacidlo_stav == LOW ) {
        run = true; //aktivuj cas pre lavy prud
        run2 = true; //aktivuj cas pre pravy prud
      }
      if (lavy_terc_kontakt_stav == LOW ) {
        run = false;
      }
      if (pravy_terc_kontakt_stav == LOW ) {
        run2 = false;
      }
      if (vynulovat_cas_tlacidlo_stav == LOW ) {
        run = false;
        run2 = false;
        second = 0;
        minute = 0;
        tenth = 0;
        second2 = 0;
        minute2 = 0;
        tenth2 = 0;
        updateLCD();
        updateLCD2();
      }
    }
    
    
    void tick() { //tick sa vykonava kazdych 100 miliseund, teda kazdu desatinu sekundy
      //LOGIKA BEZIACEHO CASU PRVEHO UTOKU (UTOK LAVY)
      if (run) {
        updateLCD();
        if (tenth == 9) {
          tenth = 0;
          if (second == 59) {
            second = 0;
            minute++;
          } else {
            second++;
          }
        } else {
          tenth++;
        }
      }
    
      //LOGIKA BEZIACEHO CASU DRUHEHO UTOKU (UTOK PRAVY)
      if (run2) {
        updateLCD2();
        if (tenth2 == 9) {
          tenth2 = 0;
          if (second2 == 59) {
            second2 = 0;
            minute2++;
          } else {
            second2++;
          }
        } else {
          tenth2++;
        }
      }
    }
    
    //VYPIS PRVEHO UTOKU NA DISPLEJ (UTOK LAVY)
    void updateLCD() {
      lcd.setCursor(0, 0);
      if (minute < 10) {
        lcd.print("0");
      }
      lcd.print(minute, DEC);
      lcd.print(":");
      if (second < 10) {
        lcd.print("0");
      }
      lcd.print(second, DEC);
      lcd.print(":");
      lcd.print(tenth, DEC);
    }
    
    //VYPIS DRUHEHO UTOKU NA DISPLEJ (UTOK PRAVY)
    void updateLCD2() {
      lcd.setCursor(0, 1);
      if (minute2 < 10) {
        lcd.print("0");
      }
      lcd.print(minute2, DEC);
      lcd.print(":");
      if (second2 < 10) {
        lcd.print("0");
      }
      lcd.print(second2, DEC);
      lcd.print(":");
      lcd.print(tenth2, DEC);
    }
    

    Schéma zapojenia (Eagle):

    Schéma zapojenia pre hasičské stopky - Arduino