IR Break Beam Sensor Tube

Happy holidays to you and yours! Today I was able to conclude my speed test. It required the construction of a small test apparatus and I only ripped the arm off of one sensor.

My stylish, new testing tower did exactly what I was hoping. I was having trouble reaching my target time with the wood beam and clothes pins because I would have to so precisely slip a piece of paper in-between both sensors at the same time that my times were impossibly high. With the new tower, the walls kept my wooden shim “shutter” in-line as I accelerated it towards the sensors. I theoretically could have exactly aligned the angle and brought the paper down at the exact right time (I did try, more than a hundred times). You can imagine the difficulty of being so precise with only your hand, a piece of paper, and sensors that are not in exact alignment.

My target time is 50 microseconds (that’s 0.000050 seconds). Whoever said that an Arduino was not suited to the task was wrong; just use interrupts and the proper sensors. My lowest ten results are below. The time difference between triggering each sensor is in microseconds and the count is how many times I had brought my shutter down.

Clothes Pin Block

Time difference: 308
Count: 12
Time difference: 928
Count: 13
Time difference: 216
Count: 41
Time difference: 660
Count: 44
Time difference: 1072
Count: 58
Time difference: 276
Count: 60
Time difference: 1060
Count: 64
Time difference: 728
Count: 65
Time difference: 924
Count: 66
Time difference: 412
Count: 73

Tower

Time difference: 12
Count: 37
Time difference: 80
Count: 45
Time difference: 140
Count: 46
Time difference: 88
Count: 50
Time difference: 56
Count: 52
Time difference: 68
Count: 68
Time difference: 28
Count: 77
Time difference: 28
Count: 157
Time difference: 40
Count: 162
Time difference: 32
Count: 171

As you can see, the tower was much more efficient at gathering good data. As you cannot see, each trial with the wood tower took much less time. I realize that if I only wanted to test the Arduino’s response time, I could have seen how fast it could spam the signal wire with pulses, but I did also want to verify my sensor response time and real-world viability. Plus, building funny-looking testing contraptions is much more fun.

Another win is that the sensors were exactly an inch and a half apart and still read without issue. As you can see, they are not even precisely aligned, so the new “test tube” that I put them on will definitely work as long as the viewing holes are large enough.

All in all, I am satisfied with how the circuit turned out. This is the last high-speed circuit test I will need to do until I weave it into a larger project. Stay tuned to find out what that is.

No sooner had I clicked “Publish” than I began getting anomalous results. I would check the connections, test again, and the count would jump by a few thousand per pass. Something smelled hot. Check the connections, test again, same problems. My plan was to finalize the circuit on the breadboard, tweak it, and then solder it into place.

Seemingly stumped, I vented my vexations to my wise wife, who suggested I skip a step and solder the sensors straightaway. She was right, of course.

It is important to note the limitations of a given setup. In this case, I could not verify any connection on the breadboard. Because things don’t just work well one minute and change their minds the next, I knew something had to be loose or shorting somewhere. Without knowing where, the logical next step was certainly a soldered setup.

I am still learning, so I will only show you the front of the protoboard. As you can see, even that is quite hairy.

Using my limited knowledge of braiding, I figured a way to braid bunches of four together after twisting together the pairs that were ending up in the same place. While I know from my internet cabling job that twisting pairs of wires can affect the quality of a signal over a distance, I think a few inches will be alright.

Your CAT 6 internet wires feature four pairs of twisted wires because some smart engineer somewhere figured out that the signals are clearer for longer distances when the length of a twist lines up with the wavelength of the frequencies being used. If you cut open the jacket of such a cable, it is quite apparent that some pairs are twisted tighter or looser, which is because higher frequencies have shorter wavelengths and lower frequencies have longer wavelengths. While a fun tangent, I put no such thought into my twistings, besides the concern that it might cause interference.

As you can see, the wires fell into line rather nicely. They are certainly easier to manage, even if they aren’t beautiful. At the end of the day, they are less likely to stress the soldering points when they are twisted and organized, as well.

One other thing you should note about internet cabling is there exists such a concept as cable porn. It is more akin to word porn than what you might be thinking. Googling such a thing ought to turn up pictures of extremely neat and well-planned bundles of network cables, perfectly combed and tucked into evenly-spaced clamps, J-hooks, and other cable management solutions. Given that I am a man who has never had the luxury of subscribing to such a time-consuming principle, though I do strive to be neat, I cannot assure the results of your internet search.

