Project by Matt; IR Break-Beam Stopwatch

Matt87317 just shared a new project: "IR Break-Beam Stopwatch"



This project is a simple stopwatch with a little bit of a twist! It operates like a conventional stopwatch… you can start and stop it, you can record lap times and you can review the lap times once you hit stop.
The twist is that this stopwatch has an IR break-beam sensor. When the beam is broken by (for example) a person running through the beam, it will trigger the Arduino to record a lap time!

Read more

8 Likes

Hey Matt,

Awesome project! Excellent use of the screen, super accessible to makers!

I’m keen to see some remixes!

Liam.

4 Likes

Hi Liam135720,

Glad you like it. I had to do a lot of my own study to figure out how to build my flyball timer.

This Arduino version enables me to share what I learned on a smaller and much more affordable scale.

Makers can adapt the IR break beam to trigger all sorts of things… all they need is some imagination.

5 Likes

Hey Matt,

Nice project! Thanks for sharing!

As an idea, I’d suggest integrating some distance-based speed calculations into the GUI as an additional modification to make to your project. Do you have any links to the tutorials/documentation that you used to set that GUI up?

I’ve had a read through the project page and didn’t see any links to it and just a little curious for a few of my own projects :sweat_smile:

1 Like

Hey Bryce,

The GUI I used for the flyball timer was made using the “tkinter” library on Python 3.

It was the best documented GUI library. Coding was the most difficult part of the project, and I read through many books and did online tutorials until I had enough information to make my interface.

I used paint.net graphic software for creating the background, light display and time display windows.

All I can advise you to do is work your way through some online tutorials for tkinter… it’s such a huge topic, my project is just the tip of the iceberg.

I think the book is titled “Python for Kids” written by Jason R Briggs. The final project in that book is a platform game written with tkinter. That book helped a lot.

Regards,
Matt

2 Likes

Hey Matt,

Thanks for letting us know. I figured it’d be one of the more popular python libraries given that you’re running it on a Pi.

One other potential option I’d suggest is generating a small web server on your Pi with the appropriate libraries and then passing the information to the document that is being presented there so you can view it from any device on your local network:

https://pythonbasics.org/webserver/

It’s actually much simpler than it sounds, and with some basic CSS (likely embedded at the top of the HTML) you can easily style it and add all kinds of interesting features with some basic embedded javascript. If you’re looking to do any work with front-end web development, this is certainly a brilliant first project to dive into:

3 Likes

Hello again Bryce,

Thanks for the links. I haven’t done any electronic stuff for quite some time now as I’ve been occupied with other things.
It was the middle of last years lockdown when I made the scaled-down Arduino version of my project… the flyball timer
was the year before that!

I considered re-writing the flyball timer software using C instead of Python, but I found it too difficult to source the

information I needed… not to mention that C is more difficult than Python overall! As you know, C is compiled where Python

runs via an interpreter, so software written in C would run faster and give me more accurate timing!

Trying to re-create the GUI using GTK-inter (a GUI library for C) is an entire project in it’s own right. Also, there is very little information
out there on using C to control the GPIO pins on the PI. This left me dead in the water.

IF I ever build another flyball timer, I would use an ESP32 micro controller to do the job.
From what I’ve read, they can be a stand-alone web server which would allow me to control the timer and see the timing

results via any device with WiFi or Bluetooth connection (depending on HOW you set it up). All I would need is my phone.

The website http://www.randomnerdtutorials.com is run by Rui and Sara Santos. They have written a number of ebooks
about projects using Arduinos and RPIs, but they specialise in ESP8266 and ESP32.
It would take a lot of time, but I’m sure the information I need to get a flyball timer 2.0 working with an ESP32 is in their
ebooks.

Regards,
Matt.

Bryce
30 November

Matt87317:

GUI I used for the flyball timer was made using the “tkinter” library on Python 3.

Hey Matt,

Thanks for letting us know. I figured it’d be one of the more popular python libraries given that you’re running it on a Pi.

One other potential option I’d suggest is generating a small web server on your Pi with the appropriate libraries and then passing the information to the document that is being presented there so you can view it from any device on your local network:

https://pythonbasics.org/webserver/

It’s actually much simpler than it sounds, and with some basic CSS (likely embedded at the top of the HTML) you can easily style it and add all kinds of interesting features with some basic embedded javascript. If you’re looking to do any work with front-end web development, this is certainly a brilliant first project to dive into:

https://www.youtube.com/embed/UB1O30fR-EE

https://www.youtube.com/embed/yfoY53QXEnI

3 Likes

Would it be possible to do it for 3 objects with 3 sensors (1 for each object) and show it on the LCD keypad shield?
can you guide me?

4 Likes

Hi EDUARDO201739

In order to work for tracking different objects, you would need some way for the timer to differentiate between the objects.

This would require more components and coding.

I haven’t tried to do it before, but I would start with RFID card reader.

If the objects you wish to track can pass by the card reader close enough (and you can attach an RFID card to each object), then you should be able to keep individual time records for each one.

4 Likes

I only have the lcd keypad, arduino uno and the 3 infrared sensors. is there really no way to do it? what a pity

2 Likes

Hi Eduardo,

Another option that might work is - If you were to use 3 seperate ‘channels’ for racers then you could keep the starting time in their own variables and once they cross the finish line the difference is calculated giving times for three objects.

Along with Matt’s awesome project I’d use the Arduino Workshop to help craft your remix.

Liam

1 Like

Hello again @EDUARDO201739

