How To Use A Break Beam Sensor & How To Make Your Own Light Gate On The Cheap

So many uses for these cheap and versatile break beam sensors, let us show you what you need, how to use them, & how to code them for a variety of projects. You get bonus project and learn about polling and interrupt requests (IRQ).


This is a companion discussion topic for the original entry at https://gurgleapps.com/learn/projects/how-to-use-a-break-beam-sensor-and-make-your-own-light-gate-on-the-cheap
1 Like

Great writeup and explanations. And thanks for uploading the code to github. It is easier to download/clone than using copy/paste.

You definitely have good eye/hand coordination to be able to pull off getting the cards attached to the skateboard to pass through the light gate without the card hitting the SMINT tin or knocking a sensor off the sticky tack. If you got it on the first take, I am especially impressed, since both the horizontal and vertical position of the cards would be changing frequently (due to the way a skateboard turns by tilting).

I am surprised that the lightgate would work outside in sunlight, because I don’t think it is filtering for PWM frequencies (usually 38KHz) like the detectors used in TV remotes do. For example, in another youtube video about lightgates, a TSOP38238 (which he then determined must have really been a TSOP38236) was used. Here’s a link to the datasheet TSOP328xx IR Receiver Modules for Remote Control Systems. But one problem with these IR remote receivers is that it seems the datasheet indicates that there is a maximum burst length, which must be followed by an off period (since these are meant to read pulse patterns used by remote controls). And of course you have to have a PMW to generate the signal to drive the LED that the IR receiver won’t filter out, but you already know how to do that.

I wasn’t able to find many technical details about the Adafruit/Piromoni 3mm light gates, so I am not sure what the receiver is, and if there is a built in resistor in the Emitter to limit current, but that would be my guess.

Unfortunately, these items are relatively cheap until you factor in the shipping and handling, which is usually more than a small item, so it is best to “buy multiple” things at once to help spread the shipping cost over multiple items. It is easy to spend $7+ to ship a “$3” item.

In the youtube comments, Steven F. Le Brun left a comment asking about how you derived the acceleration without knowing the initial velocity.

This got me thinking, and the problem is that when you are calculating the acceleration, you are measuring the time between b and d, and you would get a correct calculation if you knew the instantaneous velocity at point b and d. But the final velocity is not what you have measured; instead you have measured the average velocity over the period of time between a and b (velocity_1) and the average velocity between c and d (velocity_2).

I searched for some examples of calculations using a slotted card and a light gate, and although I found an example BBC Bitesize Measuring acceleration using a double mask, the description of the calculations don’t discuss how the calculations are really done; it is assumed you will be using a data logger that does the calculations for you.

I also found Measuring Acceleration by XTronical, but it has the same calculation you are using, so I don’t think it is correct either.

Because of acceleration, the velocity at point a and the velocity at b will not be identical. For others that want a quick review, this Khan Academy video is good Average velocity for constant acceleration, in fact the whole series is good.

If you measure the time difference between a and c, you will get a different value than the time between b and d, even though the widths of the cards are identical in your case. If there is a positive acceleration, the time between b and d will be less than the time between a and c.

To get the correct acceleration value (and assuming that acceleration is constant, as it would ideally be on an inclined plane), you need to save the time at a, b, c, and d. Then for acceleration time, use ((td-tb)+(tc-ta))/2. Then you will get the correct value for acceleration.

Edit: Although the previous equation will work, it is far from obvious why.

Here is a better explanation: Instead of using the timestamps at “b” and “d”, use the average of the timestamps at “a” and “b” (ta+tb)/2 and then subtract the average of the timestamps at “c” and “d” (tc+td)/2. Then you can also compute the acceleration between a and c, the acceleration between b and d and the acceleration between a and d, which should all be very close to each other (as long as acceleration is constant).

The following are the “equations” in the updated google spreadsheet.

acc_ac=(av_bc-av_ab)/((tb+tc)/2-(ta+tb)/2)
acc_bd=(av_cd-av_bc)/((tc+td)/2-(tb+tc)/2)
acc_ad=(av_cd-av_ab)/((tc+td)/2-(ta+tb)/2)

Note well: This is not the time at the midpoint of displacement between “a” and “b” (unless acceleration is zero). Finding the point where the instantaneous velocity is equal to the average velocity requires solving a quadratic equation, and it depends on the initial velocity and acceleration.

For some unknown reason, google sheets is adding an extra set of parenthesis (I think you call them brackets) around the denominator, but only on the last equation, so it gets changed to =(av_cd-av_ab)/(((tc+td)/2-(ta+tb)/2))

I have a google sheet that allows you to enter values for acceleration, widths of first card, slot and second card, and then simulated the ideal values you would measure. Then using the “times” and the widths, it then calculates the average velocities and acceleration. I sent a copy to the moderator. You can play with it to get an intuitive feel.

I didn’t add charts or much fancy stuff to the sheet, just the caculations (which do use named cells which at least for me make the formulas mean more). In Google sheets you can also click on view → show formulas (or ctrl+` the back tick - the key to left of the 1 key), but if you do, you will probably need to expand the columns.

A graphic my son made to show what is happening as card moves from right to left and passes the lightgate at a, b, c, and d. In the spreadsheet time 0 is ta, … time 3 is td.

Google spreadsheet screenshot with view formulas turned on

Here is the same sheet with view formulas turned off.

Note I entered the acceleration .9876543 so you can see it is recomputing the correct value. Also note that the card widths don’t have to be the same size, but you will need to have the program know about the widths of at least the two cards. If you also specify the width of the slot, you can calculate accelerations over three different (but overlapping) periods, a-c, b-d, a-d (which should be very close in value). This is simulated, so there are no measurement jitter effects due to ISR latency, polling waits, IR response (although I would expect this to be very low especially if no bandpass filtering is being done by the IR receiver). In other words this is “perfect” conditions, which can’t be duplicated in the real world because of friction, measurement errors, etc.

Here’s a link to a user manual for a commercial light gate, the Data Harvest SmartQ Technologies light gate.

At the top of page 5, it discusses measuring acceleration with a “‘double’ interrupt card”. But then it says the following:

The segments must be equal in size and measured accurately.

I agree that for best accuracy, the cards should be identical in size, but I don’t understand why it is a requirement.

Arguments for using the same size: Any measurement jitter, and rounding errors would be more likely to cancel out. In general when doing experiments, you should try to keep as many things the same as possible, so you can have a higher confidence that differences in results were due to differences in what you were trying to measure, instead of being due to differences in things you were not trying to measure the difference of, and not differences due to differences in due to using different items you are using in the measurement.

For example, it wouldn’t be a valid test to use the identical cards connected to two different vehicles with different types of wheels. For example the “hot wheels” car and the “cart with the cream cheese container” used in the Newtons 2nd Law F=ma video probably would not roll down an inclined plain at the same rate (I would expect the Hot Wheels car to go faster, since its wheels probably have much less friction). So if you were trying to get reproducible results, you should use the same car for both tests.

For similar reasons, it would be best to use two cards with the same width.

This is where a simulation can be useful, because you can simulate perfect conditions, and it can be perfectly reproducable. You still need to make sure that the simulated results agree with the expected theoretical results. Then you could test the code with simulated results, and verify that the code is working, then turn on the measurement code, and compare to the simulated values. Normally you would expect lower values, because of friction.