I plugged the ends of the wires into my Arduino and, behold! A Christmas miracle occurred. The planets aligned. That is both true literally and figuratively, as the Christmas star appears tonight because Jupiter and Saturn are so close, but also because my untested setup worked the first time it was plugged in. Any occasional small jumps in count could be accounted for in my not-so-surgical setup. Please appreciate your perception of the juxtaposed planets planets properly (it is cloudy here), and I will enjoy this successful setup as I sleep soundly tonight.

I have been very excited to resume work on this high-speed sensor project since exams started. Side note: I do regret not studying harder this week but am glad my hard studying the rest of the semester paid off. I feel the same way one might feel winning a scratch-off when I advance on the project, which is especially true this morning! I have been plagued by the issue of “bouncing” since before the arm-ripping incident put the brakes on the project.

The term “bouncing” originated from mechanical switches. Since computers are so fast, trying to get a clean digital signal from a mechanical switch usually means an onslaught of high and low signals for as long as the switch contacts vibrate from the motion. Most consumer products like game controllers or keyboards have circuit- and software-based protections against this, but every once in a while you may encounter a TV remote that flips several channels at a time.

Since I cannot print any parts yet, I will just have to work smarter than last time and take smaller steps. As you can see, I was careful to avoid taping my sensors so they do not rip, and instead twisted the wires and clipped in-line with clothes pins. Until I can fasten the sensors to their final position and solder, they will be at weird angles, so this allows me to angle them correctly.

It would seem my last changes to my circuit were not all helpful. To counter the bouncing, I tried the laziest but most conventional solution of adding decoupling capacitors. As in my Doubling Down entry, it is good practice but solved no present problem. Next, I added some basic code to ignore clustered, incoherent readings, which helped slightly. Finally, after paging through irrelevant research, I actually did my due diligence and collected a little data. 

I figured that if the Arduino is having trouble determining whether the signal is high or low, I should just make it harder to register as high. I did this by increasing the resistance at the junction of each signal wire. I successfully tested three different resistance values, coincidentally making it back up to the “internet-recommended” resistance that I snubbed in the last post. I am still not sure why the resistor would not register a signal in my earlier tests (perhaps my test had other issues) but it provided the cleanest test today. In the sample below, I printed out the count of how many times a given obscurity was registered passing in front of either sensor for each time I actually passed it in front of a sensor.

1kOhm

Count: 1

Count: 70

Count: 92

Count: 93

Count: 251

Count: 252

Count: 325

Count: 340

Count: 341

Count: 364

10kOhm

Count: 5

Count: 6

Count: 7

Count: 8

Count: 9

Count: 10

Count: 17

Count: 18

Count: 19

Count: 26

Count: 45

Count: 46

Count: 47

22kOhm

Count: 1

Count: 2

Count: 3

Count: 4

Count: 5

Count: 6

Count: 7

Count: 8

Count: 9

Count: 10

Count: 11

Count: 12

Count: 13

As is apparent, each increase in resistance significantly improved the reading. Without the bit of code that says “ignore that,” there was still a bit of bouncing. Any significantly higher resistance proved unreadable, so I believe 22kOhm really is the sweet spot, at least at room temperature.

One more challenge down, on to putting things together!

Ding Ding! I spent time this week tackling my next iteration of the 3D printed sensor tube. While I expected the first iteration to fail, I did not expect it to fail so fantastically. Thus, I have checked and double-checked my measurements and put a lot more thought into how I will attach things. Another advantage is I am not pressed for time; I have all of break to get it right.

This time, I did use good design intent. I still did use the same helical tricks from the last design, albeit sparingly, and I added a few things like using the wrap tool and variables. I added variables because trying to change the smallest thing in the last design required reworking every dimension, of which there were many. Now, by changing one variable, most things will scale to fit it because they are all codependent. This is much better design intent and allows me to change my mind or add different configurations in the future!

In the meantime, I will still be testing sensors and having to put all of the pieces together, so printing a piece that does not move or resize really should be the last thing I do. Stay tuned!

After hours of troubleshooting, I got my infrared LED emitter and receiver to work again! I am using a reverse-biased diode circuit as an extremely fast break-beam sensor (like what stops your garage door from closing when your foot is in the way). It is very difficult to test something when you cannot physically see the result (the sensors are infrared), so I had to break it down and test smaller things, instead of insisting that the setup should be correct (it mostly was until I started pulling it apart). Since it all worked before I put the project down several months ago, the lesson here is to use better documentation. Eureka, meaning “I found it,” is entirely appropriate given the critical errors I identified.