If you could tell me more precisely HOW you intend to use the timer, I can be of more help.
I have a couple of new thoughts to share:-

IF the ‘objects’ you are measuring the time on are in their own lanes, then it may not be so complicated to expand on my project.
My idea is to build an IR breakbeam for each lane… with it’s own IR LED and IR receiver. You would shine the LED directly onto the receiver… no need to use a prismatic reflector.
You can use some thin piece of sheet between the lanes so the IR lights don’t interfere with the adjacent lanes.
You would need to assign the other 2 IR sensors to digital pins available on the keypad shield.

In the code, you would need to create a timer array for each sensor. The general operation of the code would work the same, but now you have 3 lanes being timed.
Of course, there would need to be a lot of moderation to the Arduino sketch with regards to displaying the results.

Hope this helps you in some way.

Regards,
Matt.

2 Likes

Thank you very much for your help. What I want is to time 3 people individually and show it on the lcd, I found a project that uses 3 Cylewet 20Pcs 5A 125V Limit Switch. I just realized that it uses a rgb_lcd library, so I’m not able to switch to the LiquidCrystal library to use the LCD shield, its buttons and so on…

I think that with this project, you could already help me, what I want to change in this project is to adapt it to your project.

Project;

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 100;
const int colorB = 150;
const int startButtonMain = 6;
const int startButton = 5;
const int b1 = 11;
const int b2 = 12;
const int b3 = 13;

bool started = false;
bool time1Taken = false;
bool time2Taken = false;
bool time3Taken = false;


unsigned long initTime, timer1, timer2, timer3 = 0;





void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  pinMode(startButtonMain, INPUT_PULLUP);
  pinMode(startButton, INPUT_PULLUP);
  pinMode(b1, INPUT_PULLUP);
  pinMode(b2, INPUT_PULLUP);
  pinMode(b3, INPUT_PULLUP);

  lcd.setCursor(0, 0);
  lcd.print("Exemplo");
  lcd.setCursor(0, 1);
  lcd.print("3 times");

}

void loop() {
  int botao = analogRead(A0);

  if ((botao >= 500 && botao <750) &&  (!started)){
    Serial.println("timer started");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("timer started");
    initTime = millis();
    started = true;
  }

  if (started && (digitalRead(b1) == 0) && (!time1Taken)){
    timer1 = millis();
    time1Taken = true;
  }

  if (started && (digitalRead(b2) == 0) && (!time2Taken)){
    timer2 = millis();
    time2Taken = true;
  }

  if (started && (digitalRead(b3) == 0) && (!time3Taken)){
    timer3 = millis();
    time3Taken = true;
  }

  if (time1Taken && time2Taken && time3Taken){

    lcd.clear();
    
    delay(1000);
    
    lcd.setCursor(1, 0);
    lcd.print("t1");
    lcd.setCursor(7, 0);
    lcd.print("t2");
    lcd.setCursor(13, 0);
    lcd.print("t3");
    
    lcd.setCursor(0, 1);
    lcd.print((float)(timer1-initTime)/1000);
    lcd.setCursor(6, 1);
    lcd.print((float)(timer2-initTime)/1000);
    lcd.setCursor(12, 1);
    lcd.print((float)(timer3-initTime)/1000);
    
    Serial.print((float)(timer1-initTime)/1000);
    Serial.print("\t");
    Serial.print((float)(timer2-initTime)/1000);
    Serial.print("\t");
    Serial.println((float)(timer3-initTime)/1000);
    started = false;
    time1Taken = false;
    time2Taken = false;
    time3Taken = false;
  }
}

Hello again @EDUARDO201739,

I’ve been looking at the code you’ve posted here and compared it to my timer code… the only difference I can see is there are 3 variables for the RGB display (red, green, blue), and there is a setup for these colours.

Correct me if I’m wrong, but I don’t see anywhere in this code where the colours of the LCD get altered when a print statement is made.

I don’t see any reason why this code wouldn’t work with the DFRobot keypad shield… all you need to do is change which LCD library you are using to the one I use in my Arduino sketch.

# include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);    // Pins used for LCD panel.

The second line is the initialization. I gave it the name ‘lcd’, and this is what I use to reference the display every time I want to print something to it, or move the cursor.
By coincidence, the example code you provided uses lcd for its name also.

Once you’ve changed the library over, you can delete the lines for setting up the R G B colours:-

const int colorR = 0;
const int colorG = 100;
const int colorB = 150;

lcd.setRGB(colorR, colorG, colorB);

Also, the ‘botao’ appears to do an analogRead on pin A0, just like my sketch does for the buttons on the keypad shield.
You can adapt your code here to work with the DFRobot shield… have a look at the comments written at the beginning of my sketch:-

/* USING THE KEYPAD BUTTONS ON THE DFROBOT LCD KEYPAD SHIELD ver 1.1
 * -----------------------------------------------------------------
 * ALL 5 buttons are connected to analog pin A0.
 * When no buttons are pressed, the analog value on A0 is 1 (1023).
 * 
 * Analog values for the buttons are:-
 * 
 * SELECT:-    Between 800 and 900.
 * LEFT:-      Between 590 and 650.
 * DOWN:-      Between 370 and 430.
 * UP:-        Between 170 and 230.
 * RIGHT:-     0.
 */

This gives you the resistance values for each button on the shield. Use these to write if statements for carrying out actions for each button.

I hope this helps to clear a few thing up regarding the sketch.

Regards,
Matt.

5 Likes