Page Created: 6/24/2014   Last Modified: 4/12/2017   Last Generated: 12/11/2017

One of most beautiful acronyms that I have ever encountered is Light Amplification by Stimulated Emission of Radiation, or LASER. How cool is that? So after I built OswaldBot, I decided to make it a lot smarter and... add a laser.

I remember one day in the late 1980's when my high school chemistry professor explained to us that lasers had 3 properties that distinguished them from normal, everyday light. They were: 1. At the same wavelength (same color) 2. In phase (no destructive interference) 3. Collimated (parallel rays). They were available back then, and the school had one, but they were gas filled tubes, such as the red helium-neon laser, that were rather expensive and required high-voltage power supplies. The inexpensive, low-voltage semiconductor laser is a relatively recent phenomenon.

Being a fan of science fiction, I am also intrigued by intelligent computers that run spaceships and other systems, like HAL 9000 from 2001: A Space Odyssey, KITT from Knight Rider, the ship computers from Star Trek: The Next Generation and Passengers, M.U.T.H.E.R. from The Venture Bros., GLaDOS from the videogame Portal, and CASE and TARS from Interstellar.

I hate it when the fictional computer turns evil and decided that if I ever created a computer system, that it would be good, it would be helpful, it would save the day. Isaac Asimov's robot stories demonstrated to me that robotic intelligence is ultimately a good thing, as long as people are conscientious.

As with anything in the physical world, mankind needs to be careful to avoid a "runaway robot effect". We don't exactly know what sentient AI would do to humanity, just like we don't exactly know which viruses will lead to pandemics and which ones won't. It is too complex for us to predict. Chain reactions are scary things which have concerned physicists for decades. We see them in society too. They seem to emerge when enough connections form within a collective, pathways that allow Information to re-organize in paradigm-shifting ways, like a dam breach which causes a great flood. We need to make sure that we can survive the flood.

I like to believe that if someday bad robots do manage to attack mankind, good robots will step in to protect us. Robots are simply workings of the physical world, part of the same universal laws that we are, the same duality.

I also like the parts in film where the computer was dormant or buried for a long time and is successfully reactivated many years later to help us, like in Planet of the Apes (2001), Tron: Legacy. Many of these ideas made it into my LandmarkFilm. The NASA Mars Rover programs and the Voyager missions are real life versions. More recently, in January, 2014, the ESA Rosetta spacecraft was woken up after 3 years of flying through the outer solar system. And around a year later, on December 6, 2014, the New Horizons spacecraft was woken up from its final hibernation cycle in a 9-year journey to capture the first clear images of Pluto and Charon in the history of Mankind. This is beyond fascinating.

I decided I would build a laser tripwire out of a cheap laser pointer I bought at the dollar store. It is similar to the movies where the laser tripwires are protecting museums. Other people have built these things, but I'm not sure how many people have used the intelligence of the Raspberry Pi to simplify the construction and keep the cost low. I think it is amazing that you can go to the store in the US and buy a laser for $1. This was the domain of science fiction when I was young.

You can use it to set home alarms in rooms and hallways, to detect when a car enters a garage, to create a perimeter when camping, or use it to hunt ghosts and cryptids. If aimed near doors, it can detect doors being opened.

Detecting a laser is fairly simple. If something breaks the light beam, it signals a trip, if not, the computer continues with its main loop. However, there wasn't a cheap, easy source of light detectors. You can use a phototransistor or photodiode, but the circuity is complex and they are not readily available.

So I chose an old-school CdS photoresistor. They are cheap and sensitive to light. The only problem is that Cadmium sulfide is not as sensitive to the red wavelength (650nm) of the laser pointer I was using. Ideally a green laser could be used. But they are more expensive, are more dangerous to the eye, and exhibit Rayleigh scattering, which means the beam is visible to any intruder. A red laser beam is invisible until it hits a surface.