When I finished soldering the sensors into my fantastic, new 3D-printed tube, I assumed it would immediately work, since the setup worked before my last apparatus ripped the arms off of my sensors. I plugged and tried to play, but failed. This is a lesson in testing one’s work. I did not know where to start, since the voltages were too low to even power a conventional LED and the Arduino would not register anything. As far as I knew, I could not see infrared light and, since my sensors are past their shelf lives, soldering could have ruined them, as I have not kept them humidity-controlled.

After much playing around with the circuit, I soldered two more sensors and put them where the unnecessary retainer tabs had broken out of the too-large tube. Still having no luck in any configuration, I puzzled and researched and puzzled some more about how my circuit was setup. Eventually, I realized I should test my most basic assumptions, to see if the things I think are working really work.

I started with the Arduino itself. During testing, I had turned off the internal pull-down resistor, since the circuit I made featured one and could have made it redundant and the resistance too high. I wired a big, red button to bypass the receiver/transistor “switch” and pressed it a few times. Not seeing any readings, I reduced the impedance and tried again. Seeing nothing at this, I turned back on the pull-down resistor and held the sensors very close together. Finally, I got a reading. Regardless of the internal pull-down resistor, the impedance had been too high with the internet-recommended 22 kilo-Ohms. One kilo-Ohm actually worked better.

Next, I found out that you actually can see infrared light using your cell phone camera. I feel like I was late to this party, but now you don’t have to be. Sure enough, my LED was barely glowing. I had been afraid of burning out such a small diode, but reviewing the data sheet with upping the input in mind, I deemed it safe to do. I doubled the voltage back up to 3V and it glowed much more radiantly. I also put my mind to understanding more of the data sheet and discovered that they have metrics as high as one Ampere recorded. While neither I nor the Arduino are that bold, I figured a half-Ampere could not hurt.

With two of the three components now working, I took another stab at the invisible component. I took what I had learned from my research and threw out the recommendations, looking only at my own circuit. I rearranged it to my liking, unstrapped the test sensors from the tube, and held them close together. It worked! I had unstrapped them because I also made more sense of the receiver data sheet; it appears these sensors are very sensitive to angle. Sure enough, I was able to tease them apart while still getting a reading, only to about an inch and a half. While that is coincidentally (no pun intended) the diameter of my tube, there is no way the sensor angles would be in perfect alignment with my low-quality print. In fact, I had to use the soldering iron (professionals, shield your eyes) to widen the sensor bed because they had printed too small and were too fine to get a file or drill into.

It seems very simple, but the reason these test sensors did not rip apart this time is that I twisted the wires, to prevent any inherent pulling on the arms. Having cabled, I know that wires twist and pull in unexpected ways, even when left alone. Besides that, I used rubber bands, instead of electrical tape, to keep them on the tube. I feel smarter every day.

Though the intent was to print a cover to keep everything in, I had a feeling the first iteration would need revisions, so rubber bands did the trick instead.

All in all, it is a good thing that my setup failed, because I analyzed my circuit more closely and made some optimizations. I was able to reduce my cluttered circuit, since I no longer needed a voltage divider. I boosted the voltage from 1.65V to 5V for the LED emitter and raised its Amperage from 0.22 to 0.5.

On the receiving end, I threw out the resistor all together. Upon reviewing reverse-biased circuits, it turns out the only current flowing out is the reverse saturation current. This occurs because the diode is literally wired in backwards, so there is a wall of resistance on one end and the slightly higher voltage that results from light hitting the receiver, plus the voltage initially pushing on it, is what pushes a trickle of current out the other end. I’m not sure if my circuit was reverse-biased before, but it is now!

Also on the receiving end, I confirmed that it is necessary to use a transistor to amplify the signal from the receiver, since the Arduino cannot read such a small current. This is where I replaced the 22kOhm resistor with a 1kOhm resistor on the collector, which is also connected to the Arduino input pin. The pin must have an internal pulldown resistor turned on to work.

Since I was so emboldened by the data sheet, I threw out the 3V circuit all together and ran everything on 5V. I have spares. It seemed to work even better, so I kept it.

Once the circuit was working, I could play with the spacing of the sensors and the ease with which they registered. I have no idea how my television set can pick up such a signal from across the room, but with half an Ampere on the emitting LED, I could read it at a maximum distance of 1.5 inches, with just the right angle. The LED was getting rather warm with 10 Ohms, though, so I tested with 20 and 30 as well. At 20 Ohms, the LED did not get hot but was read just as well. At 30 Ohms, the readable distance decreased to an inch, so I decided 20 Ohms was the sweet spot at room temperature.

