# LaserPhotoGate
## Problem

* Schools have lots of Vernier Hardware, old and new in physics, biology and chemistry labs
* Vernier is not found in industry
* Specialized connectors and computers trap schools in a priority, expensive environment
* Photogate is used in lots of projects .. including sensing when a combination lock is opened, measuring performance of wheel encoders and integrating into a school wide test bench repertoire

## Conceive

Lots of projects require hooking switches to an arduino. There are lots of tutorials on how. The combolock project needs to detect an AC solenoid successfully stroking it's full path. Most of the time the solenoid is physically prevented from stroking it's full path. A mechanical switch would not be as reliable as a laser.
Develop a pin out of all the wires going into the RJ-11 connector into the vernier photo gate to connect as input to the arduino.
There is a git hub repository ArduinoVerneriPhotoGate-master that has a sketch that parallels vernier's description of the photogate. The photogate is often used for capturing events that happen faster than a mechanical switch can respond. The code seems to focus on the Arduino Atmel CPU interrupts to maximize speed. The goal here is to avoid mechanical contact with the solenoid. We are not interested in speed. We need to use example Arduino sketches to capture slow speed blocking/unblocking of the photogate.

## Design

Alternative designs for this switch could be:
* string pulling different types of switches
* infrared
* ultrasound
* laser beam
The string was abandoned because it would require testing mechanical reliability. Two mechanical systems (solenoid and knob turning) currently require reliability. Reliability is important because between 100 and 1000 combinations need to be checked. Mechanical switch connections are often problems.
Mechanical, infrared and ultrasound are cheaper than laser. Infrared and ultrasound have focus problems. Triangulation is usually required for accuracy and the focus is between 18 inches and around five feet. The combolock design leaves about 3 to 5 inches for the switch.
The vernier photogate was chosen for these reasons:
* invisible laser like an alarm system
* available in most schools
* no moving parts
* fits combolock apparatus (initial justification of this project)
The current goal is to get something working. Reducing cost by adding a mechanical switch is something obvious, and can easily be implemented later.

## Implement

Normal PhotoGate Behavior
The goal is to hack the Vernier PhotoGate. The first step is to understand normal operation.
Cable, PhotoGate and LabQuest ... parts and pieces of a laser photo gate switch .. can see that it is working through the splitter
Close up of a Vernier LabQuest showing a screen describing the Vernier Photogate as blocked
Close up of a Vernier LabQuest showing a screen describing the Vernier Photogate as unblocked
Vernier photogate, Vernier cable and Vernier breakout board .. the Vernier solution to connecting the Photogate to something besides the LabQuest
Vernier Breakout circuit board ... connects British Digital Connector to a header, but not header that matches arduino pinout
Cable from PhotoGate to Arduino
Goal was to build our own cable from PhotoGate to Arduino. Going to need to custom build cable that fits the combolock anyway. After cable is built, then can begin figuring out what the wires in it do.
Found RJ-11 jack
The RG-11 end with cat 5 cable crimped into it
Other end soldered onto a header
Cat5 ethernet cable .. removed one pair of the original four pairs so there are six wires in the cable ..
Wires into the header shrink wrapped
This picture shows the green/white, orange/white stripped wires of Cat5 cable
Preparing to Hack the Vernier Cable
Goal is to expose an existing, working photogate's cable so that the voltages on the individual wires can be seen. This was done with a splitter:
Duplicates or inverts the RJ11 cable so that one land line can be shared by two traditional phones (or answering machines) or can support two land lines in one cable system (since land lines or POTS only use two wires)
Splitter takes normal operation and adds Blue cable that enables looking at the voltages in the black cable
Closeup showing original black cable plugging into the splitter with the blue cable
Showing blue cable exposing the voltages in the black cable while photogate is working normally
Measuring Voltages in Vernier Cable
DMM Checkout
A Digital Multi Meter or DMM is going to be used to figure out what is going on in the cable.
DMMs have an off position .. they have a battery ... typically 9 volts that is wasted if left on
DMM put on smallest resistance scale found ... displays a 1 in the most significant or left side of the display ... indicating ∞ ohms resistance
The normal operational test of a DMM ... to see if battery is working ... is to short the Leads which should display a small number (5 ohms or less)
DMM put on the 20 volt scale ... since anticipating 5 volts (see British Telecom Digital (BTD) – Left Hand ... Photogate Column) in the cable and the alternative is a 2 volt scale ... which would error if the voltage was over 2 volts ...
Results
blockedorangeorange/whitegreengreen/whiteblueblue/white
noground3.75-0.02=04.915.040.02=0
yesground3.75005.040
no03.7504.915.04ground
yes03.75005.04ground
no03.75ground4.915.040
yes03.75ground05.040
Conclusions
ground wires: orange, green and blue/white
power from arduino to photogate: blue
hook to arduino digital pin (or analog pin): green/white .. expect 0 when the lock is opened
Comparison to Vernier British Telecom Digital (BTD) – Left Hand documentation indicates that only one of orange, green and blue/white is ground. Experiments narrowed this down to orange or green. Further experiments are needed if this system is going to be used for the Vernier motion detector which uses all the digital pins.
picture showing British Telecom Digital (BTD) – Left Hand connector plugged into Vernier LabQuest ... this is the end of the cable documented by Vernier
The RJ-11 end that plugs into the Photogate is not documented .. on the Vernier web site
The Vernier Breakout makes it clear there is a one to one mapping of the wires .. no cross connects, no duplication or wires tied together in the cable
Taking Photogate apart, making wires longer
Taking apart, can see black lump that is completely enclosed in the case but appears to have diode in it
Works outside of the case
cutting wires and exposing second laser diode
extended cable works :

## Operate

* A special cable has to be built video.
* The photogate can be powered by the USB cable video.
* Test analog by putting green/white in Analog 0 and running the Example Analog AnalogInOutSerial Sketch video and watching the serial monitor
* Test digital by running extension of the green/white wire to digital pin 2 and running the Example Digital Button Sketch video and watching the LED on the Arduino board that is connected to pin 13 blinking

## Demo

* run the analog test ... no extension cable is needed, the light on the photogate and the serial monitor can be displayed to the audience
* presentation

## Next Steps

* Figure out whether green or orange is ground
* Figure out what the second diode buried inside the photogate does
* Integrate this into the combolock platform
* Develop LabView VI to read the photogate, figure out max speed
* Work on measuring tribot encoder
* Hack a Vernier analog device .. such as temperature measurement