Photogate timing system

Locked
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Photogate timing system

Post by sachleen »

For event supervisors, what are your plans for the photogate timing system? I've struggled with creating a reliable timing system in the past and settled on just manual timing with lasers. Has anyone created a simple but reliable system that is still cheap?

I've created beam break sensors with photoresistors and laser pens but found people walking around the room causes enough vibrations to shake the laser or sensor out of alignment. This is with a small photoresistor, so the obvious solution would be to find larger sensors but that may not be as easily accessible. I've also thought about putting a lens in front of it to focus the laser to make alignment easier, but have not experimented with that idea yet.

The other thought I've had is to have just one laser and one sensor and user a pair of mirrors to redirect the light in a U pattern to create the two timing lines. Breaking either line would interrupt the beam to the sensor. That would reduce the parts and cost as well, but the vibration issue is still present.
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Re: Photogate timing system

Post by sachleen »

I figure I'll use this thread to document my trials and then create a wiki if I come up with something that works well.

I'll start off with the electronics. I'm using what's essentially an Arduino Uno. It's an ATMega328p with Arduino bootloader, programmed with a Sparkfun Pocket AVR Programmer. I'm also using a Propeller Plug for serial communication. These are all old parts I had from past projects.

For the sensor, I started with a photoresistor in a voltage divider configuration. In my experiments, a dowel moving in front of the sensor at around 1m/s was reliably picked up in code. This sensor has also worked well enough in past years for this purpose, but I wanted faster response time so I bought these photodiode sensors from Amazon. Photodiodes respond much faster than a photoresistor so this should support vehicles traveling through the gate at higher speeds. The specific sensor I got has digital and analog outputs, so I was able to just connect power and one wire to a digital pin on the Arduino, making the circuit super simple. It has a potentiometer to adjust the sensitivity if needed. In the default setting of the pot, a well lit room is not enough to trigger an output, but a flashlight or laser beam is, so that works perfectly for my needs. In the end, my hope is sensitivity of the detector will not be important because I expect to create a large difference in light during brief time the dowel is blocking the laser beam. The response time is more important than sensitivity to minor changes. The rest will be handled in the code.

For the laser, I will likely use a battery powered laser pen for the final version, but all I could find in my bin was a 5v laser module which I hooked up to a battery pack using a modified USB cable.

I've attached some pictures of the electronics hardware.
IMG_7865_2.JPG
IMG_7865_2.JPG (462.87 KiB) Viewed 2184 times
Arduino and sensor on breadbaord.
IMG_7867.JPG
IMG_7867.JPG (62.17 KiB) Viewed 2184 times
Photodiode sensor
IMG_7866_2.JPG
IMG_7866_2.JPG (76.5 KiB) Viewed 2184 times
Laser module taped to USB battery pack.
Last edited by sachleen on December 1st, 2022, 10:57 am, edited 2 times in total.
These users thanked the author sachleen for the post:
bernard (December 6th, 2022, 9:17 pm)
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Re: Photogate timing system

Post by sachleen »

For the software, I wrote a simple finite state machine code to go through the various states of operation.

There are a number of stages, but the important ones follow this pattern:

START
- wait for laser to be aligned
ARMED_WAIT
- wait for laser to break
TRIP1_ACTION
- start timer
- wait for laser to be aligned
RETRIP_WAIT
- wait for laser to break
TRIP2_ACTION
- stop timer
- print time to serial monitor
- reset state machine to START

There is also a check to see if there is serial input from the user which serves as a reset for the state machine.

Code: Select all

int ldr_pin = 2; // Shadow = 1, Light = 0
enum state_t {START, START_WAIT, ARMED_MSG, ARMED_WAIT, TRIP1_MSG, TRIP1_ACTION, RETRIP_WAIT, TRIP2_MSG, TRIP2_ACTION, END_MSG};
state_t state = START;

int start_time = 0;

void setup() {
  pinMode(ldr_pin, INPUT);
  Serial.begin(9600);

  Serial.println("Waiting for laser alignment...");
  delay(2000);
}

void loop() {
  if (Serial.available() > 0) {
    String input = Serial.readString();
    Serial.println((String)"Got the input: " + input);
    state = START;
  }

  int ldr_value = digitalRead(ldr_pin);

  switch (state) {
    case START:
      Serial.println("Waiting for laser alignment.");
      state = START_WAIT;
      break;
    case START_WAIT:
      if (ldr_value == 0) {
        state = ARMED_MSG;
      }
      break;
    case ARMED_MSG:
      Serial.println("Armed. waiting for laser break.");
      state = ARMED_WAIT;
      break;
    case ARMED_WAIT:
      if (ldr_value == 1) {
        state = TRIP1_MSG;
      }
      break;
    case TRIP1_MSG:
      Serial.println("Beam tripped. starting time");
      state = TRIP1_ACTION;
      break;
    case TRIP1_ACTION:
      start_time = millis();
      if (ldr_value == 0) {
        state = RETRIP_WAIT;
      }
      break;
    case RETRIP_WAIT: // here it is armed again and waiting for another trip
      if (ldr_value == 1) {
        state = TRIP2_MSG;
      }
      break;
    case TRIP2_MSG:
      Serial.println("Beam tripped. stopping time.");
      state = TRIP2_ACTION;
      break;
    case TRIP2_ACTION:
      Serial.println("The end");
      int end_time = millis() - start_time;
      float out_time = (float)end_time/1000;
      Serial.println((String)"Time taken: " + end_time + " - " + out_time);
      delay(2000);
      state = START;
      break;
  }
  //delay(1000);  
}
These users thanked the author sachleen for the post:
bernard (December 6th, 2022, 9:17 pm)
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Re: Photogate timing system