A lead sulfide (PbS) photoresistor would be more sensitive to red, but also infrared (heat). They are also hard to find, probably since they are also used in heat-seeking missiles. Infrared LED's were another option. If you grind the tip off an LED and shine light of a shorter wavelength on it (such as a red laser on an infrared LED), it should develop a tiny current, but the amplification circuity would be more complicated.

But the CdS sensor is sensitive enough to work well. I removed the laser diode from the laser pointer, and it has 3 button cells with a tiny surface mount resistor soldered to the circuit board. These types of cheap laser diodes are only current regulated from a resistor and the internal resistance of the button cells. The battery puts out about 190 mA max at 4.5 volts and then the current drops off quickly.

To drive the red laser, I used a 2N2222 transistor with a 1K ohm base resistor. One of the great things about low-power laser diodes is that you don't need high power to drive them. The power coming from the Raspberry Pi's GPIO +5v is just fine. Lasers are even more efficient than LEDs, probably the most efficient light source ever created.

A logic high on the GPIO port turns on the transistor and switches +5v from collector to emitter. The voltage drop incurred by the transistor lowers the output voltage to just under 4.5 volts which is close enough to the original laser battery. I added a 21 ohm resistor in series to the laser to keep the current low in case the resistor on the laser expected the previous internal battery resistance to limit current.

I constructed a black box to house the photoresistor, like a pinhole camera box with the photoresistor glued in the back where the film would normally be. But, because lasers are collimated, pinholes do not work in the same way. Most of the laser light will not go through the pinhole, so you have to make the hole the same size as the photoresistor. The downside is that light pollution from outside sources can also get into the box, but this isn't necessarily a bad thing if you are reading with a capacitor, as you'll see below.

Since photoresistors are analog but the Raspberry Pi's GPIO is digital, using a 47 nF ceramic capacitor is all you need for an RC charge circuit. You set GPIO to low to ground the capacitor and drain it, then you set GPIO to input and the capacitor will fill up at a rate based on the photoresistor until a logic high is received. The time it takes to trigger the high is inversely related to the amount of light on the photoresistor. So a dark resistor takes several seconds to read, but a light resistor reads in less than 1 second. You have to design your algorithm around this property if you want it to trip within a reasonable amount of time. You can use a smaller capacitor like 1 nF, for example, but the resolution will be restricted possibly hampering your algorithm.

I then bought a bag of tiny mirrors from a craft store (like little discoball mirrors) and some poster putty and stuck the mirrors to the wall and bounced the laser off the mirrors and back to the photoresistor, making a round trip.

At more than about 20 feet, the mirrors were very hard to align. The laser began to de-collimate or scatter, but it was still usable for about 100 feet. But every few hours, the laser would drift and misalign. However, the poster putty calmed down after a few days and there was minimal drift.

Aligning multiple mirrors is therefore time consuming. You have to start with the first mirror and align it, then wait for it to calm down after a few days and see where it points, then place your second mirror, and repeat.

To determine if the laser tripped, I read the light-to-dark ratio about once a second. First I read the value with the laser off, then turn on the laser and read the value again. This ratio changes during the time of day. This is further complicated by a memory effect of the photoresistor since Cadmium sulfide mimics the human eye. So if you were to shine a bright light on your eye, for example, it takes a while for you to see well in the dark again, which is similar to the photoresistor.

I decided to pulse the laser about once per second. As long as the sensor keeps receiving pulses, its dark resistance doesn't have time to drop very low due to the memory effect, and this speeds up the reads. But the sensor responds very quickly to short pulses of light, the opposite direction.

So if something breaks the beam, the ratio is large, near 1, since the dark value matches closely to the expected light value (which is blocked and now dark).

Any delays in the main loop will just make the dark value even greater since the memory effect has more time to wear off, which makes the light ratio even smaller and less likely to trip. This is good, since the reverse would cause false alarms.

This system works pretty well, but has some problems that made it unreliable:

  • The mirrors would still drift over several days and become misaligned.
  • When the mirrors would misalign, the background light would have more bias on the light-to-dark ratio, and it would cause false alarms (trips). When the edge of the laser barely hit the photosensor, the light values would fluctuate wildly, possibly due to noise in the laser or power supply ripples.

