Saturday, December 8, 2012

Our laser maze from the BrainTank conference

One important detail the
journalist left out: Every
time someone fails, our laser
maze hurls insults at the
unfortunate loser. Click
here to see full size.








Here's a news article from the Sept 15th, 2012 BrainTank mini-conference we had in Providence. My involvement with it was the construction of the laser maze.  The initial design of the challenge was done by me and my friend Megan.  She owned the physical design, I owned the design of the electronics and programming.  There was a lot of crossover as we helped each other through many design challenges.  We also had huge amounts of help from friends on the day of deployment.  The project was a huge success and I am very proud of myself and everyone who contributed.  Next year I hope to build an even better version.

I spent several months beforehand sourcing all the parts I could.
-5mW 650nm lasers(count:100)
-650nm photoresistors(count:70)
-2xAA battery holders with batteries(count:100)
-All the scrap CAT5 and CAT4 cable I could find
-Arduino Mega and assorted resistors

It was a challenge finding the correct part when all the information I had on it was a sheet of specifications and a single photo of the object.  On top of that, I didn't know much about electronics.  I was going to learn with this project.  I had to be careful with my purchases because even though I was buying "samples", I couldn't get any of these companies to deal with me for less than 100$.  I checked, rechecked, and sent off the Western Union money.  A few weeks later, I get a big box in the mail.  LASERS : 100 PIECES

Now we're in business!



I spent over a month testing every possible arrangement of electronics.  I had to build a single laser tripwire, and once I got that right, I could make many more and arrange them into an obstacle course.  The entire concept of the thing relies on the behavior of the photoresistor.  When light hits it, its resistance drops to almost nothing.  When light is absent, its resistance skyrockets.  Arduino boards are capable of measuring varying levels of resistance, and the Arduino Mega has 16 ports capable of this.  If a single laser beam is broken, the contestant fails the challenge.  I found that I could chain three photoresistors on a single circuit, so I could have up to 48 laser beams monitored by a single Arduino Mega board.  I tore up a lot of CAT5 and CAT4 cabling for this.  Computer cabling was a great choice because it is already designed to transfer electricity, and everyone I knew had scrap cable.

The circuit design was very simple.

+5V - photoresistor - photoresistor - photoresistor - Arduino receiver - 220O resistor - ground

Multiply this many times, and you've got one piece of the laser maze.
Click to Enlarge
The programming was another matter.  While the Arduino could now receive signals indicating its state, it wouldn't have known what each level of voltage means.  And even if the code running on the Arduino was perfect, there was no way to communicate to anyone that they broke a beam and lost.

I ended up using the Arduino IDE to control the Arduino board itself, and I used a language called Processing to allow my laptop to interface with the Arduino's serial input.  Since I had never written Java syntax before, I had to pick that up too.

To get the information from the laser to the laptop, I settled on a simple design.  The USB link was seriously limited in communications bandwidth, so I made the Arduino only report information when absolutely necessary.  The only things transmitted over the link was a RESET command, and a FAIL response.  At 9600 baud, transmitting much text was difficult- but with this communication model, all I had to transmit was a single bit.

When a RESET command was sent from my laptop, the Arduino began monitoring every input for failure.  If the voltage of any input fell below a hardcoded baseline(determined by the ambient light in the room, defects in the materials, and many other things), then the Arduino would communicate back a FAIL to my laptop.  Upon receiving that event, Processing would load a couple sound files.  A siren followed by a randomly chosen insult from some of the most famous and devastatingly witty movies of our time.  My computer would then use loudspeakers to publicly shame our now crestfallen participant.

Huge props go to Brandon for his masterful audio work, debugging work without which we would not have had a functional program, and his indispensable work on deployment day.

The laser maze even had a GUI!  I borrowed some code from a GUI tutorial to make a clickable rectangle.  The rectangle would turn from grey to black to indicate the maze is in a failure state, and turns back and sends a RESET command when you clicked on it.  Needless to say, the code was not elegant or pretty in any sense of the word, but since I took on this project precisely because I didn't know this stuff, "barely working" is a coup.

And all of this only touches on some of the electronic challenges we had to overcome.   The laser maze also had a physical component, and we had to settle on the design while overcoming the fact that we were cost limited, had to deploy it within a couple of hours, and had to comply with fire codes.  Needless to say, we made and discarded many ideas before settling on the final design.  Without Megan's expertise in building prototypes this would not have happened.  We used towers made of PVC pipe and an aesthetic inspired by Tron.
Prototype towers.
We kept the tower shape
but rejected the mirrors

The week before the event, we wove electronics through all the towers and built as much as we could before the event.  The worst case scenario was if something broke the day of and we couldn't fix it.  We tried to make our electronics fail in every possible way just so they wouldn't fail on the day of the event.  We smashed, burned, stomped on, and electrocuted quite a few of our components.  Losing a connection would have been a nightmare so we made everything as robust as we could.

Early in the morning on the day of, we started setting everything up.  We had over a dozen people helping out- fetching things, soldering, wiring, testing, adjusting.  One-by-one, we plugged in a sensor, aimed a laser, and manually modified the Arduino program to display its state.  Rinse, repeat.  By the end of it, we had a mess of torn up twisted-pair sticking out of a breadboard, tamed only by massive amounts of duct tape.  Fragile, sketchy, and completely functional.  I asked for a final adjustment of the ambient light.  I asked everyone to get in and block a laser.  Baseline established.  Debugging functions disabled.  Sirens enabled.  I asked everyone to step aside, sent the RESET command.  Ready for the first victim.

We set up a golden statue and challenged people to get through the lasers, steal it, and sneak out undetected, armed with only a spray canister to see the laser beams with.  It was an hour before someone managed to get through successfully.  From there, we started having time trials to see who could get through the fastest.  The best time was 8 seconds.  After some time trials, people started hacking our laser maze.

Aside from being fragile and having obvious gaps in the beams, our physical security barrier had a security flaw-  the sensors didn't care where the laser was coming from.  It only gave an ON or OFF state.  If a potential attacker was armed with their own laser, they could point it at a sensor, and if they broke the original laser beam the sensor wouldn't be able to detect it.  This is what they were doing in the newspaper article.

It also had a weakness where the Arduino hardware could only sample the sensor state so quickly.  If someone broke the laser beam and withdrew from it very fast, they would not be detected.  We had several people try to run very fast through it but nobody succeeded in running fast enough.  You could wave your hand through it, though.

Overall, the day was a massive success.  We had some downtime when things would break, but with the persistence of our volunteers, we were able to get things up and running quickly again. Once I get all the code together I will release it. 

EDIT:  Here is the source code for the laser maze.  Bonus 47 mp3 clips of insults inside
http://micrmsoft.com/puzzlerchallengeh4u3t4enjr8gr94/final_lasermaze.zip

No comments:

Post a Comment