Post by sachleen »

So my idea for this photogate is to use one laser, one sensor, and two mirrors to make the beam travel across both timing lines.
drawing.png
drawing.png (32.8 KiB) Viewed 2054 times
I purchased a couple of round "table mirror" from the dollar store. They are about 4.5" in diameter and have a little fold out stand so it should make testing easy. I organized them as shown in the diagram above and it was relatively easy to align the mirrors to point the laser to my target. The picture below shows the perspective from the laser pointer (bottom of picture). The second mirror can be seen inside the reflection of the first.
IMG_7956.JPG
IMG_7956.JPG (236.08 KiB) Viewed 2054 times
In the picture below, the laser beam is pointing on the wall after being redireted by two mirrors. The dot on the wall is no longer small and round. The shadow in the middle is a 1/4" dowel I used to block the beam to show how wide the beam has become after being reflected twice. I suppose better quality mirrors would minimize this but better quality mirrors would cost more than $1. I should be able to account for this by tuning the sensor better.
laser_good.jpg
laser_good.jpg (46.35 KiB) Viewed 2054 times
I'm happy to find that while walking around the floor near this setup, the laser point on the wall moves quite a bit with the movement of the floor. This is not ideal, but since I experience this issue at the event every year, it's good to have the same problem at home.

My first idea for handling this is to create a larger cylinder (think toilet paper tube) lined with reflective foil or tape with the sensor inside. When the laser shines into the tube, the light will bounce off the walls and back and create a glow inside. As long as the laser stays within the tube, I can sacrifice some brightness for a larger sensor area.
The next step will be to experiment with this idea. I will need to setup a way to measure how much light is inside the tube when the laser is aligned and blocked. I also need to determine what the maximum size of tube I can use, as I have to strike a balance between laser's movement across the 9.25m distance it travels and how much brightness is lost inside the tube.
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Re: Photogate timing system

Post by sachleen »

I think I have a solution to the "larger sensor" issue. I experimented with a variety of materials starting with foil, thinking it would bounce the light around in the tube to make the whole tube glow red. This did not work very well. I noticed some materials scatter the laser beam when it shines on them, so I pointed the laser at anything I could find around the house to see what might be the best. I finally settled on a translucent plastic material that I cut out of the lid of an oatmeal box. I also had a lightbulb I had just replaced and the frosted "glass" plastic on that worked very well too, but cutting the oatmeal lid was easier.

To put it all together, I drilled a hole in the back of a can to insert the laser sensor into and put the oatmeal lid on the main opening of the can. As the light shines in, it spreads and makes the back of the can glow. To test this, I jumped up and down to cause the laser pointer to move. Normally, it would easily move off of the tiny sensor and give me false triggers, but now, with some tuning in software to set a threshold, the beam can move up an down by about half an inch and still be read accurately. Initial placement still needs to be somewhat in the middle of the can and I imagine I will have to check the laser is aligned regularly, but I believe this will be enough to remove false triggers from people walking around on the floor.

IMG_8557.JPG
IMG_8557.JPG (334.26 KiB) Viewed 1654 times
Picture of the beam not shining into the can, my laptop screen shows analog readings from the Arduino
IMG_8556.JPG
IMG_8556.JPG (324.27 KiB) Viewed 1654 times
Picture of the beam pointing into the can, my laptop screen shows analog readings from the Arduino
IMG_8459.JPG
IMG_8459.JPG (300.67 KiB) Viewed 1654 times
Picture of the back of the can showing the sensor

The next step is to build some structure to mount this at the required height. I'm still using the same mirrors as before. Those have good adjustment built in to them so I'll try to keep my structure simple too.
Last edited by sachleen on February 4th, 2023, 10:34 am, edited 1 time in total.
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Re: Photogate timing system

Post by sachleen »

After testing a lot with my olive can sensor and mirrors, I've come to the conclusion that I likely won't be able to solve my vibration issue. There are actually two issues..

First is probably to do with the mirrors I have. The round mirrors with the built in stand worked fine for testing on the ground, but when I mounted them on the little stands I made, the vibration of the mirror alone was too much. So I scrapped those for flat rectangular mirrors that I taped on to the stand directly. For adjustments, I'd have to just rotate and use shims to change the angle of the whole stand.