So I built 2-axis gimbals for the mirrors from some wood, bolts, and metal pipe hanging strap that I had laying around, and glued them to the wall using epoxy. I could then align them carefully with set screws. This prevented the mirror drift.

I created a "deadband", a ratio in-between tripped (high) and non-tripped (low). If any reads fell into the deadband, the system considered it to be misaligned and disabled itself. This worked surprisingly well and is reliable. It is simpler than implementing hysteresis, since I don't have to record and compare past values. Real trips make it past the deadband and are detected. Anything that falls within the deadband is almost certainly due to a misalignment or some kind of light pollution.

The pulsed laser is also hard to see. A person can't easily avoid detection. Trying to find out where the beam is is likely to trip it. Somebody could try to gradually interrupt the beam to trigger the deadband, but it would be almost impossible to gauge how much you would need to interrupt, especially if you kept the deadband range small. In my experimentation, putting your hand slowly in the beam sets it off. A person could try to use smoke, but that would set off the smoke alarms and it would be hard to control the density. If you are certain your alignment is good and light pollution is not an issue, you can tell your algorithm to remove the deadband.

To prevent an intruder from flooding the sensor with light to disable it, you can set a threshold for dark detection. If the sensor is supposed to be dark, but it is very bright, sound the alarm. In this case, it would be best to mount the final mirror on a black wall away from any windows. If the final mirror is far from the sensor, is is unlikely that uncollumated light from lightning will be enough to set off the sensor. An intruder would have to time his light pulses with the laser, and you can tell your algorithm to vary this randomly.

If you criss-crossed several of these and varied the algorithms, there is no easy way I know of to bypass them. In the movies, they show acrobats dancing past the lasers and usually tripping them. Placing multiple sensors and lasers close to each other in hard to reach places on different cycles would mean an intruder would have to pinpoint and time pulses with existing lasers he can barely see. The total parts cost is under $5 (not counting the Raspberry Pi) so you can flood an area with multiple beams for very low cost.

There is also a "haunted by machine" psychological component. If you convince the intruder he has already tripped the laser, he won't care to trip it again. Defeating laser tripwires takes time. Therefore, at random intervals, you could create scare routines. Like HAL 9000 and GLaDOS, there is not much more frightening than to be in the presence of an irrational computer that doesn't want you there.

But that's where you start down the dark path of creating the Evil computer. It's one thing to create a computer to warn you of what it sees, but it is an entirely different thing to cause it to scare someone into incriminating themselves. When you build such a system, you are negatively manipulating a random human being in the future that you have never met. It is a choice made in time without any chance to change our mind. It lacks human "distinction and proportionality". While some futurists consider artificial intelligence to be one of the greatest threats to humanity, other futurists strangely welcome this. At the time of this writing in 2016, the famous Bulletin of the Atomic Scientists↗ lists the "killer robot problem" as an emerging danger on its Doomsday Clock. Perhaps it is now time to re-read Asimov's Three Laws↗.

In conclusion, I learned a lot from this project. When you try really hard to do something you've never done before, to overcome physical or logical problems, there is great satisfaction when you are finished, no matter how frivolous it may seem. It is like you are running your hand across the wall of the universe, feeling its texture, and then sitting around a campfire on an alien planet, contemplating what you have just seen.

Working with light and lasers was kind of eerie, at times. At certain points, late at night, the system would trip, and I would investigate the ghostly laser noise. I wondered how much was due to quantum effects. Light is quantum. Einstein's photoelectric effect (which is why an LED can work as a detector) is quantum. Lasers are how the famous double-slit experiment is performed to show the wave-particle duality that demonstrates that reality is not what we think it is. Today, you can easily perform this experiment with a cheap laser pointer and 3 pencil leads (which I also did) to see the interference pattern.

Just because you can buy a laser for $1 doesn't make it any less mysterious to me.