With all of these optimizations, I was able to significantly reduce the amount of wires on my breadboard. I will have to go back to the (virtual) drawing board and follow my plan from the last post of printing a high-definition sensor bed, contained by a lower-definition tube, probably with tabs in different, more effective places. I still like the idea of a cover, though, since I can open it up and work “under the hood” conveniently.

While the 3D printing will have to wait until next semester, I will actually be able to keep the project going. Since I have my “optimized” circuit, I can start soldering everything together so it will be plug-and-play as soon as the parts are printed. I can also design the parts to be printed now, since I know what I need and am more certain of the tolerances. I say “optimized” with quotes because we are actually covering circuits next semester. Most of the math I used was V = IR. My knowledge consists entirely of high school physics, Electronics for Dummies, and some helpful online resources that explain components and commonly-used circuits. On the bright side, I will be traveling partially up the electrical engineering tree to add more emphasis on the control side of engineering, so I should have a much better grasp in a few years!

I have been playing around with infrared photodiodes and slowly testing them. Ideally, I want fast photodiodes that can catch a momentary break in light. Without realizing that the refresh rate of these devices are literally on the data sheet, I bought some handy, dandy Adafruit sensors, only to discover they did not work for my purposes.

After a discussion with my engineering friend, Seth, who does things like this all day, I found some more appropriate sensors… when they arrived, I again discovered that I had ignored other key features on the data sheet. They are 2.5 mm wide! I’m not sure what I thought that dimension referred to, but my rolled paper tube apparatus gained me one good data point before my sensors broke apart (see “You Win Some, You Lose Some“).

The fun and easy-to-use, but too-slow break beam sensors from Adafruit

All that is to say, I decided that 3D printing a sensor cradle would be a better option. The only problem? I have never 3D printed anything before! Yes, it does seem absurd; my classmates have been doing it for years. Well, it’s true. Before school, I had started designing a part using the free software, Tinkercad.

As you can see, I was limited to making shapes that consisted of a conglomeration of other shapes. In some cases, it was useful to just drop in a “negative” shape (like the clear shapes in the pictures), but in others it was downright time consuming and limiting. I had intended for the CBS logo-looking things to be wrap-around points for the wires to keep the stress off of the sensors. As you can see in my next design, I got a little more creative.

UMaine made me buy a copy of SOLIDWORKS, so I decided to step it up a notch. I threw everything I had learned at this new model. I even learned a few new things, like wrapping around a shape with the helical tool. I consulted with the 3D Printing Club lab techs to ensure my tiny design features were even feasible. They seemed reasonably confident that it would print alright, and there’s always the option of taking a drill and a file to it afterwards. I figured I would design the part as I wanted it and see what failed upon printing.

I tried to slice it in a way that would not put scaffolding around the entire print. You can see how far the printer got before it ran into an error. Despite having the physical puck in my hand, it still did not occur to me that the piece was twice as wide as I should have dimensioned. Those little mathematical errors give some very interesting real-world results.


What’s more, the campus is shutting down due to COVID concerns about people returning from hot spots after Thanksgiving Break. I got a notice last week that the last day to submit a print was Friday, so I crammed for a full eight hours after class to get the part print-ready in time.

We settled for the all-over scaffolding and the lab techs printed with a hotter print head this time. Overall, I am impressed with what a .4mm nozzle did. my tiny .45mm and 1.8mm holes came out correctly, as did the rectangular bed for my 4-pin wire connector. I wasn’t sure how tightly I could tolerance the design, and it appears that the limit is the square holes for my sensors, since they are too small. 0.2mm seemed to be enough in most cases.

Going forward, I think I will separate the design further. My intent was to have an outer shell that simply slides onto this cylinder. I have various tabs for the pieces to click together. Given how brittle the material is, I will have to modify those tabs. I will instead use the high-resolution resin printer to print the sensor cradles and just leave a place to insert them on the body of the tube. I will also be sure to use better design intent, since I cannot just drag the size up and down without editing most features individually. For now, I will have to see what of this I can still use because otherwise I will be waiting until the spring semester to resume this project.

The resin printer is on the very top right of the shelf. Can you tell how excited the 3D Printing Club is that they will be getting a bigger space once the new engineering building is completed?