Second issue was the small light weight stands I built out of scrap wood to hold everything at the required 17cm height. They were just too easy to move while walking around on the floor. I added some random weights I found around the house to weigh them down and that helped a little bit, but it was still not reliable enough. Keep in mind, this is after solving the sensor problem, so walking around on the floor was causing the laser dot to move by up to 1" at times. The big issue is a slight movement of any piece creates a huge movement of the laser at the end. The laser and both mirrors need to be very still on the ground for it to stay aligned.

The combination of these issues led me to make a second sensor and get a second laser to make a more traditional 2 laser trip-wire system as a backup. To do this, I used a long Cat5 cable and some RJ45 connectors. A pair of wires for 5V and GND and another pair for the analog signal and GND. This will let me power the second sensor and read its value from the single microcontroller.

On the code side, not much was needed to support this, I just change the LDR_PIN to the second LDR in the appropriate state of the FSM logic. I also added a flag to be able to switch between 1 sensor and 2 sensor modes without having to re-upload the code.

On the other side, I have two lasers, both connected to USB power banks. Both lasers can be driven by 5v so I just soldered male USB-A connectors to them to directly plug them into USB battery packs. I discovered another issue here, one of my power banks worked fine, but the second one would turn off after about 30 seconds. I discovered some batteries have circuitry that measures current draw and if it's too little, it turns the power off. I'm not sure the purpose of this "feature" but it is quite annoying for driving lasers that barely draw 20mA! The solution was hack out a female USB-A and add a 100ohm resistor to create a roughly 50mA current draw in addition to the laser. This seemed to be enough to allow the power bank to constantly power the laser without turning off.

This will likely be my last update before my competition next weekend, so hopefully it all works well! Hopefully the mirrors work as I'd really like to be able to use it with just one sensor, but I have a backup plan anyway. After the competition, I'll put everything together on the Wiki and see about making improvements for the future.

A couple of pictures of my setup are below.
IMG_8664 (1).jpg
IMG_8664 (1).jpg (311.43 KiB) Viewed 1376 times
IMG_8628 (1).jpg
IMG_8628 (1).jpg (163.82 KiB) Viewed 1376 times
User avatar
sachleen
Exalted Member
Exalted Member
Posts: 225
Joined: April 10th, 2007, 8:31 pm
Division: Grad
State: CA
Has thanked: 0
Been thanked: 3 times
Contact:

Re: Photogate timing system

Post by sachleen »

So my regional was last weekend and the photo gate system worked wonderfully! I did not have enough time in the morning to experiment with the mirrors so I had to go straight to plan B and setup 2 lasers and 2 sensors with the cat5 cable running down the length. Throughout the day, the sensors and lasers stayed aligned (except for students bumping into them while setting up) and we generally had zero issues.

This makes me hopeful for this way of creating the sensor. There is work to be done to re-package the whole device as there are still a lot of parts and many wires hanging from a breadboard.

Some of the things I want to change:
  • Make the sensor smaller - no reason to have a olive can since the active sensing area is about 1" diameter circle in the center anyway. That's more than enough for alignment, by the way!
  • Put all of the electronics on a PCB or proto-board so it's a bit more plug-and-play instead of setting up individual wires on a breadboard.
  • Look into putting the laser and sensor on the same board so they can share a power supply. On the other end, a mirror can bounce the laser back into the sensor. This would still require two lasers and two sensors, but the beam would only have go travel ~2-3m instead of ~10m as was my original plan so alignment should still be very easy. The upside is, if you use 5v laser modules instead of laser pens, you would not need a separate battery pack for each one.
  • Make the stands more compact. While I could stack everything in a way that would make it easy to fit into my suitcase for travel, I'd like to make the whole system smaller when it's folded up. This is also the main reason I can't just use a heavy base to dampen vibrations on the floor.
  • Either put a screen and buttons on the main sensor or use Bluetooth/WiFi to link the sensors to a mobile device for controlling the system. The experience of using the Arduino Serial Monitor or PuTTY for interacting with the system could definitely be improved.
So that's a wish list.. we'll see how much time I can devote to improving this before next year!
Last edited by sachleen on March 7th, 2023, 12:16 pm, edited 1 time in total.
These users thanked the author sachleen for the post:
sneepity (March 9th, 2023, 3:51 pm)
User avatar
pumptato-cat
Exalted Member
Exalted Member
Posts: 340
Joined: June 15th, 2022, 11:04 am
Division: C
Pronouns: She/Her/Hers
Has thanked: 103 times
Been thanked: 77 times
Contact:

Re: Photogate timing system

Post by pumptato-cat »

Sachleen, thanks for running what sounded like a high-quality event! Following along with your project so far has been very interesting.
anything'll fly if you throw it hard enough
Locked

Return to “Scrambler C”

Who is online

Users browsing this forum: No registered users and 0 guests